diff --git a/ansible/deploy-staging-runner.yml b/ansible/deploy-staging-runner.yml index b6b366d..4345080 100644 --- a/ansible/deploy-staging-runner.yml +++ b/ansible/deploy-staging-runner.yml @@ -49,6 +49,7 @@ - gnupg - jq - nodejs + - make state: present # ============================================ diff --git a/frontend/src/pages/HomePage/FeaturesGrid.tsx b/frontend/src/pages/HomePage/FeaturesGrid.tsx index e70e88a..961b44b 100644 --- a/frontend/src/pages/HomePage/FeaturesGrid.tsx +++ b/frontend/src/pages/HomePage/FeaturesGrid.tsx @@ -26,10 +26,10 @@ const features = [ imageAlt: 'Document Storage', }, { - title: 'Service Stations', + title: 'Fuel Stations', description: 'Find and track your favorite service stations and fuel locations.', - imageSrc: 'https://images.unsplash.com/photo-1594940887841-4996b7f80874?w=600&h=400&fit=crop', - imageAlt: 'Service Stations', + imageSrc: 'https://images.unsplash.com/photo-1572281335102-5f780686ee91?ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&fit=crop&crop=focalpoint&fp-x=0.5&fp-y=0.6&q=80&auto=format&ixlib=rb-4.1.0&w=600&h=400', + imageAlt: 'Fuel Stations', }, { title: 'Reports & Analytics', diff --git a/scripts/export-database.sh b/scripts/export-database.sh index 1e00bab..e4a2a82 100755 --- a/scripts/export-database.sh +++ b/scripts/export-database.sh @@ -9,6 +9,7 @@ set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' +BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration @@ -16,14 +17,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" EXPORT_DIR="${PROJECT_ROOT}/database-exports" TIMESTAMP=$(date +%Y%m%d_%H%M%S) -CONTAINER_NAME="mvp-postgres" + +# Environment-based container names +CONTAINER_NAME="" # Will be set based on environment selection +ENVIRONMENT="" # production or staging # Default values EXPORT_FORMAT="sql" COMPRESS=true INCLUDE_SCHEMA=true INCLUDE_DATA=true -EXPORT_NAME="motovaultpro_export_${TIMESTAMP}" +EXPORT_NAME="" # Will be set after environment selection # Function to print colored output print_info() { @@ -38,6 +42,69 @@ print_error() { echo -e "${RED}[ERROR]${NC} $1" } +print_env() { + echo -e "${BLUE}[ENV]${NC} $1" +} + +# Function to select environment +select_environment() { + if [ -n "$ENVIRONMENT" ]; then + # Environment already set via command line + return + fi + + echo "" + echo -e "${BLUE}========================================${NC}" + echo -e "${BLUE} MotoVaultPro Database Export${NC}" + echo -e "${BLUE}========================================${NC}" + echo "" + echo "Select environment to export from:" + echo "" + echo " 1) Production (mvp-postgres)" + echo " 2) Staging (mvp-postgres-staging)" + echo "" + read -p "Enter choice [1-2]: " ENV_CHOICE + + case $ENV_CHOICE in + 1) + ENVIRONMENT="production" + CONTAINER_NAME="mvp-postgres" + ;; + 2) + ENVIRONMENT="staging" + CONTAINER_NAME="mvp-postgres-staging" + ;; + *) + print_error "Invalid choice. Please enter 1 or 2." + exit 1 + ;; + esac + + echo "" + print_env "Selected environment: ${ENVIRONMENT}" + print_env "Container: ${CONTAINER_NAME}" + echo "" +} + +# Function to set container name based on environment +set_container_from_environment() { + case $ENVIRONMENT in + production|prod) + ENVIRONMENT="production" + CONTAINER_NAME="mvp-postgres" + ;; + staging|stage) + ENVIRONMENT="staging" + CONTAINER_NAME="mvp-postgres-staging" + ;; + *) + print_error "Invalid environment: $ENVIRONMENT" + print_error "Valid options: production, staging" + exit 1 + ;; + esac +} + # Function to show usage show_usage() { cat << EOF @@ -47,6 +114,7 @@ Usage: $0 [options] Options: -h, --help Show this help message + -e, --env ENV Environment: production or staging (prompts if not specified) -f, --format FORMAT Export format: sql, custom, directory (default: sql) -o, --output NAME Custom export filename (without extension) -n, --no-compress Don't compress the export @@ -54,20 +122,30 @@ Options: --data-only Export data only (no schema) --exclude-table TABLE Exclude specific table(s) (can be used multiple times) --include-table TABLE Include only specific table(s) (can be used multiple times) - -c, --container NAME Container name (default: mvp-postgres) + -c, --container NAME Override container name (ignores environment selection) + +Environments: + production (prod) Uses container: mvp-postgres + staging (stage) Uses container: mvp-postgres-staging Examples: - # Full database export with compression + # Interactive environment selection $0 - # Schema only export - $0 --schema-only + # Export from production + $0 --env production - # Export specific tables - $0 --include-table vehicles --include-table fuel_logs + # Export from staging + $0 --env staging + + # Schema only export from production + $0 --env prod --schema-only + + # Export specific tables from staging + $0 -e staging --include-table vehicles --include-table fuel_logs # Custom format for pg_restore - $0 --format custom --output my_backup + $0 --env production --format custom --output my_backup EOF exit 0 @@ -76,12 +154,17 @@ EOF # Parse command line arguments EXCLUDE_TABLES=() INCLUDE_TABLES=() +CONTAINER_OVERRIDE="" while [[ $# -gt 0 ]]; do case $1 in -h|--help) show_usage ;; + -e|--env) + ENVIRONMENT="$2" + shift 2 + ;; -f|--format) EXPORT_FORMAT="$2" shift 2 @@ -111,7 +194,7 @@ while [[ $# -gt 0 ]]; do shift 2 ;; -c|--container) - CONTAINER_NAME="$2" + CONTAINER_OVERRIDE="$2" shift 2 ;; *) @@ -121,6 +204,25 @@ while [[ $# -gt 0 ]]; do esac done +# Handle environment selection +if [ -n "$CONTAINER_OVERRIDE" ]; then + # Container explicitly specified, use it directly + CONTAINER_NAME="$CONTAINER_OVERRIDE" + ENVIRONMENT="custom" + print_info "Using custom container: $CONTAINER_NAME" +elif [ -n "$ENVIRONMENT" ]; then + # Environment specified via command line + set_container_from_environment +else + # No environment specified, prompt user + select_environment +fi + +# Set default export name with environment prefix +if [ -z "$EXPORT_NAME" ]; then + EXPORT_NAME="motovaultpro_${ENVIRONMENT}_export_${TIMESTAMP}" +fi + # Create export directory if it doesn't exist mkdir -p "${EXPORT_DIR}" @@ -186,6 +288,7 @@ fi # Export database print_info "Starting database export..." +print_info "Environment: ${ENVIRONMENT}" print_info "Container: ${CONTAINER_NAME}" print_info "Format: ${EXPORT_FORMAT}" print_info "Output: ${OUTPUT_PATH}" @@ -221,6 +324,8 @@ METADATA_FILE="${EXPORT_DIR}/${EXPORT_NAME}_metadata.json" cat > "${METADATA_FILE}" << EOF { "export_timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)", + "environment": "${ENVIRONMENT}", + "container_name": "${CONTAINER_NAME}", "database_name": "motovaultpro", "export_format": "${EXPORT_FORMAT}", "compressed": ${COMPRESS}, @@ -324,6 +429,8 @@ echo "" print_info "===============================================" print_info "Database Export Complete!" print_info "===============================================" +print_info "Environment: ${ENVIRONMENT}" +print_info "Container: ${CONTAINER_NAME}" print_info "Export file: ${OUTPUT_PATH}" print_info "Metadata: ${METADATA_FILE}" print_info "Instructions: ${IMPORT_INSTRUCTIONS}" diff --git a/scripts/import-database.sh b/scripts/import-database.sh index 753539e..dd1f744 100755 --- a/scripts/import-database.sh +++ b/scripts/import-database.sh @@ -9,14 +9,18 @@ set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' +BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" -CONTAINER_NAME="mvp-postgres" DATABASE_NAME="motovaultpro" +# Environment-based container names +CONTAINER_NAME="" # Will be set based on environment selection +ENVIRONMENT="" # production or staging + # Default values BACKUP_EXISTING=true DROP_EXISTING=false @@ -36,6 +40,69 @@ print_error() { echo -e "${RED}[ERROR]${NC} $1" } +print_env() { + echo -e "${BLUE}[ENV]${NC} $1" +} + +# Function to select environment +select_environment() { + if [ -n "$ENVIRONMENT" ]; then + # Environment already set via command line + return + fi + + echo "" + echo -e "${BLUE}========================================${NC}" + echo -e "${BLUE} MotoVaultPro Database Import${NC}" + echo -e "${BLUE}========================================${NC}" + echo "" + echo "Select environment to import to:" + echo "" + echo " 1) Production (mvp-postgres)" + echo " 2) Staging (mvp-postgres-staging)" + echo "" + read -p "Enter choice [1-2]: " ENV_CHOICE + + case $ENV_CHOICE in + 1) + ENVIRONMENT="production" + CONTAINER_NAME="mvp-postgres" + ;; + 2) + ENVIRONMENT="staging" + CONTAINER_NAME="mvp-postgres-staging" + ;; + *) + print_error "Invalid choice. Please enter 1 or 2." + exit 1 + ;; + esac + + echo "" + print_env "Selected environment: ${ENVIRONMENT}" + print_env "Container: ${CONTAINER_NAME}" + echo "" +} + +# Function to set container name based on environment +set_container_from_environment() { + case $ENVIRONMENT in + production|prod) + ENVIRONMENT="production" + CONTAINER_NAME="mvp-postgres" + ;; + staging|stage) + ENVIRONMENT="staging" + CONTAINER_NAME="mvp-postgres-staging" + ;; + *) + print_error "Invalid environment: $ENVIRONMENT" + print_error "Valid options: production, staging" + exit 1 + ;; + esac +} + # Function to show usage show_usage() { cat << EOF @@ -45,7 +112,8 @@ Usage: $0 [options] Options: -h, --help Show this help message - -c, --container NAME Container name (default: mvp-postgres) + -e, --env ENV Environment: production or staging (prompts if not specified) + -c, --container NAME Override container name (ignores environment selection) -d, --database NAME Database name (default: motovaultpro) --create-db Create database if it doesn't exist --drop-existing Drop existing database before import (DANGER!) @@ -53,15 +121,25 @@ Options: --force Skip confirmation prompts -f, --format FORMAT Import format: sql, custom, directory (auto-detected if not specified) +Environments: + production (prod) Uses container: mvp-postgres + staging (stage) Uses container: mvp-postgres-staging + Examples: - # Import a standard SQL dump - $0 database-exports/motovaultpro_export_20250101_120000.sql.gz + # Interactive environment selection + $0 database-exports/backup.sql.gz - # Import with database recreation - $0 --drop-existing --create-db backup.sql + # Import to production + $0 --env production database-exports/backup.sql.gz - # Import custom format - $0 --format custom backup.dump + # Import to staging + $0 --env staging database-exports/backup.sql.gz + + # Import with database recreation to staging + $0 -e staging --drop-existing --create-db backup.sql + + # Import custom format to production + $0 --env prod --format custom backup.dump Safety Features: - Creates backup of existing database by default @@ -74,13 +152,19 @@ EOF } # Parse command line arguments +CONTAINER_OVERRIDE="" + while [[ $# -gt 0 ]]; do case $1 in -h|--help) show_usage ;; + -e|--env) + ENVIRONMENT="$2" + shift 2 + ;; -c|--container) - CONTAINER_NAME="$2" + CONTAINER_OVERRIDE="$2" shift 2 ;; -d|--database) @@ -129,6 +213,20 @@ if [ ! -e "$IMPORT_FILE" ]; then exit 1 fi +# Handle environment selection +if [ -n "$CONTAINER_OVERRIDE" ]; then + # Container explicitly specified, use it directly + CONTAINER_NAME="$CONTAINER_OVERRIDE" + ENVIRONMENT="custom" + print_info "Using custom container: $CONTAINER_NAME" +elif [ -n "$ENVIRONMENT" ]; then + # Environment specified via command line + set_container_from_environment +else + # No environment specified, prompt user + select_environment +fi + # Auto-detect format if not specified if [ -z "$IMPORT_FORMAT" ]; then if [[ "$IMPORT_FILE" == *.sql.gz ]]; then @@ -205,6 +303,8 @@ fi # Import based on format print_info "Starting database import..." +print_info "Environment: $ENVIRONMENT" +print_info "Container: $CONTAINER_NAME" print_info "File: $IMPORT_FILE" print_info "Format: $IMPORT_FORMAT" print_info "Database: $DATABASE_NAME" @@ -276,6 +376,8 @@ echo "" print_info "===============================================" print_info "Database Import Complete!" print_info "===============================================" +print_info "Environment: $ENVIRONMENT" +print_info "Container: $CONTAINER_NAME" print_info "Database: $DATABASE_NAME" print_info "Tables: $TABLE_COUNT" if [ "$BACKUP_EXISTING" = true ] && [ -n "$BACKUP_FILE" ]; then