From bfa499f7ef3d63798ade617165768c626647457b Mon Sep 17 00:00:00 2001 From: Bobby <30593201+luciferreeves@users.noreply.github.com> Date: Wed, 11 Mar 2026 00:02:08 +0530 Subject: feat: improve database seeding process with detailed logging for table drops --- scripts/entrypoint.sh | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'scripts') 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 -- cgit v1.2.3