chore(deploy): refactor database cleanup and migration workflow in deploy.sh
- Remove deprecated --migrate flag and related RUN_MIGRATE logic - Simplify database cleanup workflow to always run migrations before cleaning - Add run_prisma_generate() function to update Prisma Client after migrations - Update documentation to reflect new workflow where --clean-database implies migration - Remove conditional migration logic that could cause double execution
This commit is contained in:
@@ -9,9 +9,8 @@
|
||||
# ./deploy.sh --flutter – bygg bara flutter web-app
|
||||
# ./deploy.sh --importer – bygg bara importer-microservice
|
||||
# ./deploy.sh --seed – kör full seed på databasen (opt-in)
|
||||
# ./deploy.sh --migrate – kör Prisma-migrationer explicit (opt-in)
|
||||
# ./deploy.sh --skip-migration – hoppa över automatisk startup-migrering i recipe-api
|
||||
# ./deploy.sh --clean-database – kör underhålls-SQL som rensar data men behåller kategorier
|
||||
# ./deploy.sh --clean-database – kör migration och därefter underhålls-SQL som rensar data men behåller kategorier
|
||||
# ./deploy.sh --pull-always – kontrollera uppdateringar för basimages
|
||||
# ./deploy.sh --backend --seed – kombinera flaggor fritt (git pull körs alltid)
|
||||
|
||||
@@ -26,7 +25,6 @@ BUILD_BACKEND=false
|
||||
BUILD_FLUTTER=false
|
||||
BUILD_IMPORTER=false
|
||||
RUN_SEED=false
|
||||
RUN_MIGRATE=false
|
||||
RUN_CLEAN_DATABASE=false
|
||||
SKIP_MIGRATION=false
|
||||
PULL_IMAGES=false # --pull=false är standard (snabbt)
|
||||
@@ -101,13 +99,17 @@ run_prisma_migrate_deploy() {
|
||||
info "Migrationer slutförda utan fel."
|
||||
}
|
||||
|
||||
run_prisma_generate() {
|
||||
info "Uppdaterar Prisma Client..."
|
||||
docker exec recipe-api sh -lc "cd /app && npx prisma generate --schema prisma/schema.prisma"
|
||||
}
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--backend) BUILD_BACKEND=true; BUILD_ALL=false ;;
|
||||
--flutter) BUILD_FLUTTER=true; BUILD_ALL=false ;;
|
||||
--importer) BUILD_IMPORTER=true; BUILD_ALL=false ;;
|
||||
--seed) RUN_SEED=true ;;
|
||||
--migrate) RUN_MIGRATE=true; BUILD_BACKEND=true; BUILD_ALL=false ;;
|
||||
--skip-migration) SKIP_MIGRATION=true ;;
|
||||
--clean-database) RUN_CLEAN_DATABASE=true; BUILD_BACKEND=true; BUILD_ALL=false ;;
|
||||
--pull-always) PULL_IMAGES=true ;;
|
||||
@@ -125,8 +127,8 @@ if [ "$BUILD_ALL" = true ]; then
|
||||
BUILD_IMPORTER=true
|
||||
fi
|
||||
|
||||
# Om explicit migration begärs, stäng av automigrering i containern för att undvika dubbelkörning.
|
||||
if [ "$RUN_MIGRATE" = true ]; then
|
||||
# Om databasrensning begärs, stäng av automigrering i containern för att undvika dubbelkörning.
|
||||
if [ "$RUN_CLEAN_DATABASE" = true ]; then
|
||||
SKIP_MIGRATION=true
|
||||
fi
|
||||
|
||||
@@ -136,7 +138,7 @@ fi
|
||||
require_cmd git
|
||||
require_cmd docker
|
||||
|
||||
if [ "$BUILD_BACKEND" = true ] || [ "$RUN_SEED" = true ] || [ "$RUN_CLEAN_DATABASE" = true ] || [ "$RUN_MIGRATE" = true ]; then
|
||||
if [ "$BUILD_BACKEND" = true ] || [ "$RUN_SEED" = true ] || [ "$RUN_CLEAN_DATABASE" = true ]; then
|
||||
require_cmd grep
|
||||
fi
|
||||
|
||||
@@ -176,17 +178,15 @@ fi
|
||||
info "Startar tjänster..."
|
||||
"${COMPOSE_CMD[@]}" up -d
|
||||
|
||||
# ── Prisma migreringar och databasrensning (opt-in) ─────────────────────────
|
||||
if [ "$RUN_MIGRATE" = true ] || [ "$RUN_CLEAN_DATABASE" = true ]; then
|
||||
# ── Databasrensning (opt-in) ──────────────────────────────────────────────────
|
||||
if [ "$RUN_CLEAN_DATABASE" = true ]; then
|
||||
CLEAN_SQL_FILE="backend/prisma/maintenance/clean-database.sql"
|
||||
|
||||
wait_for_backend_prisma || fatal "Backend blev inte redo för Prisma-kommandon i tid."
|
||||
|
||||
if [ "$RUN_MIGRATE" = true ]; then
|
||||
info "Säkerställer uppdaterat databasschema före rensning..."
|
||||
run_prisma_migrate_deploy
|
||||
fi
|
||||
|
||||
if [ "$RUN_CLEAN_DATABASE" = true ]; then
|
||||
[ -f "$CLEAN_SQL_FILE" ] || fatal "Saknar $CLEAN_SQL_FILE"
|
||||
|
||||
MARIADB_ROOT_PASSWORD="$(read_env_value MARIADB_ROOT_PASSWORD)"
|
||||
@@ -198,10 +198,14 @@ if [ "$RUN_MIGRATE" = true ] || [ "$RUN_CLEAN_DATABASE" = true ]; then
|
||||
info "Kör databasrensning från $CLEAN_SQL_FILE ..."
|
||||
docker exec -i recipe-db mariadb -uroot -p"$MARIADB_ROOT_PASSWORD" "$MARIADB_DATABASE" < "$CLEAN_SQL_FILE"
|
||||
info "Databasrensning klar (kategorier bevarade enligt SQL-filen)."
|
||||
|
||||
run_prisma_generate
|
||||
fi
|
||||
|
||||
info "Uppdaterar Prisma Client..."
|
||||
docker exec recipe-api sh -lc "cd /app && npx prisma generate --schema prisma/schema.prisma"
|
||||
# Visa Prisma Client-output även vid vanlig deploy när automigrering är aktiv.
|
||||
if [ "$RUN_CLEAN_DATABASE" = false ] && [ "$SKIP_MIGRATION" = false ] && [ "$BUILD_BACKEND" = true ]; then
|
||||
wait_for_backend_prisma || fatal "Backend blev inte redo för Prisma-kommandon i tid."
|
||||
run_prisma_generate
|
||||
fi
|
||||
|
||||
# ── Seed (opt-in) ─────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user