cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open saltcod opened this issue 2 years ago • 2 comments

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.

saltcod avatar Jun 16 '23 12:06 saltcod

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

CareTiger avatar Jun 20 '23 02:06 CareTiger

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

jonkurtis avatar Mar 19 '24 00:03 jonkurtis