diff options
| author | Bobby <[email protected]> | 2026-03-11 00:02:08 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-11 00:02:08 +0530 |
| commit | bfa499f7ef3d63798ade617165768c626647457b (patch) | |
| tree | d59af19d54677a69add84e9a4fea11f44925bd52 /scripts | |
| parent | 0014f60955760ffd6bd6bfd2e01ada6ea2502f81 (diff) | |
| download | pagoda-bfa499f7ef3d63798ade617165768c626647457b.tar.xz pagoda-bfa499f7ef3d63798ade617165768c626647457b.zip | |
feat: improve database seeding process with detailed logging for table drops
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/entrypoint.sh | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index bad1c63..a1e6408 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,12 +1,43 @@ #!/bin/bash set -e +if [ "$SEED" = "true" ]; then + echo "[entrypoint] SEED=true, wiping database..." + if [ "$DB_DRIVER" = "sqlite" ]; then + rm -f "$DSN" + echo "[entrypoint] Deleted $DSN" + elif [ "$DB_DRIVER" = "libsql" ]; then + TURSO_URL=$(echo "$DSN" | sed 's|^libsql://|https://|; s|?.*||') + TURSO_TOKEN=$(echo "$DSN" | sed -n 's/.*authToken=\(.*\)/\1/p') + 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"}]}' \ + | sed 's/{"type":"text","value":"/\n/g' | sed -n 's/"}.*/\1/p' | sed '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="${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" + else + echo "[entrypoint] No tables to drop" + fi + fi +fi + echo "[entrypoint] Starting shrine server..." ./shrine & SHRINE_PID=$! if [ "$SEED" = "true" ]; then - echo "[entrypoint] SEED=true, waiting for server on port ${PORT:-3000}..." + echo "[entrypoint] Waiting for server on port ${PORT:-3000}..." RETRIES=0 MAX_RETRIES=30 until bash -c "echo > /dev/tcp/localhost/${PORT:-3000}" 2>/dev/null; do |
