@@ -551,7 +551,6 @@ update_files() {
551551 " *.backup"
552552 " *.bak"
553553 " scripts"
554- " prisma/migrations"
555554 )
556555
557556 # Find the actual source directory (strip the top-level directory)
@@ -622,6 +621,64 @@ update_files() {
622621 log_success " Application files updated successfully ($files_copied files)"
623622}
624623
624+ # Merge new migrations with existing ones
625+ merge_migrations () {
626+ local source_dir=" $1 "
627+
628+ log " Merging Prisma migrations..."
629+
630+ # Find the actual source directory
631+ local actual_source_dir
632+ actual_source_dir=$( find " $source_dir " -maxdepth 1 -type d -name " community-scripts-ProxmoxVE-Local-*" | head -1)
633+
634+ if [ -z " $actual_source_dir " ]; then
635+ log_error " Could not find source directory for migration merge"
636+ return 1
637+ fi
638+
639+ # Check if source has migrations
640+ if [ ! -d " $actual_source_dir /prisma/migrations" ]; then
641+ log " No migrations found in new release"
642+ return 0
643+ fi
644+
645+ # Check if we have existing migrations
646+ if [ ! -d " prisma/migrations" ]; then
647+ log " No existing migrations found, copying all migrations from new release"
648+ mkdir -p " prisma"
649+ cp -r " $actual_source_dir /prisma/migrations" " prisma/"
650+ log_success " All migrations copied from new release"
651+ return 0
652+ fi
653+
654+ # Merge migrations - copy only new ones
655+ local new_migrations_copied=0
656+ local existing_migrations=$( find prisma/migrations -mindepth 1 -maxdepth 1 -type d | wc -l)
657+
658+ for migration_dir in " $actual_source_dir /prisma/migrations" /* ; do
659+ if [ -d " $migration_dir " ]; then
660+ local migration_name=$( basename " $migration_dir " )
661+ local target_migration=" prisma/migrations/$migration_name "
662+
663+ if [ ! -d " $target_migration " ]; then
664+ log " Adding new migration: $migration_name "
665+ cp -r " $migration_dir " " $target_migration "
666+ new_migrations_copied=$(( new_migrations_copied + 1 ))
667+ else
668+ log " Migration $migration_name already exists, skipping"
669+ fi
670+ fi
671+ done
672+
673+ local final_migrations=$( find prisma/migrations -mindepth 1 -maxdepth 1 -type d | wc -l)
674+
675+ if [ " $new_migrations_copied " -gt 0 ]; then
676+ log_success " Added $new_migrations_copied new migrations (total: $final_migrations )"
677+ else
678+ log " No new migrations to add (total: $final_migrations )"
679+ fi
680+ }
681+
625682# Install dependencies and build
626683install_and_build () {
627684 log " Installing dependencies..."
@@ -924,6 +981,12 @@ main() {
924981 rollback
925982 fi
926983
984+ # Merge new migrations with existing ones
985+ if ! merge_migrations " $source_dir " ; then
986+ log_error " Migration merge failed, rolling back..."
987+ rollback
988+ fi
989+
927990 # Restore .env and data directory before building
928991 restore_backup_files
929992
0 commit comments