how to connect one github repo to different supabase branch projects
I have an app that has two github branches (main, development) which currently link to supabase branches (main, development).
when I swtich branches in my editer, and run db pull or link status it always points the project to the main project branch project ref. why is this? What is the best practice to handle a prod and development branch?
I want my supabase UI to be the source of truth, but im super confused how supabase migrations or schemas work. I need to keep them up to date with the remote db, but how?
33 Replies
I think that db pull/link always references your actual project and does not mention branches
if you want to see the branches you have for a project you can do
supabase branches list
If you have a main and development branch and you are using github, what you would want to do is do all you changes for migrations and anything else in the GIT branch and then push those changes to your github dev branch. If everything is synced up correctly then you should see schema changes reflected in dev branch on supabase dashboard.
When you are happy, you can merge that github branch and then it will migrate any schema changes to the main branchthanks for the reply! Does this mean making all schema changes locally through CLI? So I shouldn't use the UI?
i've found that to keep things tracked for myself better i will use local migration files using supabase local and github branches to test those migrations
could you give me a walk through of the steps you take when you make a change in the DB?
say I make a change in the supabase UI (add a table)
what do I need to do to ensure my git repo supabase folder is up to date
i would start supabase local -> get a new github branc -> use the UI to make changes -> get the migration file using
db diff --local -f <my_change_name>
-> commit those changes and push the branch to gitub and create a pull request
This should spin up a branch on supabase that i can expect (note a few people have been having some issues here recently with respect to missing tables/edge functions)
when i'm happy i would merge the changes using the platform ui switch back to main branch locally and do git pull
<my_change_name> where does this come from? the github branch name or the commit message?
and when you say start in supabase local - does this mean my projects CLI?
right now I am having an issue when I have two on going supabase branches - each "linked" to the corresponding branch in github , but when I try to check which supabase project is linked in my CLI - it always points to the main project
local means cli
yeah i think that this could be clearer, branches are not really managed locally except with github
so the branch you are editing should be determined by github branch
ohhhhh i see
so github is the source of truth for branches?
the change name comes form whatever you call it i.e
added_profiles_table
does this mean for each github branch there should be a diferent supabase folder which points to the corresponding branch in supabase?
nope
same supabase folder but just different github branches
as long as you use github to push the changes it will reflect on the branches n it's own
i hope im not overstepping
would you be available for a quick call
if not totally get it
do you want to try the hangout?
lets do it
im in the hangout
@ihm40 I was able to get the local instance running and everyihing working for the main branch.
now I want to make a new development supabase branch (am currently on my development git branch)
and I want to push db changes to the development supabase branch. do u know how I can do this? all of AI answers are out of date and not working
supabase db branch create development
I was able to use this to make the branch but then this:
supabase db push --branch development
does not work. i would also like to start the development branch locally through this:
'''supabase start --branch development'''
i don't know if you can work with branches locally like that. What i would say is push your changes to your gitub branch. Navigate to supabase platform and see if it creates a branch for you otherwise create a new branch using the UI and point it to your github branch
is there a way to run a specific supabase db branch locally?
i haven't found a way to do that and i don't think that supabase local has this idea of branching because at a high level a branch is almost like a seperate project with it's own database and edge functions etc. It's just that the supabase platform has orchestrated it in such a way that you can create changes and "merge" them
So it uses github branches as the source of reference for what a branch should look like
would u recommend making a new project then? instead of using the supabase branch system? and then when I merge my git dev branch into git main I'll just have to change a few endpoints here and there?
i'm not sure how that would work. I have seen people have a whole seperate project on supabase platform for for "staging" and what they do is push changes to staging first after making it locally and if everything looks good they would push changes to main
i would try and get branching working if you can because that is a lot of work to manage
yeah i want to keep branches too for my edge functions mainly and all the data i dont want to have to migraete that over
so now that my lcoal is working- do u recommend me make a branch through CLI locally and then push to see if its reflect in supabase?
branches are made through git not through the cli (for the most part), supabase because it is connected to github should pick up on branches and create the supabase branch for you
i would say try get that working, a few people have reported some issues in the last few days with platform branching though so beware of that also
okay interestingly enough this just made a branch for me:
upabase branches create development
in supabase
but the branch is compltely empty.
yeah you would probably need to point that branch to a github branch
on supabase platform
oh wait it just took a second now everything is popuilated again
okay making progress now. i made it a persistent banch.
oh yeah that would make sense, takes a while usually
how can I check which supabase branch my current git development branch is pointing to?
does it just point to the same one as the name?
if I start the supabase server, does it start an instance of the development branch?
yeah should do
if you are on the development branch then it should reflect the changes on that branch
but thats because the migration files and config.toml will be the same
so if I make a new table through the CLI, then I can check if the tables made my running start locally.
then once I push - it should imemdiatly go to the development branch ?
if you run
supabase db push
it won't go to development but to main branch i think
if you run git push
it should go to the development branchif I merge into main will it also update the main supabase db? or does that require the supabase db push command
it should update main supabase
have you used workdirs for supabase? keeping one for dev and one for prod?
the only thing is you may need to do pull for main locally to get the right migration files and edge functiosn
i haven't