S
Supabase•2mo ago
Robin

Github integration issue -> Remote migration versions not found in local migrations directory.

Hello. Sorry in advance as I am not very knowledgeable when it comes to webdev. I have a project made by someone else so I am not entirely sure where to start. We have set up a website with supabase and vercel, and it works fine, but I'm trying to add vercel and github integration to my supabase account because I figured it would simply be easier to manage that way. But I am having an issue where when I push to git it simply fails the supabase preview check on github saying "Remote migration versions not found in local migrations directory.". The vercel check succeeds and the website updates regardless though. If anyone can help me resolve this or at least point me in the right direction in the docs or something I would appreciate it. I don't know what other information is relevant in this case, let me know and I'll see what I find.
36 Replies
ihm40
ihm40•2mo ago
Just to confirm, you added the github integration yourself and did you follow the instructions here https://supabase.com/docs/guides/deployment/branching/github-integration. I ask because i'm wondering if previously you were using the UI to manage your database and so your local database is completely our of sync with the remote one hence this mismatch in migration versions?
Robin
RobinOP•2mo ago
Yeah I added it myself and no I didn't follow this. I'll take a look at it thank you. I also didn't have a supabase folder in my repo, which I don't know if it matters or not for this. Just trying to reverse engineer a bit here. Maybe I should just make a new project and figure that out a bit first.
ihm40
ihm40•2mo ago
what does your repo look like?
Robin
RobinOP•2mo ago
No description
ihm40
ihm40•2mo ago
it does look like you have a supabase folder or did you add that now?
Robin
RobinOP•2mo ago
i added it now yeah been trying to figure out how to set this up
ihm40
ihm40•2mo ago
oh okay, yeah i would go through that guide then and see what happens. My best guess is that you need to tell github which folder it should use for supabase and then you have to pull your remote db schema down and then that should get you closer
Robin
RobinOP•2mo ago
Thanks I'll see how it goes
Robin
RobinOP•2mo ago
I'm at the supabase db pull step right now, but I am running into this error
No description
Robin
RobinOP•2mo ago
Any idea how I can sync the migration history to my local? without accidentally overwriting the history in my supabase dashboard 😬
ihm40
ihm40•2mo ago
try this, delete the (local) migrations folder and run supabase db pull i'm trying to make sure we only work on the local supabase instance and avoid touching the remote completely
Robin
RobinOP•2mo ago
It gives me the same error
ihm40
ihm40•2mo ago
what do you get if you type npx supabase migration list
Robin
RobinOP•2mo ago
No description
Robin
RobinOP•2mo ago
did fetch
ihm40
ihm40•2mo ago
For example, your migration history may look like the table below, with missing entries in either local or remote.

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
│ 20230103054303 │ 2023-01-03 05:43:03
20230103054315 │ │ 2023-01-03 05:43:15
To reset your migration history to a clean state, first delete your local migration file.

$ rm supabase/migrations/20230103054315_remote_commit.sql

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
│ 20230103054303 │ 2023-01-03 05:43:03
Then mark the remote migration 20230103054303 as reverted.

$ supabase migration repair 20230103054303 --status reverted
Connecting to remote database...
Repaired migration history: [20220810154537] => reverted
Finished supabase migration repair.

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
Now you can run db pull again to dump the remote schema as a local migration file.

$ supabase db pull
Connecting to remote database...
Schema written to supabase/migrations/20240414044403_remote_schema.sql
Update remote migration history table? [Y/n]
Repaired migration history: [20240414044403] => applied
Finished supabase db pull.

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
20240414044403 │ 20240414044403 │ 2024-04-14 04:44:03
For example, your migration history may look like the table below, with missing entries in either local or remote.

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
│ 20230103054303 │ 2023-01-03 05:43:03
20230103054315 │ │ 2023-01-03 05:43:15
To reset your migration history to a clean state, first delete your local migration file.

$ rm supabase/migrations/20230103054315_remote_commit.sql

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
│ 20230103054303 │ 2023-01-03 05:43:03
Then mark the remote migration 20230103054303 as reverted.

$ supabase migration repair 20230103054303 --status reverted
Connecting to remote database...
Repaired migration history: [20220810154537] => reverted
Finished supabase migration repair.

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
Now you can run db pull again to dump the remote schema as a local migration file.

$ supabase db pull
Connecting to remote database...
Schema written to supabase/migrations/20240414044403_remote_schema.sql
Update remote migration history table? [Y/n]
Repaired migration history: [20240414044403] => applied
Finished supabase db pull.

$ supabase migration list
LOCAL │ REMOTE │ TIME (UTC)
─────────────────┼────────────────┼──────────────────────
20240414044403 │ 20240414044403 │ 2024-04-14 04:44:03
ihm40
ihm40•2mo ago
it seems like in your situation when you have migrations in remote and not in local what you have to do is apply supabase migration repair <migration-tag> --status reverted for each of the remote migrations and then do supabase db pull
Robin
RobinOP•2mo ago
after fetching i have this
No description
Robin
RobinOP•2mo ago
but i also manually removed one that was added by supabase which i assume is bad 20240101000003_enable_public_products.sql
ihm40
ihm40•2mo ago
where did you remove it from, locally?
Robin
RobinOP•2mo ago
yeah, just moved it out of the supabase folder that was generated when i did init and stuff earlier supabase/migrations but

Connecting to remote database...
Applying migration 20240101000003_enable_public_products.sql...
ERROR: relation "products" does not exist (SQLSTATE 42P01)
At statement: 0
-- Enable public read access to products table
-- This allows the store to be accessed without authentication

-- Enable RLS on products table if not already enabled
ALTER TABLE products ENABLE ROW LEVEL SECURITY

Connecting to remote database...
Applying migration 20240101000003_enable_public_products.sql...
ERROR: relation "products" does not exist (SQLSTATE 42P01)
At statement: 0
-- Enable public read access to products table
-- This allows the store to be accessed without authentication

-- Enable RLS on products table if not already enabled
ALTER TABLE products ENABLE ROW LEVEL SECURITY
it keeps complaining about this products relation which seems related to that file. does it when i do pull as well which i am not sure if it's part of a larger issue
Robin
RobinOP•2mo ago
No description
Robin
RobinOP•2mo ago
basically it seems like actually idk
ihm40
ihm40•2mo ago
from this image and the one further up it seems like we shouldn't have that first file there? was that a local change you did?
Robin
RobinOP•2mo ago
No that was just added there by supabase i think. All I did was supabase init, supabase start, and supabase db pull that's why i removed it but i tried adding it back but without it, there also seem to be an error one sec i feel like this is just gonna be like pulling on a thread 😹 I just feel like these migrations are kinda busted?
Robin
RobinOP•2mo ago
No description
Robin
RobinOP•2mo ago
i don't know exactly how this works but i feel like these changes have already been applied to my supabase project the first migration says add_download_url_to_user_purchases so that's where it is throwing but further down there's remove_user_purchases_table so like should i just remove these and remove them in remote? like this is supposed to be history so idk why it's doing anything
ihm40
ihm40•2mo ago
what was the commend ran here?
Robin
RobinOP•2mo ago
supabase db pull like am i understanding this right that this is kind of like supabase's versioning system? if so i should be able to just purge this and start clean right?
ihm40
ihm40•2mo ago
as far as i'm aware you can purge and start again, i've confused myself now so it might be worth running supabase start in a different terminal and taking a look at your local database see what tables are/ are not there
Robin
RobinOP•2mo ago
Well just deleting and commiting after syncing them as we had done seems to have made it happy at least.
No description
Robin
RobinOP•2mo ago
now we'll see if it can do the rest of the github integration steps
ihm40
ihm40•2mo ago
haha one step closer
Robin
RobinOP•2mo ago
Ok I think after doing supabase migration repair --status reverted on all the migrations in the history in my dashboard it seems to all work now. I finished all of the steps on the github integration and its pushed to git and it has resolved successfully on both vercel and supabase Thanks a lot for the help
ihm40
ihm40•2mo ago
awesome, glad to hear it!

Did you find this page helpful?