Developers love how easy it is to grow a SaaS business with SalableLearn more →
To set this script up, create a new file called extract-branch-name.js inside a scripts folder in the root of your repository and add the below code to it.
Bitbucket Pipeline & ENVs
To add the step to our Bitbucket pipeline, we can add the below code to our bitbucket-pipelines.yml file under the branches trigger.
This configuration will trigger the create branch script every time a branch is created or pushed to that starts with feature-db, this is why earlier we needed to update the create-db-branch function to not fail if we try to create an existing branch which would cause excess failures in our pipeline logs.
With our pipelines now configured, all we need to do is add in our environment variables on Bitbucket for the scripts to function correctly. To do that, head to “Repository Settings” and then “Repository Variables” for your repository. Then you’ll want to add in the below variables.
You’ll need to create a PlanetScale Service Token to perform the actions we’ve configured and run the CI scripts. To do this, you can follow their guide here.
- DB_NAME: Name of your database on PlanetScale.
- ORG_NAME: Name of your oragnization on PlanetScale.
- PLANETSCALE_SERVICE_TOKEN: The value of your PlanetScale Service Token.
- PLANETSCALE_SERVICE_TOKEN_ID: The ID of your PlanetScale Service Token.
After adding these variables, everything should be configured and we can test that everything works!
To test if everything has been setup correctly, create a new branch for your repository by using the Bitbucket UI or by creating one locally and pushing it. Ensure your new branch is using the pre-defined naming structure, in our case this is feature-db/YOUR_BRANCH_NAME.
Then after your branch has been created, watch your pipeline run and hopefully if all goes to plan, a new branch should have been created on PlanetScale using the name of your git branch. If this is the case then everything is working as expected!
In this post, we’ve covered how to configure a Bitbucket repository to use Bitbucket pipelines to create dedicated PlanetScale database branches based on if the source git branch uses a pre-defined naming structure. This aids us in not going above the 5 development branches and needing to upgrade to a more expensive plan just for a higher allowance.
I hope you found this post helpful.
Tech Blog #4: How to version all packages synchronously, in a monorepo using Lerna
Today we are setting up automatic versioning of packages inside of a monorepo using Lerna. There are many ways in which you can do this with different technologies...
Tech Blog #5: Automatically sync multiple repositories versions using GitHub Actions
Tech Blog #3: Using a private GitHub repository as an NPM package in another repository
Creating NPM packages is an easy and convenient way to share code across multiple projects. But, if you want to keep the package private and are unwilling to pay for the