Documentation

Migrating database schemas

This document explains how to migrate your database schema using the schema editor in the PlanetScale Console.

You can also migrate your database schema by connecting to your database with a MySQL client and issuing data definition language (DDL) statements. However, PlanetScale recommends using the schema editor because of these benefits:

  • The schema editor ensures that the entire set of schema changes can apply successfully before applying any changes to your database. The schema editor either applies the whole set of submitted changes, or applies no changes at all.
  • The schema editor ensures that the schema change does not lock large tables for long periods. If you need to perform a long-running schema migration on large tables, please contact support@planetscale.com.
  • The schema editor makes your new schema immediately visible to all clients. Otherwise, it can take a few minutes before this occurs.

See Understanding sharding schemes for information on configuring your database for horizontal scaling.

Prerequisites

Before you edit your database schema, you must first create a database.

Overview

To create a PlanetScale Database, follow these steps:

  1. Go to the PlanetScale console.
  2. Click on your cluster name.
  3. Click on your database name.
  4. Under Schema, click Edit.
  5. Under Schema Migration DDL, enter SQL data definition language statements.
  6. Click Apply Schema Migration

Step 1. Go to the PlanetScale console.

This opens the Clusters Overview.

Step 2. Click on your cluster name.

Step 3. Click on your database name.

This opens the Overview for your database.

Step 4. Under Schema, click Edit.

Step 5. Under Schema Migration DDL, enter SQL data definition language statements.

The Schema Migration DDL dialog supports a limited set of data definition language statements.

Example:

CREATE TABLE `user` (
  `user_id` bigint(20) NOT NULL,
  `name` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

Step 6. Click Apply Schema Migration.

Your database schema is now updated.

Step 7. (Optional) Under Schema, click Edit.

Under Current Schema, you can see your updated database schema.