diff --git a/scripts/deploy_package.sh b/scripts/deploy_package.sh index 4d40527..1e53ca2 100644 --- a/scripts/deploy_package.sh +++ b/scripts/deploy_package.sh @@ -95,11 +95,26 @@ echo "[2/9] Pre-cleaning existing data for this file..." DELETE FROM ${P}chunk_vectors WHERE uuid = '$UUID'; DELETE FROM ${P}chunk WHERE file_uuid = '$UUID'; DELETE FROM ${P}videos WHERE file_uuid = '$UUID'; + -- Drop legacy constraint that conflicts with global identity re-import + DO \$\$ + BEGIN + IF EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'identities_name_key') THEN + ALTER TABLE ${P}identities DROP CONSTRAINT identities_name_key; + END IF; + END + \$\$; EOSQL echo " ✅ Cleared existing data for $UUID" # 3. Import each table file in dependency order (FK constraints) -echo "[3/9] Importing DB data (per-table)..." +echo "[3/9] Normalizing schema prefix and importing DB data..." +# Normalize COPY schema prefix: dev. → ${SCHEMA}. so it matches target schema +if [ "${SCHEMA}" != "dev" ]; then + for f in "$DIR"/sql/dev_*.sql; do + sed -i '' "s/COPY dev\./COPY ${SCHEMA}./g" "$f" + done + echo " Schema prefix normalized: dev. → ${SCHEMA}." +fi IMPORT_ORDER=( "sql/dev_videos.sql" "sql/dev_chunk.sql"