diff options
| author | Bobby <[email protected]> | 2026-03-11 00:10:25 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-11 00:10:25 +0530 |
| commit | 847ade6db1282d6342cd433e651ee6f50d6be866 (patch) | |
| tree | 075839f9ee916534da9f73640329aafaea028668 /scripts | |
| parent | d3a543545a16a4700f515c398f645251da30f09f (diff) | |
| download | pagoda-847ade6db1282d6342cd433e651ee6f50d6be866.tar.xz pagoda-847ade6db1282d6342cd433e651ee6f50d6be866.zip | |
feat: enhance entrypoint script to drop indexes and tables with improved logging
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/entrypoint.sh | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 6fdb427..2d894c9 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -9,25 +9,34 @@ if [ "$SEED" = "true" ]; then elif [ "$DB_DRIVER" = "libsql" ]; then TURSO_URL=$(echo "$DSN" | sed 's|^libsql://|https://|; s|?.*||') TURSO_TOKEN=$(echo "$DSN" | sed -n 's/.*authToken=\(.*\)/\1/p') + INDEXES=$(curl -s "${TURSO_URL}/v2/pipeline" \ + -H "Authorization: Bearer ${TURSO_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{"requests":[{"type":"execute","stmt":{"sql":"SELECT name FROM sqlite_master WHERE type='\''index'\'' AND name NOT LIKE '\''sqlite_%'\''"}},{"type":"close"}]}' \ + | grep -o '"type":"text","value":"[^"]*"' | sed 's/.*"value":"//;s/"//') TABLES=$(curl -s "${TURSO_URL}/v2/pipeline" \ -H "Authorization: Bearer ${TURSO_TOKEN}" \ -H "Content-Type: application/json" \ -d '{"requests":[{"type":"execute","stmt":{"sql":"SELECT name FROM sqlite_master WHERE type='\''table'\'' AND name NOT LIKE '\''sqlite_%'\'' AND name NOT LIKE '\''_litestream%'\''"}},{"type":"close"}]}' \ | grep -o '"type":"text","value":"[^"]*"' | sed 's/.*"value":"//;s/"//') - if [ -n "$TABLES" ]; then - STMTS="" - for TABLE in $TABLES; do - echo "[entrypoint] Dropping table: $TABLE" - STMTS="${STMTS}{\"type\":\"execute\",\"stmt\":{\"sql\":\"DROP TABLE IF EXISTS ${TABLE}\"}}," - done + STMTS="" + for INDEX in $INDEXES; do + echo "[entrypoint] Dropping index: $INDEX" + STMTS="${STMTS}{\"type\":\"execute\",\"stmt\":{\"sql\":\"DROP INDEX IF EXISTS ${INDEX}\"}}," + done + for TABLE in $TABLES; do + echo "[entrypoint] Dropping table: $TABLE" + STMTS="${STMTS}{\"type\":\"execute\",\"stmt\":{\"sql\":\"DROP TABLE IF EXISTS ${TABLE}\"}}," + done + if [ -n "$STMTS" ]; then STMTS="${STMTS%,}" curl -s "${TURSO_URL}/v2/pipeline" \ -H "Authorization: Bearer ${TURSO_TOKEN}" \ -H "Content-Type: application/json" \ -d "{\"requests\":[${STMTS},{\"type\":\"close\"}]}" > /dev/null - echo "[entrypoint] All tables dropped" + echo "[entrypoint] All indexes and tables dropped" else - echo "[entrypoint] No tables to drop" + echo "[entrypoint] Nothing to drop" fi fi fi |
