Fix startup issues

This commit is contained in:
Urtzi Alfaro
2025-10-01 12:17:59 +02:00
parent 2eeebfc1e0
commit 016742d63f
53 changed files with 2000 additions and 2091 deletions

View File

@@ -15,6 +15,9 @@ data:
LOG_LEVEL: "INFO"
# Database initialization settings
# IMPORTANT: Services NEVER run migrations - they only verify DB is ready
# Migrations are handled by dedicated migration jobs
# DB_FORCE_RECREATE only affects migration jobs, not services
DB_FORCE_RECREATE: "false"
BUILD_DATE: "2024-01-20T10:00:00Z"
VCS_REF: "latest"

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for alert-processor database
set -e
SERVICE_NAME="alert-processor"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=alert-processor-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find alert-processor database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for alert-processor database
set -e
SERVICE_NAME="alert-processor"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=alert-processor-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find alert-processor database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for alert-processor database
set -e
SERVICE_NAME="alert-processor"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ALERT_PROCESSOR_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=alert-processor-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find alert-processor database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for alert-processor service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your alert-processor service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for auth database
set -e
SERVICE_NAME="auth"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.AUTH_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.AUTH_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=auth-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find auth database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for auth database
set -e
SERVICE_NAME="auth"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.AUTH_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.AUTH_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=auth-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find auth database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for auth database
set -e
SERVICE_NAME="auth"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.AUTH_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.AUTH_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=auth-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find auth database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for auth service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your auth service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for external database
set -e
SERVICE_NAME="external"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=external-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find external database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for external database
set -e
SERVICE_NAME="external"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=external-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find external database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for external database
set -e
SERVICE_NAME="external"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.EXTERNAL_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=external-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find external database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for external service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your external service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for forecasting database
set -e
SERVICE_NAME="forecasting"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=forecasting-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find forecasting database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for forecasting database
set -e
SERVICE_NAME="forecasting"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=forecasting-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find forecasting database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for forecasting database
set -e
SERVICE_NAME="forecasting"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.FORECASTING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=forecasting-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find forecasting database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for forecasting service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your forecasting service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for inventory database
set -e
SERVICE_NAME="inventory"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=inventory-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find inventory database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for inventory database
set -e
SERVICE_NAME="inventory"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=inventory-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find inventory database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for inventory database
set -e
SERVICE_NAME="inventory"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.INVENTORY_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=inventory-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find inventory database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for inventory service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your inventory service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for notification database
set -e
SERVICE_NAME="notification"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find notification database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for notification database
set -e
SERVICE_NAME="notification"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find notification database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for notification database
set -e
SERVICE_NAME="notification"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.NOTIFICATION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=notification-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find notification database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for notification service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your notification service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for orders database
set -e
SERVICE_NAME="orders"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ORDERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ORDERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=orders-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find orders database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for orders database
set -e
SERVICE_NAME="orders"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ORDERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ORDERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=orders-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find orders database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for orders database
set -e
SERVICE_NAME="orders"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.ORDERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.ORDERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=orders-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find orders database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for orders service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your orders service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for pos database
set -e
SERVICE_NAME="pos"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.POS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.POS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=pos-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find pos database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for pos database
set -e
SERVICE_NAME="pos"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.POS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.POS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=pos-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find pos database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for pos database
set -e
SERVICE_NAME="pos"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.POS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.POS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=pos-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find pos database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for pos service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your pos service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for production database
set -e
SERVICE_NAME="production"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=production-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find production database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for production database
set -e
SERVICE_NAME="production"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=production-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find production database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for production database
set -e
SERVICE_NAME="production"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.PRODUCTION_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=production-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find production database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for production service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your production service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for recipes database
set -e
SERVICE_NAME="recipes"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find recipes database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for recipes database
set -e
SERVICE_NAME="recipes"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find recipes database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for recipes database
set -e
SERVICE_NAME="recipes"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.RECIPES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.RECIPES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=recipes-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find recipes database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for recipes service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your recipes service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for sales database
set -e
SERVICE_NAME="sales"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SALES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SALES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=sales-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find sales database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for sales database
set -e
SERVICE_NAME="sales"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SALES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SALES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=sales-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find sales database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for sales database
set -e
SERVICE_NAME="sales"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SALES_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SALES_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=sales-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find sales database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for sales service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your sales service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for suppliers database
set -e
SERVICE_NAME="suppliers"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=suppliers-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find suppliers database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for suppliers database
set -e
SERVICE_NAME="suppliers"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=suppliers-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find suppliers database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for suppliers database
set -e
SERVICE_NAME="suppliers"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.SUPPLIERS_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=suppliers-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find suppliers database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for suppliers service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your suppliers service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for tenant database
set -e
SERVICE_NAME="tenant"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TENANT_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TENANT_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=tenant-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find tenant database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for tenant database
set -e
SERVICE_NAME="tenant"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TENANT_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TENANT_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=tenant-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find tenant database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for tenant database
set -e
SERVICE_NAME="tenant"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TENANT_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TENANT_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=tenant-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find tenant database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for tenant service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your tenant service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi

View File

@@ -1,39 +0,0 @@
#!/bin/bash
# Backup script for training database
set -e
SERVICE_NAME="training"
BACKUP_DIR="${BACKUP_DIR:-./backups}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${SERVICE_NAME}_backup_${TIMESTAMP}.sql"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
echo "Starting backup for $SERVICE_NAME database..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TRAINING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TRAINING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=training-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find training database pod"
exit 1
fi
echo "Backing up to: $BACKUP_FILE"
kubectl exec "$POD_NAME" -n bakery-ia -- pg_dump -U "$DB_USER" "$DB_NAME" > "$BACKUP_FILE"
if [ $? -eq 0 ]; then
echo "Backup completed successfully: $BACKUP_FILE"
# Compress the backup
gzip "$BACKUP_FILE"
echo "Backup compressed: ${BACKUP_FILE}.gz"
else
echo "Backup failed"
exit 1
fi

View File

@@ -1,47 +0,0 @@
#!/bin/bash
# Restore script for training database
set -e
SERVICE_NAME="training"
BACKUP_FILE="$1"
if [ -z "$BACKUP_FILE" ]; then
echo "Usage: $0 <backup_file>"
echo "Example: $0 ./backups/${SERVICE_NAME}_backup_20240101_120000.sql"
exit 1
fi
if [ ! -f "$BACKUP_FILE" ]; then
echo "Error: Backup file not found: $BACKUP_FILE"
exit 1
fi
echo "Starting restore for $SERVICE_NAME database from: $BACKUP_FILE"
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TRAINING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TRAINING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=training-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find training database pod"
exit 1
fi
# Check if file is compressed
if [[ "$BACKUP_FILE" == *.gz ]]; then
echo "Decompressing backup file..."
zcat "$BACKUP_FILE" | kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME"
else
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$BACKUP_FILE"
fi
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed"
exit 1
fi

View File

@@ -1,55 +0,0 @@
#!/bin/bash
# Seeding script for training database
set -e
SERVICE_NAME="training"
SEED_FILE="${SEED_FILE:-infrastructure/scripts/seeds/${SERVICE_NAME}_seed.sql}"
echo "Starting database seeding for $SERVICE_NAME..."
# Get database credentials from Kubernetes secrets
DB_USER=$(kubectl get secret database-secrets -n bakery-ia -o jsonpath='{.data.TRAINING_DB_USER}' | base64 -d)
DB_NAME=$(kubectl get configmap bakery-config -n bakery-ia -o jsonpath='{.data.TRAINING_DB_NAME}')
# Get the pod name
POD_NAME=$(kubectl get pods -n bakery-ia -l app.kubernetes.io/name=training-db -o jsonpath='{.items[0].metadata.name}')
if [ -z "$POD_NAME" ]; then
echo "Error: Could not find training database pod"
exit 1
fi
# Check if seed file exists
if [ ! -f "$SEED_FILE" ]; then
echo "Warning: Seed file not found: $SEED_FILE"
echo "Creating sample seed file..."
mkdir -p "infrastructure/scripts/seeds"
cat > "$SEED_FILE" << 'SEED_EOF'
-- Sample seed data for training service
-- Add your seed data here
-- Example:
-- INSERT INTO sample_table (name, created_at) VALUES
-- ('Sample Data 1', NOW()),
-- ('Sample Data 2', NOW());
-- Note: Replace with actual seed data for your training service
SELECT 'Seed file created. Please add your seed data.' as message;
SEED_EOF
echo "Sample seed file created at: $SEED_FILE"
echo "Please edit this file to add your actual seed data"
exit 0
fi
echo "Applying seed data from: $SEED_FILE"
kubectl exec -i "$POD_NAME" -n bakery-ia -- psql -U "$DB_USER" "$DB_NAME" < "$SEED_FILE"
if [ $? -eq 0 ]; then
echo "Seeding completed successfully"
else
echo "Seeding failed"
exit 1
fi