A Postgres database for every GitHub branch 🤝

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
database branching means you can have separate database instances or entire superbase instances for each feature of your application so let's say you have a main branch in GitHub which is the production version of your application so on the superbas side you have a hosted production version of your database which is linked to your production application to read and write data but now you want to add some new functionality so you create a new Branch to work on your feature but what if it needs to change the structure of your database now with database branching you can spin up a separate instance of super base specifically for your feature Branch any changes that are made to the structure of the database are tracked in migration files which can then be committed to GitHub along with the rest of your application code for this new feature when you push those changes up to GitHub theel kicks off a new build and preview deploy of your application and seeing that there are new migrations we'll run those against the database Branch as well now when we're ready to merge this feature into production we simply merge this pull request and this will automatically deploy a new version of our application and run the new migrations against the production version of superbase so it's the workflow we know and love from G but now for your database I'm going to show you the process of building a new feature using branching to keep everything in sync let's get into it here I have a simple bookmarking app where I can keep a track of my favorite sites I can sign in with John superb. and my super secure password it's totally not just the word super secure with threes for ease and then as a signed in user I can see my favorite websites and a description for each one this is linked to my superbase project running locally so I have my studio instance here on Port 54323 and down here I'm printing out some helpful information that we can use while developing so this shows the URL and a non key for the superbase project we are currently connected to so we can see that's our instance running locally this app itself is written in nextjs and it has this superbase folder for our locally running instance which has each of our database migrations so anytime the structure of our database changes like we create a new table or add a new column we document each of those changes in a migration file so anyone on the team can run those migrations and ensure their local database instance is in the right state so this first migration is setting up some tables for Out book marks and then this one is enabling roow level security and adding some policies we also have this seed file to populate the database with some example data so we can see this is inserting a new user me in this case and then inserting some bookmarks of some of my favorite sites so this nextjs app has been cloned down from this repo which we can see is in the same state with those same migrations and this repo is used to deploy the live version of our application using versel so let's step through the process of building a new feature I want to add a favorite button for each of my bookmarks so over in my local instance of superbase I can just use the studio UI to add a new column with the name favorite which is of type bullion we can set the default value to false and turn off allow nullable as we always want this to be a bullan value of either true or false and let's click save to add that new column now I am super efficient at writing nextjs so I know that to build this feature I just need to uncomment this line to render the favorite component and look at that we now have a favorite button for each of our bookmarks and if I toggle one of these to be my favorite we can see that value is updated in superbase so our feature is ready to deploy but we now have app changes as well as database changes with a feature that's additive like this where we're just adding a new column it's not being used by anything until we deploy the new version of our app we could deploy the database first and then deploy our app but if we were changing the names of columns or deleting columns or dropping tables as I know we all love to do we could be a state where our application and our database are out of sync and our requests for data are actually failing but not anymore thanks to branching we can create a diff of any structural changes we've made locally by running superbase DB diff and writing the result to a file or - F and the name of our file will be add- favorite DB button now we can check that file to confirm that it's just altering our bookmarks table and adding a column for favorite and since this folder lives within our nextjs project we can commit this migration along with the changes required for our application to implement this favorite button so this is a feat or feature and it will add favorite schema changes so let's create that commit and then we can push our feature Branch to GitHub and open a pull request we can add a description that this will add the ability to favorite my bookmarks and create the pull request so we can see versel has detected these changes and is building and deploying a new preview version of our application and now superbase has detected some changes in the schema and is deploying a new preview database that's in exactly the same State as the feature we were working on locally while all of that is deploying we can check out our hosted superbase instance which is our production version of our database and now we have this drop down where we can select manage branches and see all the different instances or branches of our superbase project we can see our new preview branch has finished deploying so let's check it out by clicking here then we can head over to the table editor and click on our bookmarks table and see that our new favorite column has been added and it set the default value to false for all of our existing bookmarks so back over in verl we can see this preview deployment of our app and we can open that one up and see this login screen but if we take a look at the URL and a non key that this preview version is connected to it matches the preview branch of our superbase project so each feature the team is working on can have its own branch which is a completely isolated instance of super base specifically for this feature branch of the application very cool so let's sign in and we can see our new favorite buttons for each of our bookmarks and again if we favored a couple and head over to our superbase instance for this Branch those values have been updated this is is awesome let's deploy it to production so back over in our PR we can see that the checks have passed and these migrations will successfully run on the production database so all we need to do is merge this PR into our main branch that will run those migrations against our production database and deploy the new version of our application so back over in our hosted superbase Studio we can change the branch back to main or whatever our production branch is and then if we look at the table editor and the bookmarks table we can see that our new column has been added we don't have any data in production so let's go to our deployments in versel and open the production version of our application and we don't yet have an account so let's sign up as John superbase doio and my super secure password and we can add a new bookmark for ver.com and another one for openai and we can favorite this one for versel because our feature has been successfully deployed to production and now that you're a pro collaborating with others why not learn how easy it is to collaborate with robots by checking out this video right here where we use superbase AI to generate RLS policies making implementing author ation a breeze but until next time keep building cool stuff
Info
Channel: Supabase
Views: 4,798
Rating: undefined out of 5
Keywords:
Id: peXKxavGnBo
Channel Id: undefined
Length: 6min 34sec (394 seconds)
Published: Wed Dec 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.