Skip to content

Auto-generate a schema.sql file when you run migrations #1215

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

Closed
saltcod opened this issue Jun 16, 2023 · 2 comments · Fixed by #2099
Closed

Auto-generate a schema.sql file when you run migrations #1215

saltcod opened this issue Jun 16, 2023 · 2 comments · Fixed by #2099

Comments

@saltcod
Copy link
Contributor

saltcod commented Jun 16, 2023

Is your feature request related to a problem? Please describe.
I often want to know what my table schema looks like. To do this, I need to open the Dashboard table editor for the table in question, then scroll to see the columns.

Describe the solution you'd like
Rails has a schema.rb file that does this. (I think) When you run a migration, it updates the schema.rb file with a snapshot of all current tables and their schema.

The accepted answer for this question gives a concise explanation of why this file is useful:
https://stackoverflow.com/questions/9884429/rails-what-does-schema-rb-do

CleanShot 2023-06-16 at 09 45 59@2x

Here's a schema.rb example:

CleanShot 2023-06-16 at 09 48 16@2x

This file could live in /supabase/schema.sql

Describe alternatives you've considered
Generating types to a types.ts file is also helpful, but its a little noisier than this schema.sql approach.

@CareTiger
Copy link

doesnt supabase db dump -f supabase/schema.sql do this?

@jonkurtis
Copy link

doesnt supabase db dump -f supabase/schema.sql do this?

it does indeed.

however, i think an alternative approach that would better accomplish the intended DX would be to create all schemas in a /schemas file, then be able to run db reset to run off of /schema files instead of /migrations. then run db diff --use-migra on the newly reset schema to generate migration files.

when you want to change a schema file you change it in /schema instead of /migrations, editing the original schema SQL. db reset off of /schema. db diff off of newly reset local db to update migrations to push up to prod.

this enables you to better organize files under /supabase/schema/users.sql, /supabase/schema/teams.sql. can also include comments and organize each file as desired.

easier to reason about than one big dump into schema.sql

You would need to be able to tell supabase db reset to look at /supabase/schema/ instead of /migrations

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

Successfully merging a pull request may close this issue.

4 participants