PlanetScale pscale CLI helper scripts (Recording from live demo at PlanetScale Happy-Half-Hour)
Ever wanted to accomplish a complex database workflow with pscale CLI and needed a way to automate asynchronous operations like database branch creation or schema change requests merges? Interested in using the PlanetScale database branching, approval and merging features directly out of your pull/merge requests?
This is a collection of helper scripts around the PlanetScale CLI to synchronously
- wait for branch creation to be completed
- wait for deploy requests to be successfully merged (and get an update on the current migration status)
- DB connection string creation/parsing and extending scope of service tokens
- examples on how create branches and deploy requests (branches, credentials, deploy requests)
- creating one-time links with connection info for feature branches that correspond to your preview environments
- run pscale from a Docker container and still use your local config files, service tokens and port forwarding
- delete databases
In the issues section of this repo you will find examples how to integrate your favorite framework and CI with the pscale workflow examples provided here. If you have our own examples you like to share with the commmunity and get the chance to win some swag, please add your example here.
In case you like to see those helper scripts in action without any further manual configuration, just
- Create a copy of this repo by clicking on the green 'Use this template' button or just here. Both private and public repo visibility work.
-
Create a PlanetScale account: If you have not done already, sign up here for a PlanetScale account, you can have one database for free. Do not create a database yet though, this step will be automated as part of the first Action workflow.
-
Switch to the Actions tab in your repo
- Start the workflows manually, in the displayed order.
- When you run the workflows, follow the output where it will ask you to authenticate to PlanetScale by clicking the displayed links.
The workflows covered so far have been all triggered as manual GitHub Action jobs. If you start the "Create branch/PR for schema change" workflow, a pull request like this one will be created that is associated with a PlanetScale deploy request and the desired schema changes. Those schema changes can then be applied by adding a /ps-merge
comment to the pull request. This IssueOps command will also create GitHub deployment events, so that you could have other integrations and Action based workflows hook into the deployment lifecycle.
You can also create a database branch and deploy request based on an already existing Pull Request using /ps-create
:
If you like to refresh the schema information of your branch or add additional DDL statements, use /ps-update
:
Approvals can be done using /ps-approve
:
Finally, you can delete the database branch associated with a Git branch using /ps-delete
:
Stay tuned for updates and any feedbacks / PRs are welcome 😊