v1.3.9: NAS 마이그레이션 루프 stdin 소비 버그 수정
psql이 파이프 입력을 읽어 baseline·migrate가 첫 파일만 처리되던 문제를 /dev/null 연결과 for 루프로 해결한다. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -77,8 +77,9 @@ load_db_env_from_container() {
|
||||
fi
|
||||
}
|
||||
|
||||
# psql이 while 루프 stdin을 읽지 않도록 /dev/null 연결
|
||||
psql_exec() {
|
||||
compose exec -T "$DB_SERVICE" psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" "$@"
|
||||
compose exec -T "$DB_SERVICE" psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" "$@" </dev/null
|
||||
}
|
||||
|
||||
query_sql() {
|
||||
@@ -130,18 +131,32 @@ is_applied() {
|
||||
[ "$(query_sql "SELECT EXISTS (SELECT 1 FROM $SCHEMA_MIGRATIONS_TABLE WHERE file_name = '$file_name');")" = "t" ]
|
||||
}
|
||||
|
||||
matches_baseline_target() {
|
||||
file_name=$1
|
||||
|
||||
if [ -z "$BASELINE_TARGET" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$file_name" = "$BASELINE_TARGET" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "$file_name" | grep -q "^${BASELINE_TARGET}_"
|
||||
}
|
||||
|
||||
print_status() {
|
||||
if ! has_schema_migrations_table; then
|
||||
echo "schema_migrations 테이블이 없습니다."
|
||||
echo "기존 운영 DB라면 먼저 sh scripts/migrate-production-db.sh baseline 으로 현재 파일들을 적용 완료로 기록하세요."
|
||||
|
||||
migration_files | while IFS= read -r file_name; do
|
||||
for file_name in $(migration_files); do
|
||||
echo "pending $file_name"
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
|
||||
migration_files | while IFS= read -r file_name; do
|
||||
for file_name in $(migration_files); do
|
||||
if is_applied "$file_name"; then
|
||||
echo "applied $file_name"
|
||||
else
|
||||
@@ -152,18 +167,18 @@ print_status() {
|
||||
|
||||
baseline_migrations() {
|
||||
ensure_schema_migrations_table
|
||||
found_target=0
|
||||
stop_after_current=0
|
||||
|
||||
migration_files | while IFS= read -r file_name; do
|
||||
if [ -n "$BASELINE_TARGET" ] && [ "$found_target" -eq 1 ]; then
|
||||
continue
|
||||
for file_name in $(migration_files); do
|
||||
if [ "$stop_after_current" -eq 1 ]; then
|
||||
break
|
||||
fi
|
||||
|
||||
run_sql "INSERT INTO $SCHEMA_MIGRATIONS_TABLE (file_name) VALUES ('$file_name') ON CONFLICT (file_name) DO NOTHING;"
|
||||
echo "baseline $file_name"
|
||||
|
||||
if [ -n "$BASELINE_TARGET" ] && { [ "$file_name" = "$BASELINE_TARGET" ] || echo "$file_name" | grep -q "^${BASELINE_TARGET}_"; }; then
|
||||
found_target=1
|
||||
if [ -n "$BASELINE_TARGET" ] && matches_baseline_target "$file_name"; then
|
||||
stop_after_current=1
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -186,7 +201,7 @@ migrate_database() {
|
||||
|
||||
ensure_schema_migrations_table
|
||||
|
||||
migration_files | while IFS= read -r file_name; do
|
||||
for file_name in $(migration_files); do
|
||||
if is_applied "$file_name"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user