Spaces:
Running
Running
Upload hf-entrypoint.sh
Browse files- hf-entrypoint.sh +29 -0
hf-entrypoint.sh
CHANGED
|
@@ -55,6 +55,35 @@ if command -v psql >/dev/null 2>&1; then
|
|
| 55 |
fi
|
| 56 |
fi
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
DATABASE_QUERY="sslmode=${DATABASE_SSLMODE}&sslrootcert=${DATABASE_SSLROOTCERT}"
|
| 59 |
if [ -n "${DATABASE_QUERY_EXTRA:-}" ]; then
|
| 60 |
DATABASE_QUERY="${DATABASE_QUERY}&${DATABASE_QUERY_EXTRA}"
|
|
|
|
| 55 |
fi
|
| 56 |
fi
|
| 57 |
|
| 58 |
+
# sub2api AutoSetup currently uses a hard 60s migration context.
|
| 59 |
+
# Migration 033 may exceed this on remote managed PostgreSQL.
|
| 60 |
+
# Pre-apply 033 once (without recording schema_migrations) so the real runner
|
| 61 |
+
# can re-run it quickly and record checksum in its own flow.
|
| 62 |
+
if command -v psql >/dev/null 2>&1 && command -v curl >/dev/null 2>&1; then
|
| 63 |
+
SCHEMA_MIGRATIONS_EXISTS=$(psql "dbname=${DATABASE_DBNAME}" -tAc "SELECT to_regclass('public.schema_migrations') IS NOT NULL" 2>/dev/null | tr -d '[:space:]' || true)
|
| 64 |
+
if [ "${SCHEMA_MIGRATIONS_EXISTS}" = "true" ]; then
|
| 65 |
+
MIG_033_APPLIED=$(psql "dbname=${DATABASE_DBNAME}" -tAc "SELECT 1 FROM schema_migrations WHERE filename='033_ops_monitoring_vnext.sql' LIMIT 1" 2>/dev/null | tr -d '[:space:]' || true)
|
| 66 |
+
else
|
| 67 |
+
MIG_033_APPLIED=""
|
| 68 |
+
fi
|
| 69 |
+
|
| 70 |
+
if [ "${MIG_033_APPLIED}" != "1" ]; then
|
| 71 |
+
MIG_033_URL="${MIG_033_URL:-https://raw.githubusercontent.com/Wei-Shaw/sub2api/main/backend/migrations/033_ops_monitoring_vnext.sql}"
|
| 72 |
+
MIG_033_SQL="/tmp/033_ops_monitoring_vnext.sql"
|
| 73 |
+
if curl -fsSL "${MIG_033_URL}" -o "${MIG_033_SQL}" >/dev/null 2>&1; then
|
| 74 |
+
echo "[boot] pre-applying migration 033 to avoid AutoSetup timeout..."
|
| 75 |
+
if PGOPTIONS="-c statement_timeout=0 -c lock_timeout=0" psql "dbname=${DATABASE_DBNAME}" -v ON_ERROR_STOP=1 -f "${MIG_033_SQL}" >/dev/null 2>&1; then
|
| 76 |
+
echo "[boot] pre-apply 033 done"
|
| 77 |
+
else
|
| 78 |
+
echo "[warn] pre-apply 033 failed; AutoSetup will continue with built-in migration flow"
|
| 79 |
+
fi
|
| 80 |
+
rm -f "${MIG_033_SQL}" || true
|
| 81 |
+
else
|
| 82 |
+
echo "[warn] failed to download migration 033 from ${MIG_033_URL}"
|
| 83 |
+
fi
|
| 84 |
+
fi
|
| 85 |
+
fi
|
| 86 |
+
|
| 87 |
DATABASE_QUERY="sslmode=${DATABASE_SSLMODE}&sslrootcert=${DATABASE_SSLROOTCERT}"
|
| 88 |
if [ -n "${DATABASE_QUERY_EXTRA:-}" ]; then
|
| 89 |
DATABASE_QUERY="${DATABASE_QUERY}&${DATABASE_QUERY_EXTRA}"
|