Understanding migrations
You’ve already used migrations with supabase db diff
and stored database data in seed.sql
with supabase db dump
. In fact, throughout this book, with every new chapter, I created an iteratively growing schema with supabase db diff
. Whenever I changed something in the structure of the database, for example, when I added functions in the rls_helpers
schema (or even the schema itself), I ran the following:
npx supabase db diff --local \ --schema rls_helpers -f added_XYZ_in_rls_helpers
If you work like this when you develop your Supabase projects, you’ve already got iterative migration files.
Note
I wouldn’t have to explicitly use --schema rls_helpers
, but when I know which schema changed, I usually only pinpoint to that specific schema. It makes the process of creating the migration slightly more efficient.
Now, when I want to push only new changes to a production database (so not doing a full reset but only adding the new/changed...