[GUIDE] Sync local and prod schemas when they're out of sync #18483
techwizzdom
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Thank you so much for this explanation! Follow-up question, do we check the remote_schema.sql into version control? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey all 👋🏼,
I noticed that many people have problems when they make changes in remote DB and local DB only by clicking around the Supabase UI - and then, projects go out of sync. As a consequence, you cannot make nice migrations with
db diff/push
.I had the same problem, but I finally found a solution I don't see it in the documentation, so I'm sharing it here:
This will create a remote schema in
supabase/migrations/{{timestamp}}_remote_schema.sql
.This will create a difference between local and remote DB schemas in
supabase/migrations/{{timestamp}}_initial_diff.sql
.Go through
*_initial_diff.sql
file and see the differences. Keep only those you want to apply to the remote.When you're ready, do:
This will show which migrations will be applied to the remote, it will not actually push them. It's just for checking. If you did everything right, you should see only the
initial_diff
migration:Check your remote - changes in initial_diff should be applied.
new_column
to tablescreenplays
via UI. If you then do:A new file
supabase/migrations/{{timestamp}}_add_new_column.sql
will be created and inside you should see only:And changes you kept from the initial diff (if any).
It would be awesome to add this to the official docs.
Beta Was this translation helpful? Give feedback.
All reactions