Skip to content

blackjack2693/planetscale-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlanetScale Workflow Helper scripts

I Edit this readme right now :D

📺 Recording from live demo at PlanetScale Happy-Half-Hour

📺Longer talk at WeAreDevelopers DevOps Day

This is a collection of GitHub Workflows and CI/CD helper scripts around PlanetScale's database branching workflows to

IssueOps Example

image (example PR)

Issue-Ops based workflows

(GitHub Actions workflow source)

Installation

To test out the IssueOps commands, either work on a copy of this repo or run the following command in the root directory of your GitHub repo's workspace:

curl https://raw.githubusercontent.com/jonico/pscale-workflow-helper-scripts/main/install.sh | bash
git add .pscale .github/workflows
git commit -m "Add pscale helper scripts and IssueOps workflows"
git push

/ps-create: Create PlanetScale Deploy Request from your PR

You can create a database branch and deploy request in an already existing Pull Request using /ps-create: image

See configuration section for an explanation of the environment variables to set to specify a PlanetScale org and database different from the default settings.

/ps-attach: Attach existing PlanetScale branch or Deploy Request to your PR

If the PlanetScale deploy request or database branch and your pull request both exist already, you can use the /ps-attach command, followed by the PlanetScale URL to your branch/DR:

image

/ps-update: Refresh schema info in your PR from your attached Deploy Request

If you like to refresh the schema information of your branch or add additional DDL statements, use /ps-update:

image

/ps-approve: Approve Deploy Request from your PR

Approvals can be done using /ps-approve:

image

/ps-merge: Merge Deploy Request attached to your PR

Schema changes in attached deploy requests can then be applied to production 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.

image

/ps-delete: Delete PlanetScale branch attached to your PR

Finally, you can delete the database branch associated with a Git branch using /ps-delete:

image

Stay tuned for updates and any feedbacks / PRs are welcome 😊

Zero-setup Action workflows included ✨

In case you like to see those helper scripts in action without any further manual configuration, just

  1. 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.

image

  1. 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.

  2. Switch to the Actions tab in your repo

image

  1. Start the workflows manually, in the displayed order.

image

See configuration section for an explanation of the environment variables to set to specify a PlanetScale org and database different from the default settings.

  1. When you run the workflows, follow the output where it will ask you to authenticate to PlanetScale by clicking the displayed links.

image

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.

image

If you like to install the workflows in your own repository, follow the installation steps.

Configuration

All scripts and IssueOps command in this repo have been designed to run successfully even if zero configuration was provided. If the defaut values do not fit your you, or you do not like to always authorize every action with the Web UI, here are the environment variables you can override in your CI/CD or set as GitHub secrets for your GitHub Action workflows to override default behavior.

DB_NAME

DB_NAME is name of your PlanetScale database. Unless you attach a specific branch or deploy request to your PR, it defaults to example-db-<yourgithubaccount>. If you rather like to change the source for the default DB name, it would be this file.

ORG_NAME

ORG_NAME is name of your PlanetScale organization. Unless you attach a specific branch or deploy request to your PR, it defaults to the first PlanetScale org you joined with your account. If you rather like to change the source for the default DB name, it would be this file.

PLANETSCALE_SERVICE_TOKEN_NAME and PLANETSCALE_SERVICE_TOKEN

If you do not like to authorize actions by clicking on authorization links in the browser, you can create PlanetScale service tokens. Don't forget to set the proper scopes for the database operations you like to automate.

Note: While service tokens can be used to work with existing databases, there is currently no scope to create new databases. This is why the scripts / workflows to create entirely new databses will always prompt you to authenticate via the Web UI.

CI - Runnning in CI

GitHub Actions and many other CI/CD platforms set the CI variable to true when they run a script. The helper scripts in the .pscale/cli-helper-scripts/ directory will only prompt for interactive user input if the CI variable is not set. In CI mode, it will output additional workflow commands to standard out to enable communication between GitHub Action workflow steps. If you are using a different CI/CD platform than GitHub Actions, you can ignore all lines starting with "::".

Initial table

When you create a bew database from scratch, a default table called pixel_matrix will be created. If you like to change this behavior, modify this file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages