From b48cf89ab323bd666be680f280b732eabe998e3f Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 9 Jun 2026 19:07:15 +0200 Subject: [PATCH] Add remote dev db back --- README.md | 19 +++++++++++++------ package.json | 3 ++- scripts/dev_db_reset.sh | 11 +++++++++++ scripts/dev_db_seed.sh | 32 ++++++++++++++++++++++++++++++++ scripts/dev_db_write_schema.sh | 31 +++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 7 deletions(-) create mode 100755 scripts/dev_db_reset.sh create mode 100755 scripts/dev_db_seed.sh create mode 100755 scripts/dev_db_write_schema.sh diff --git a/README.md b/README.md index 72e3491e..c1fe5fc0 100644 --- a/README.md +++ b/README.md @@ -160,9 +160,9 @@ Start the development server: yarn dev ``` -Note: the dev remote server is not available until further notice (to save money). The above command will start a local -server instead (same as `yarn dev:isolated` below). You'll have to set up Firebase and Supabase first (see below). -Contact us if you need help; we may spin up the dev remote server for you. +[//]: # 'Note: the dev remote server is not available until further notice (to save money). The above command will start a local' +[//]: # "server instead (same as `yarn dev:isolated` below). You'll have to set up Firebase and Supabase first (see below)." +[//]: # 'Contact us if you need help; we may spin up the dev remote server for you.' Once the server is running, visit http://localhost:3000 to start using the app. You can sign up and visit the profiles; you should see a few synthetic profiles. @@ -170,6 +170,13 @@ you should see a few synthetic profiles. Note: it's normal if page loading locally is much slower than the deployed version. It can take up to 10 seconds, it would be great to improve that though! +If you update the database schema (in the SQL files) or the database is not super clean or too large (e.g., someone +clogged it up), you can reset it to a clean state by running: + +```bash +yarn dev:db:reset +``` + #### Full isolation Running `yarn dev:isolated` spins up a local Supabase and Firebase emulator instead of pointing at the shared remote @@ -191,9 +198,9 @@ However, running in full isolation requires installing several heavy dependencie First startup is slow (30-60s) and the stack uses significant memory. If your machine has less than 8GB RAM, you may notice slowdowns. -[//]: # 'If this feels like too much, you can skip isolation entirely — `yarn dev` works out of the box against the shared remote' -[//]: # "and is perfectly fine for most contributions, especially UI changes, wording fixes, or anything that doesn't touch the" -[//]: # 'database or authentication.' +If this feels like too much, you can skip isolation entirely — `yarn dev` works out of the box against the shared remote +and is perfectly fine for most contributions, especially UI changes, wording fixes, or anything that doesn't touch the +database or authentication. ###### Setup instructions diff --git a/package.json b/package.json index 74b8ce8c..0c97a983 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "build-sync-android": "./scripts/build_sync_android.sh", "build-web-view": "./scripts/build_web_view.sh", "clean-install": "./scripts/install.sh", - "dev": "yarn dev:isolated", + "dev": "./scripts/run_local.sh dev", + "dev:db:reset": "./scripts/dev_db_reset.sh", "dev:isolated": "./scripts/run_local_isolated.sh", "emulate": "firebase emulators:start --only auth,storage --project compass-57c3c", "postinstall": "./scripts/post_install.sh", diff --git a/scripts/dev_db_reset.sh b/scripts/dev_db_reset.sh new file mode 100755 index 00000000..30d0db0a --- /dev/null +++ b/scripts/dev_db_reset.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +./scripts/combine-migrations.sh + +./scripts/dev_db_write_schema.sh + +./scripts/dev_db_seed.sh diff --git a/scripts/dev_db_seed.sh b/scripts/dev_db_seed.sh new file mode 100755 index 00000000..be5416cd --- /dev/null +++ b/scripts/dev_db_seed.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +source .env + +export ENV=dev +export ENVIRONMENT=dev + +export DATABASE_URL="postgres://postgres.zbspxezubpzxmuxciurg:ZTNlifGKofSKhu8c@aws-1-us-west-1.pooler.supabase.com:6543/postgres" + +cd tests/e2e/utils + +npx tsx seed-test-data.ts + +# May need to run this as well +#ALTER SCHEMA public OWNER TO postgres; +#GRANT ALL PRIVILEGES ON SCHEMA public TO postgres; +#GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres; +#GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO postgres; +#ALTER DEFAULT PRIVILEGES IN SCHEMA public +# GRANT ALL ON TABLES TO postgres; +#ALTER DEFAULT PRIVILEGES IN SCHEMA public +# GRANT ALL ON SEQUENCES TO postgres; +# +#grant usage on schema "public" to anon; +#grant usage on schema "public" to authenticated; +# +#GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA "public" TO authenticated; +#GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA "public" TO anon; diff --git a/scripts/dev_db_write_schema.sh b/scripts/dev_db_write_schema.sh new file mode 100755 index 00000000..5cda55e4 --- /dev/null +++ b/scripts/dev_db_write_schema.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")/.." + +source .env + +#export ENV=dev + +CONN="postgres://postgres.zbspxezubpzxmuxciurg:ZTNlifGKofSKhu8c@aws-1-us-west-1.pooler.supabase.com:6543/postgres" + +MIGRATIONS_DIR="supabase/migrations" + +if ! ls "$MIGRATIONS_DIR"/*.sql >/dev/null 2>&1; then + echo "❌ No migrations found in $MIGRATIONS_DIR. Run ./scripts/combine-migrations.sh first." + exit 1 +fi + +echo "⚠️ About to DROP SCHEMA public on CONN and re-apply all migrations." + +# Clear existing schema +psql "$CONN" -v ON_ERROR_STOP=1 -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" + +# Apply new schema (just the schema, not the data obviously), in lexical order +for f in "$MIGRATIONS_DIR"/*.sql; do + echo "→ Applying $(basename "$f")" + psql "$CONN" -v ON_ERROR_STOP=1 -f "$f" +done + +echo "✅ Schema written to remote dev supabase"