Add migration services
This commit is contained in:
55
infrastructure/scripts/pos_seed.sh
Executable file
55
infrastructure/scripts/pos_seed.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user