Before you begin
Before starting the tutorial, do the following:
- Create a CockroachDB Cloud account.
- Create a Vercel account.
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.
After the cluster is created, the Connection info window appears. Click the Connection string tab and copy the connection string to a secure location. You will use this connection string to connect to CockroachDB later in the tutorial.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
cockroachdb fork of the prisma-examples repo:
-
Navigate to the
rest-nextjs-api-routes directory:
-
Install the application dependencies:
-
Install the
vercel and prisma CLI tools:
Step 3. Initialize the database
-
Save the connection string you obtained earlier from the CockroachDB Cloud Console to the
DATABASE_URL environment variable in an .env file in your project:
Prisma loads the variables defined in .env to the project environment. By default, Prisma uses the DATABASE_URL environment variable as the connection string to the database.
-
Run Prisma Migrate to initialize the database with the schema defined in
prisma/prisma.schema.
You should see the following output:
This command also initializes Prisma Client to communicate with your CockroachDB cluster, based on the configuration in the prisma/schema.prisma file.
Step 4. Deploy the application
-
(Optional) Run the app server locally to preview your site:
You should see the following output:
-
Run the
vercel command to start deploying the app:
You will be asked to sign into your Vercel account. When you authenticate your credentials, you should see the following message:
The --confirm flag instructs Vercel to deploy the app to the example-app-typescript-vercel Vercel project, using the default settings:
Follow the links provided to view and manage your deployed application.