supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
1.09k stars 212 forks source link

Supbase local migration not being updated in remote #2136

Closed emmyduruc closed 7 months ago

emmyduruc commented 7 months ago

Bug report

i am using the CLI migration locally is up-to-date and i can see new tables in studioURL but when i run $ "supabase db push" Connecting to remote database... Remote database is up to date. and when i check my remote db the changes are not up-to-date

Describe the bug

the Remote db is not getting updated A clear and concise description of what the bug is. i am using the CLI migration locally is up-to-date and i can see new tables in studioURL but when i run $ "supabase db push" Connecting to remote database... Remote database is up to date.

To Reproduce

supabase create new migration

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '…'
  2. Click on '…'
  3. Scroll down to '…'
  4. See error

Expected behavior

That the local changes should be in the remote when i run supabase db push A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

Additional context

Add any other context about the problem here.

saltcod commented 7 months ago

Thanks @emmyduruc — do any of the other local commands work? (ie: are you certain the project is linked correctly?)

emmyduruc commented 7 months ago

Thanks @emmyduruc — do any of the other local commands work? (ie: are you certain the project is linked correctly?)

the project is linked correctly all other local commands works effectively

sweatybridge commented 7 months ago

Could you run supabase migration list and share the output?

emmyduruc commented 7 months ago

Could you run supabase migration list and share the output? here is the output from "supabase migration list" image

sweatybridge commented 7 months ago

It does seem like all your local migrations are already pushed to remote.

Can you elaborate which migration file and which statement is missing on remote?

emmyduruc commented 7 months ago

They are pushed to remote but i do not see the new tables the local and remote tables looks totally different though the migrations are in sync

sweatybridge commented 7 months ago

Can you run supabase projects list to check that you are linked to the right project?

If so, run supabase db pull. This will pull down schema changes from remote to local so they are back in sync.

emmyduruc commented 7 months ago

Can you run supabase projects list to check that you are linked to the right project?

If so, run supabase db pull. This will pull down schema changes from remote to local so they are back in sync.

@sweatybridge thanks for your comment.... i have checked the project list it seems i am connected to the right project i also pulled the remote yet they remain unsynced Local Remote
Screenshot 2024-04-11 at 13 42 40 Screenshot 2024-04-11 at 13 35 52

I literally have no clue on how to resolve this as it seems super frustrating

sweatybridge commented 7 months ago

One more question to check: have you saved all your local migrations to disk? This can be done with supabase db diff which should report no changes found.

emmyduruc commented 7 months ago

One more question to check: have you saved all your local migrations to disk? This can be done with supabase db diff which should report no changes found.

Unfortunately did not help

sweatybridge commented 7 months ago

Unfortunately did not help

What's the output from supabase db diff and supabase db diff --linked?

sweatybridge commented 7 months ago

As a last resort, you can also reset your remote database: supabase db reset --linked

This will delete all data in your remote database so make sure to have a backup.

sweatybridge commented 7 months ago

Any updates on this one? There's another way to sync up your schema

  1. Start a local database

    supabase db start
  2. Backup your migrations directory

    mv supabase/migrations supabase/backup
  3. Dump your remote schema

    mkdir supabase/migrations
    supabase db dump -f supabase/migrations/0_schema.sql
  4. Save local diff as a migration file

    supabase db diff -f schema_drift
  5. Repair your migration history and push

    supabase migration repair --status reverted
    supabase migration repair --status applied 0
    supabase db push

I think these steps will be simpler with declarative schema. But for now, you will have to fix the schema drift using those steps above.