Before you begin
Before starting the tutorial, do the following:- Create a CockroachDB Cloud account.
- Create a Starter Netlify account. You can do this with your GitHub login credentials.
Step 1. Create a CockroachDB Standard cluster
- . If this is your first CockroachDB Cloud organization, it will be credited with $400 in to get you started.
- On the Get Started page, click Create cluster.
- On the Select a plan page, select Standard.
- On the Cloud & Regions page, select a cloud provider (GCP or AWS).
- In the Regions section, select a region for the cluster. Refer to for the regions where CockroachDB Standard clusters can be deployed. To create a multi-region cluster, click Add region and select additional regions.
- Click Next: Capacity.
- On the Capacity page, keep the at the default value of 2 vCPUs. Click Next: Finalize.
- On the Finalize page, name your cluster. If an active free trial is listed in the right pane, you will not need to add a payment method, though you will need to do this by the to maintain your organization’s clusters. Click Create cluster. Your cluster will be created in a few seconds and the Create SQL user dialog will display.
The connection string is pre-populated with your username, cluster name, and other details, including your password. Your password, in particular, will be provided only once. Save it in a secure place (we recommend a password manager) to connect to your cluster in the future. If you forget your password, you can reset it by going to the SQL Users page for the cluster, found at
https://cockroachlabs.cloud/cluster/<CLUSTER ID>/users.Step 2. Get the code
-
Clone the code’s GitHub repo:
The project has the following directory structure:In this tutorial, we focus on the files in the
netlifyandprismadirectories. -
At the top of the repo directory, fork the repo:
To deploy your code to Netlify, you need to have your own repo or your own fork of the existing repo.
Step 3. Initialize the database
-
In the
.envfile in your project, set theDATABASE_URLenvironment variable to the connection string you obtained earlier from the CockroachDB Cloud Console:Prisma loads the variables defined in.envto the project environment. -
Install Prisma:
-
Run Prisma Migrate to initialize the database with the schema defined in
prisma/prisma.schema.You should see the following output:This command initializes Prisma Client to communicate with your CockroachDB cluster, based on the configuration in theprisma/schema.prismafile. The command also seeds your database with some sample data, using the script defined inprisma/seed.ts.
Step 4. Deploy the application
You can deploy web applications directly from GitHub to Netlify. In this tutorial, we use the Netlify CLI to deploy the app.-
Install the
netlifyCLI: -
Sign into your Netlify account:
-
Run the app server locally to preview your site:
If the local deployment succeeds, you should see the following message in your terminal:For a preview of the site, visit http://localhost:8888. Interacting with the site triggers the Netlify functions defined in the
netlify/functionsdirectory. These functions use Prisma Client to run and queries against the database:getScores.tsreads all rows from theplayer_scorestable and returns values in theid,name, andscorecolumns.getPlayers.tsreads and returns all rows from theplayerstable.addScore.tswrites new scores to theplayer_scorestable.
-
Deploy your app with the Netlify CLI:
Choose to create a new site, and then select the default options for each of the subsequent prompts. You will be required to authorize Netlify with GitHub. After the app is deployed, you should see the following message:
-
Navigate to the admin URL for your site:
From the Site overview page, you can manage your site. The Site overview page also provides you with a public URL for your site.

