first commit
This commit is contained in:
41
demos/cloudflare/scripts/reset-db.sh
Executable file
41
demos/cloudflare/scripts/reset-db.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
# Reset remote D1 database by deleting and recreating it.
|
||||
# With Access auth + autoProvision, users are recreated on first login.
|
||||
#
|
||||
# Usage: pnpm db:reset:remote
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DB_NAME="emdash-demo"
|
||||
WRANGLER_CONFIG="wrangler.jsonc"
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$SCRIPT_DIR/.."
|
||||
|
||||
echo "Deleting database '$DB_NAME'..."
|
||||
npx wrangler d1 delete "$DB_NAME" --skip-confirmation
|
||||
|
||||
echo "Creating new database '$DB_NAME'..."
|
||||
OUTPUT=$(npx wrangler d1 create "$DB_NAME" 2>&1)
|
||||
echo "$OUTPUT"
|
||||
|
||||
# Extract new database ID from output
|
||||
NEW_ID=$(echo "$OUTPUT" | grep -o '"database_id": "[^"]*"' | head -1 | cut -d'"' -f4)
|
||||
|
||||
if [ -z "$NEW_ID" ]; then
|
||||
echo "Failed to extract new database ID"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "New database ID: $NEW_ID"
|
||||
|
||||
# Update wrangler.jsonc with new ID
|
||||
if [ -f "$WRANGLER_CONFIG" ]; then
|
||||
echo "Updating $WRANGLER_CONFIG with new database ID..."
|
||||
sed -i '' "s/\"database_id\": \"[^\"]*\"/\"database_id\": \"$NEW_ID\"/" "$WRANGLER_CONFIG"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Database recreated. Next steps:"
|
||||
echo " 1. pnpm deploy (redeploy with new DB ID)"
|
||||
echo " 2. Visit /_emdash/admin to run setup wizard (applies seed content)"
|
||||
echo " 3. Access will auto-provision your admin user on first login"
|
||||
53
demos/cloudflare/scripts/reset-db.sql
Normal file
53
demos/cloudflare/scripts/reset-db.sql
Normal file
@@ -0,0 +1,53 @@
|
||||
-- Reset content and schema, preserving users and auth.
|
||||
-- After running this, redeploy and go through the setup wizard to re-seed.
|
||||
--
|
||||
-- Usage: npx wrangler d1 execute emdash-demo --remote --file=scripts/reset-db.sql
|
||||
--
|
||||
-- NOTE: D1 may not support IF EXISTS reliably. If a table doesn't exist,
|
||||
-- the statement fails and D1 aborts. Use reset-db.sh instead, which
|
||||
-- discovers existing tables dynamically.
|
||||
|
||||
-- Drop dynamic content tables
|
||||
DROP TABLE IF EXISTS ec_posts;
|
||||
DROP TABLE IF EXISTS ec_pages;
|
||||
|
||||
-- Drop FTS virtual tables
|
||||
DROP TABLE IF EXISTS ec_posts_fts;
|
||||
DROP TABLE IF EXISTS ec_pages_fts;
|
||||
|
||||
-- Drop emdash system tables (child tables before parents)
|
||||
DROP TABLE IF EXISTS _emdash_entry_taxonomies;
|
||||
DROP TABLE IF EXISTS _emdash_entries;
|
||||
DROP TABLE IF EXISTS _emdash_revisions;
|
||||
DROP TABLE IF EXISTS _emdash_seo;
|
||||
DROP TABLE IF EXISTS _emdash_comments;
|
||||
DROP TABLE IF EXISTS _emdash_fields;
|
||||
DROP TABLE IF EXISTS _emdash_collections;
|
||||
DROP TABLE IF EXISTS _emdash_taxonomy_terms;
|
||||
DROP TABLE IF EXISTS _emdash_taxonomies;
|
||||
DROP TABLE IF EXISTS _emdash_media;
|
||||
DROP TABLE IF EXISTS _emdash_menu_items;
|
||||
DROP TABLE IF EXISTS _emdash_menus;
|
||||
DROP TABLE IF EXISTS _emdash_widgets;
|
||||
DROP TABLE IF EXISTS _emdash_widget_areas;
|
||||
DROP TABLE IF EXISTS _emdash_sections;
|
||||
DROP TABLE IF EXISTS _emdash_redirects;
|
||||
DROP TABLE IF EXISTS _emdash_404_log;
|
||||
DROP TABLE IF EXISTS _emdash_plugins;
|
||||
DROP TABLE IF EXISTS _emdash_cron_tasks;
|
||||
DROP TABLE IF EXISTS _emdash_authorization_codes;
|
||||
DROP TABLE IF EXISTS _emdash_oauth_tokens;
|
||||
DROP TABLE IF EXISTS _emdash_device_codes;
|
||||
DROP TABLE IF EXISTS _emdash_api_tokens;
|
||||
DROP TABLE IF EXISTS _emdash_oauth_clients;
|
||||
|
||||
-- Clear options (setup flag etc.) so the setup wizard re-runs
|
||||
DROP TABLE IF EXISTS options;
|
||||
|
||||
-- Drop migration tracking so migrations re-run
|
||||
DROP TABLE IF EXISTS _emdash_migrations;
|
||||
DROP TABLE IF EXISTS _emdash_migrations_lock;
|
||||
DROP TABLE IF EXISTS d1_migrations;
|
||||
|
||||
-- Auth tables are intentionally preserved:
|
||||
-- users, passkeys, sessions, login_tokens, invites, oauth_accounts
|
||||
Reference in New Issue
Block a user