Open-source schema for the self-hosted Supabase instance behind the WaspScripts projects which is hosted through a self-hosted Coolify instance.
This repo contains structure only — tables, columns, functions, triggers, views, RLS policies, and foreign table definitions — with no row data. It's meant to let anyone inspect the database design or spin up a matching instance from scratch.
- Schemas:
public,profiles,scripts,stats,stripe,info - All tables, columns, constraints, indexes, sequences
- All views
- All functions (including trigger functions)
- All triggers
- All Row Level Security (RLS) policies
- RLS policies on Supabase's
storageschema (supabase/storage_policies.sql) - Foreign table definitions for the Stripe wrapper (
stripeschema) — these reference a foreign server by name only; no credentials are included (see below)
Supabase's own internal schemas (auth, storage, realtime, extensions, vault,
cron, net, pgbouncer, pgsodium, etc.) are intentionally excluded. These are
recreated automatically by Supabase's own Docker images when you spin up a fresh
self-hosted instance — they don't belong to this project. The one exception is the RLS
policies on storage tables (e.g. storage.objects), which are project-specific and
are kept in supabase/storage_policies.sql.
- Any row data
- Supabase's internal schemas and their migrations
- Any secrets or credentials. The
stripeschema's foreign tables reference aSERVER "stripe_wrapper_server"that is defined separately (outside this dump) and backed by a Supabase Vault secret reference — never a literal API key.
-
Stand up a self-hosted Supabase instance using the official Docker setup.
-
Install any required extensions your schemas depend on (e.g. the Stripe Wrapper if you want the
stripeschema's foreign tables to actually resolve data). -
Apply the migrations in
supabase/migrations/in order, e.g.:supabase db push --db-url "postgresql://postgres:<password>@<host>:<port>/postgres" -
Apply
supabase/storage_policies.sqlto recreate the storage bucket access rules. -
If you use the Stripe Wrapper, create the foreign server and Vault secret yourself — see Supabase's Wrappers docs linked above. This repo does not include that setup since it's credential-specific to each deployment.
supabase/schema.sql is the live, always-current snapshot of the schema. It's kept up
to date by the db-utils container, which runs inside the Supabase stack
(docker-compose.yml) and reaches Postgres over the internal Docker network, so the
database never needs to be exposed to the internet. Its script,
volumes/db-utils/sync.sh:
- Dumps the schema for
public,profiles,scripts,stats,stripe,infowith the samepg_dumpflags andsedcleanup thatsupabase db dumpuses, so the output format is identical. - Dumps the
storageschema separately and extracts only its RLS statements intosupabase/storage_policies.sql. - Runs a grep-based secret scan over the fresh dumps as a safety net before committing.
- Commits and pushes
supabase/schema.sqlandsupabase/storage_policies.sqlonly if they actually changed.
It runs every 24 hours as a Coolify scheduled task. To run it on demand, open the
db-utils container's terminal and run:
sync| Variable | Description |
|---|---|
WASP_DB_DEPLOY_KEY |
Base64 of the private key of a write-enabled deploy key for this repo (base64 -w0 <key>) |
The database credentials come from the stack's existing SERVICE_PASSWORD_POSTGRES, so
nothing database-related is stored outside the server.
The same db-utils container also runs volumes/db-utils/trim-logs.sh weekly as a
Coolify scheduled task. It connects to the _supabase database as supabase_admin,
calls analytics_cleanup_old_logs() and then runs VACUUM ANALYZE.
To run it on demand, open the db-utils container's terminal and run:
trim-logsThe scheduled task definitions are kept in cron_tasks/ for reference.
supabase/migrations/ holds the one-off, manually curated baseline migration used to
originally seed a fresh instance. It is not updated automatically — supabase/schema.sql
is the source of truth for "what does the schema look like right now."