Deploy Local Database Changes to Supabase Remote Through Github Actions

Ben Patton
InstructorBen Patton
Share this video with your friends

Social Share Links

Send Tweet
Published 9 months ago
Updated 2 days ago

In common workflows we do not want to push directly to the remote database from our machine. We will setup a github action that will run whenever we push to our main branch of our github repo.

[00:00] If you remember back to a previous lesson, we used Supabase db push to push our changes in our local database to our remote database. Now, when you're working on a team, you most likely don't want to have that workflow. You probably want to have some sort of CICD set up so that when you push to your GitHub repository, [00:20] it picks up those changes as a part of c I and then deploys them. So first, I have a GitHub repository set up. And then you'll notice I have this GitHub workflows set up. So you want to create a GitHub folder with a workflows folder in it. And then I've just called this prod to dos dot YAML. And this error here is because I have an extension. It's a YAML extension. If [00:40] you want to install it, you can just install it from the v s code. Marketplace is the first one in the list. And it just helps with formatting because you may get syntax errors otherwise when your action gets pushed to GitHub and it tries to run it. So I'm gonna go ahead and paste our code here, and we're gonna save that. And we're gonna leave this alone for a second. Let's go ahead and come back into our project that's running locally and [01:00] let's just create a new table and we'll call this users. We'll just add a user name column and this will be of type text. Save. Okay. So now we have a user's table in our local database. So back in our terminal, we need to run m p x x super base d b diff. And then we want to create a file and we'll just name this users table created. And this time instead of [01:19] pushing with super base d b push, we're gonna use our newly created action here that references our project to push as part of the GitHub action. So if we wanna just run through this GitHub action file real quick, we're just saying every time we push to the main branch, we want to run this action. And we have some environment variables set in our GitHub secrets. [01:39] And then we're gonna run this super base link to our project and then we're gonna push any changes that picked up it picks up in our super base file to our remote database. So now if we come back to GitHub and let's look at our settings, we can come to secrets and variables, actions. You'll see I've already created my secrets. So what you wanna do [01:59] here is just grab the names over here. You'll create a new repository secret. This will be the name. And then whatever your access token is in your project, you'll give that as the value. Same thing with your password when you created your database and then the project ID. And if you need help finding those values, you can come into settings, go to usage, and then you can find your access token here. Or you can [02:19] generate a new one if you don't remember it. And then to find your project ID, you come into project settings and it's this reference ID value. And then the password is the password you created whenever you created the database. And if you need to create a new password, you can come here and you'll see we open this a little bit more. We can reset the database password. Let's close that. We can come [02:39] back to our project and let's come back to the code. And so now that we have dipped our database and we have the migration file, we get this message here that says, you should run through base DB reset. And this is just to test that everything is working properly locally before we push to GitHub and try to merge it into our remote database. So we can run p x [02:59] super base d b reset. Okay. That's finished running and everything is working fine. So now we can run git add. We'll give it a commit message. Created GitHub action and then we'll push. Okay. And then we want to come into our actions and you'll see this action is running. Ignore all of these. This was for testing. And so we can come in here now and we can look at [03:19] our deploy. So Super base DB push has ran and it applied the migration. So now if we come into our actual project and let's come back to our table editor, we now have our users table.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today