Deploying schema migrations to Google Cloud SQL using Atlas and GitHub Actions
In this article
- Overview
- What is Cloud SQL?
- What is Cloud SQL Auth Proxy?
- What is GitHub Actions?
- Deploying Schema Migrations to Cloud SQL
- Prerequisites
- Step-by-Step
- Wrapping Up
Overview
In this guide, we demonstrate how to handle database schema changes when working with Cloud SQL. Within the framework of this topic, we are going to introduce how to set up a GitHub Actions workflow to automatically deploy database schema changes to a Cloud SQL instance. This approach is meant to enhance automation, version control, CI/CD, DevOps practices, and scalability, contributing to more efficient and reliable database management.
Before diving into the practical implementation, let's first look at some of the underlying technologies that we will be working with.
What is Cloud SQL?
Cloud SQL is a fully-managed database service that makes it easy to set up, maintain, manage, and administer your relational databases in the cloud. With Cloud SQL, you can deploy your databases in a highly available and scalable manner, with automatic failover and load balancing, so that your applications can handle a large number of concurrent requests and traffic spikes. You can also choose from different machine types and storage sizes to meet your specific performance and storage requirements.
What is Cloud SQL Auth Proxy?
The Cloud SQL Auth Proxy is a utility for ensuring simple, secure connections to your Cloud SQL instances. It provides a convenient way to control access to your database using Identity and Access Management (IAM) permissions while ensuring a secure connection to your Cloud SQL instance. Like most proxy tools, it serves as the intermediary authority on connection authorizations. Using the Cloud SQL Auth proxy is the recommended method for connecting to a Cloud SQL instance.
What is GitHub Actions?
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production. GitHub Actions goes beyond just DevOps and lets you run workflows when other events happen in your repository. For example, in this guide, you will run a workflow to automatically deploy migrations to a Cloud SQL database whenever someone pushes changes to the main branch in your repository.
Deploying Schema Migrations to Cloud SQL
Prerequisites
Prerequisites to the guide:
- You will need to have the GCP Project Editor role. This role grants you full read and write access to resources within your project.
- Google Cloud SDK installed on your workstation. If you have not installed the SDK, you can find instructions for installing the SDK from the official documentation.
- A running Cloud SQL instance to work against. If you have not created the instance yet, see Creating instances at cloud.google.com.
- A GitHub repository to create and run a GitHub Actions workflow.