Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support declarative schema with db diff #2099

Merged
merged 5 commits into from
May 3, 2024
Merged

Conversation

sweatybridge
Copy link
Contributor

@sweatybridge sweatybridge commented Mar 27, 2024

What kind of change does this PR introduce?

closes #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
  • 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.

@sweatybridge sweatybridge requested a review from a team as a code owner March 27, 2024 10:59
@coveralls
Copy link

coveralls commented Mar 27, 2024

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%
Files with Coverage Reduction New Missed Lines %
internal/gen/keys/keys.go 5 11.76%
Totals Coverage Status
Change from base Build 8933751783: -0.3%
Covered Lines: 6386
Relevant Lines: 11110

💛 - Coveralls

@sweatybridge sweatybridge merged commit 52d679f into develop May 3, 2024
9 checks passed
@sweatybridge sweatybridge deleted the dec-schema branch May 3, 2024 04:36
@github-actions github-actions bot mentioned this pull request May 7, 2024
@xleddyl
Copy link

xleddyl commented Sep 16, 2024

@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?

@sweatybridge
Copy link
Contributor Author

oh.. you need to stop the local stack first with supabase stop before running supabase db diff. Otherwise it will always connect to the locally running db instead.

@xleddyl
Copy link

xleddyl commented Sep 19, 2024

Thank you so much, I’ll give it a try! By the way, I think this feature should be highlighted in the official docs. It’s incredibly useful and essential for efficiently managing migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-generate a schema.sql file when you run migrations
3 participants