Build and Deploy a GraphQL API to the Edge with MySQL and PlanetScale — Part 2

Build and Deploy a GraphQL API to the Edge with MySQL and PlanetScale — Part 2

Set up MySQL Database with PlanetScale

PlanetScale is the best place to serve and scale your MySQL Database. You'll need to create an account, create a database, add a products table, and obtain the connection details to continue.

  1. Sign up for a PlanetScale account

  2. Create a new database

  3. Create a new branch and open the web console to execute the following SQL statement:

CREATE TABLE `products` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `slug` VARCHAR(255) NOT NULL UNIQUE,
  `price` INT NOT NULL DEFAULT 0,
  `onSale` BOOLEAN DEFAULT FALSE,
  PRIMARY KEY (`id`),
  INDEX slug_index (`slug`),
);
  1. Enable safe migrations for the main branch

    Enable safe migrations with PlanetScale main branch

  2. Open a deploy request and merge the changes into main.

    Merge products branch with main using deploy requests

That's it! You now have a database we can use to store product data.

👉 Continue to Part 3