cli
cli copied to clipboard
feat: support declarative schema with db diff
What kind of change does this PR introduce?
closes https://github.com/supabase/cli/issues/1215
What is the new behavior?
- Add schema files to
supabase/schemas(they will be run in lexical order)- Easiest way to create one is
supabase db dump --local -f supabase/schemas/base.sql
- Easiest way to create one is
- Then run
supabase db diff
A new local database will be created from declared schemas for diffing.
$ supabase db diff
Creating local database from supabase/schemas...
Setting up initial schema...
Creating custom roles supabase/roles.sql...
Applying schema supabase/schemas/base.sql...
Connecting to local database...
Creating shadow database...
Setting up initial schema...
Creating custom roles supabase/roles.sql...
Applying migration 20231204107450_grant.sql...
Diffing schemas: extensions,private,public
Finished supabase db diff on branch dec-schema.
No schema changes found
Additional context
Add any other context or screenshots.
Pull Request Test Coverage Report for Build 8933882059
Details
- 11 of 64 (17.19%) changed or added relevant lines in 6 files are covered.
- 5 unchanged lines in 1 file lost coverage.
- Overall coverage decreased (-0.3%) to 57.48%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| internal/db/diff/pgadmin.go | 0 | 1 | 0.0% |
| internal/utils/flags/db_url.go | 0 | 1 | 0.0% |
| internal/db/diff/diff.go | 6 | 57 | 10.53% |
| <!-- | Total: | 11 | 64 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| internal/gen/keys/keys.go | 5 | 11.76% |
| <!-- | Total: | 5 |
| Totals | |
|---|---|
| Change from base Build 8933751783: | -0.3% |
| Covered Lines: | 6386 |
| Relevant Lines: | 11110 |
💛 - Coveralls
@SweatyBridge I tried creating a supabase/schemas folder and putting the definitions inside, but I can't manage to make the script work. It always diffs the local DB with the one generated from the migrations and not the schema.
Can you check if this still works or has been deprecated?