Skip to content

Commit 48bc955

Browse files
authored
ENG-1244 Correct the sqldiff process (#673)
* ENG-1244: use pg-schema for dbdiff; add migra as legacy command; document
1 parent fa2e614 commit 48bc955

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/database/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ We follow the Supabase [Declarative Database Schema](https://supabase.com/docs/g
3636
1. Assuming you're working on a feature branch.
3737
2. Make changes to the schema, by editing files in `packages/database/supabase/schemas`
3838
3. If you created a new schema file, make sure to add it to `[db.migrations] schema_paths` in `packages/database/supabase/config.toml`. Schema files are applied in that order, you may need to be strategic in placing your file.
39-
4. `turbo check-schema`, which will do the following:
39+
4. `pnpm run check-schema`, which will do the following:
4040
1. Check your logic with `sqruff lint supabase/schemas`
4141
1. If there are errors there, you can fix them with `pnpm run lint:fix`
4242
2. Stop Supabase.
43-
3. See if there would be a migration to apply with `supabase db diff`
43+
3. See if there would be a migration to apply with `pnpm run dbdiff`
44+
4. Also check with `pnpm run dbdiff:legacy`, which has known false positives (esp. views), but is more complete (esp. with respect to grants).
4445
5. If applying the new schema fails, repeat step 4
4546
6. If you are satisfied with the migration, create a migration file with `pnpm run dbdiff:save some_meaningful_migration_name`
4647
1. If all goes well, there should be a new file named `supabase/migrations/2..._some_meaningful_migration_name.sql` which you should `git add`.
48+
2. If there were _valid_ migration steps identified by `dbdiff:legacy` that were missing in `dbdiff` you may have to add them by hand to that file.
4749
7. `pnpm run migrate`, which will do the following:
4850
1. Start Supabase
4951
2. Apply the new migration locally

packages/database/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
"test": "pnpm run build && cucumber-js",
3636
"genenv": "tsx scripts/createEnv.mts",
3737
"gentypes": "tsx scripts/genTypes.ts",
38-
"dbdiff": "supabase stop && supabase db diff",
39-
"dbdiff:save": "supabase stop && supabase db diff -f",
38+
"dbdiff": "supabase stop && supabase db diff --use-pg-schema",
39+
"dbdiff:legacy": "supabase stop && supabase db diff",
40+
"dbdiff:save": "supabase stop && supabase db diff --use-pg-schema -f",
4041
"deploy": "tsx scripts/deploy.ts",
4142
"deploy:functions": "tsx scripts/deploy.ts -f"
4243
},

0 commit comments

Comments
 (0)