Skip to main content

Database Reset & Reinstall

Full wipe-and-recreate of the Cloud Spanner schema and seed data. All scripts are dry-run by default — add --apply to execute.

Prerequisites

  • gcloud installed and authenticated (gcloud auth login)
  • Access to the target GCP project/Spanner instance/database
  • jq installed

Step 1: Drop all tables

# Dry-run (lists tables that would be dropped)
infra/scripts/drop-all-spanner-tables.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos

# Apply (destructive; requires typing a random confirmation string)
infra/scripts/drop-all-spanner-tables.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos \
--apply

Step 2: Apply schema from SQLDelight .sq files

The master schema is defined in SQLDelight .sq files under apps/specifications/schema/src/main/sqldelight/com/myriad/schema/.

The script extracts CREATE TABLE and CREATE INDEX statements from all .sq files, topologically sorts them by FK dependencies, and applies the DDL.

# Dry-run (shows parsed DDL, table order, and statement counts)
infra/scripts/apply-init-sql.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos

# Apply
infra/scripts/apply-init-sql.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos \
--apply

Step 3: Apply migrations and post-reset bootstrap extras

After the SQLDelight schema is in place, run the migration wrapper. It applies any future versioned files in apps/specifications/sql/migrations/ and the idempotent post-reset extras in apps/specifications/sql/bootstrap/ (for example, seed rows that .sq files cannot express).

# Dry-run (shows versioned migrations and bootstrap extras that would run)
infra/scripts/apply-spanner-migrations.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos

# Apply
infra/scripts/apply-spanner-migrations.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos \
--apply

Keep the dry-run output with the reset ticket before running with --apply.

Step 4 (optional): Bootstrap first superuser

infra/scripts/bootstrap-first-superuser.sh \
--project pinpoint-payments \
--instance pinpointpos-spanner \
--database pinpointpos \
--email you@company.com \
--first-name Your \
--last-name Name \
--firebase-id your-firebase-uid