Next.js starter application using Prisma to connect to PlanetScale

Overview

Next.js starter

This is a Next.js project that uses Prisma to connect to a PlanetScale database and Tailwind CSS for styling.

Prerequisites

pscale auth login

Set up the database

Create a new database with the following command:

pscale database create <DATABASE_NAME>

A branch, main, was automatically created when you created your database, so you can use that for BRANCH_NAME in the steps below.

Set up the starter Next.js app

Clone the starter repository.

git clone https://github.com/planetscale/nextjs-starter

Install the dependencies.

npm install

Next, you'll need to create a database username and password through the CLI to connect to your application. If you'd prefer to use the dashboard for this step, you can find those instructions in the Connection Strings documentation and then come back here to finish setup.

First, create your .env file by renaming the .env.example file to .env:

mv .env.example .env

Next, using the PlanetScale CLI, create a new username and password for the branch of your database:

pscale password create <DATABASE_NAME> <BRANCH_NAME> <PASSWORD_NAME>

The PASSWORD_NAME value represents the name of the username and password being generated. You can have multiple credentials for a branch, so this gives you a way to categorize them. To manage your passwords in the dashboard, go to your database overview page, click "Settings", and then click "Passwords".

Take note of the values returned to you, as you won't be able to see this password again.

Password production-password was successfully created.
Please save the values below as they will not be shown again

  NAME                  USERNAME       ACCESS HOST URL                     ROLE               PLAIN TEXT
 --------------------- -------------- ----------------------------------- ------------------ -------------------------------------------------------
  production-password   xxxxxxxxxxxxx   xxxxxx.us-east-2.psdb.cloud   Can Read & Write   pscale_pw_xxxxxxx

You'll use these properties to construct your connection string, which will be the value for DATABASE_URL in your .env file. Update the DATABASE_URL property with your connection string in the following format:

mysql://<USERNAME>:<PLAIN_TEXT_PASSWORD>@<ACCESS_HOST_URL>/<DATABASE_NAME>?sslaccept=strict

Push the database schema to your PlanetScale database using Prisma.

npx prisma db push

Run the seed script to populate your database with Product and Category data.

npm run seed

Run the App

Run the app with following command:

npm run dev

Open your browser at localhost:3000 to see the running application.

Deploying

After you've got your application running locally, it's time to deploy it. To do so, you'll need to promote your database branch (main by default) to be the production branch (read the branching documentation for more information).

pscale branch promote <DATABASE_NAME> <BRANCH_NAME>

Now that your branch has been promoted to production, you can either use the existing password you generated earlier for running locally or create a new password. Regardless, you'll need a password in the deployment steps below.

Choose one of the following deploy buttons and make sure to update the DATABASE_URL variable during this setup process.

Deploy on Vercel

Deploy with Vercel

Deploy on Netlify

*Note: The Netlify.toml file in this repository includes the configuration for you to customize the DATABASE_URL property on the initial deploy.

Deploy to Netlify

Learn More

To learn more about PlanetScale, take a look at the following resources:

What's next?

Learn more about how PlanetScale allows you to make non-blocking schema changes to your database tables without locking or causing downtime for production databases. If you're interested in learning how to secure your application when connecting to PlanetScale, please read Connecting to PlanetScale securely.

Need help?

Get help from PlanetScale's support team, or join our GitHub Discussion board to see how others are using PlanetScale.

You might also like...

This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io)

This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io)

Alternative Prisma Data Proxy This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io). In order to deploy your project to

Dec 28, 2022

A fullstack next.js template with all the fun stuff like next auth, mongodb, prisma, chakra ui

A fullstack next.js template with all the fun stuff like next auth, mongodb, prisma, chakra ui

Welcome to FullStack Next.js template 👋 A fullstack next.js template with all the fun stuff like next auth, mongodb, prisma, chakra ui ✨ Demo Tech Ne

Oct 16, 2022

Fullstack Turborepo starter. Typescript, Nestjs, Nextjs, Tailwind, Prisma, Github Actions, Docker, And Reverse proxy configured

Turborepo (NestJS + Prisma + NextJS + Tailwind + Typescript + Jest) Starter This is fullstack turborepo starter. It comes with the following features.

Jan 9, 2023

A simple CLI to generate a starter schema for keystone-6 from a pre-existing prisma schema.

Prisma2Keystone A tool for converting prisma schema to keystone schema typescript This is a proof of concept. More work is needed Usage npx prisma2key

Dec 17, 2022

A prisma-typegraphQL-typescript starter template with minimal setup

TypeGraphql-Prisma-Typescript Starter template. TECH INSIDE TypeGraphQL Apollo-express-server v3 Prisma v4 Typescript v4.7 TypegraphQL-prisma extensio

Sep 5, 2022

A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site

A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site

FRAGMENTED Summary A web application that allows the user to connect through Unstoppable Domains and claim a small block of the site. Each user will b

Jan 24, 2022

Python based web application to import, connect and analyze manufacturing data from multiple data sources.

Python based web application to import, connect and analyze manufacturing data from multiple data sources.

Analysis Platform Analysis Platform is an open source web application to import, connect and visualize factory IoT data. It helps to collect, link and

Dec 1, 2022

A full-stack application that allows gamers to connect and match to people with similar interests.

A full-stack application that allows gamers to connect and match to people with similar interests.

Platform that allows gamers to connect and find people with similar interests. Built during the @Rocketseat NLW eSports event. Preview: Quickstart Ser

Oct 2, 2022

NX monorepo showing the TMDB Watchlist mobile app with Expo, tRPC, Next, and Prisma

NX monorepo showing the TMDB Watchlist mobile app with Expo, tRPC, Next, and Prisma

tmdb-watchlist-prisma This app uses TMDB to retrieve a list of Now Playing movies. You can add/remove movies to track which ones you've watched. There

Dec 28, 2022
Comments
  • Cleaned up example.

    Cleaned up example.

    • Fixed issue in README for using npm instead of npx
    • Fixing issue styling issue for product images
    • Fixed broken link in README
    • Removed unused images from /public folder
    • Updated seed data to use the images in the public folder
    • Minor formatting cleanup from prettier
    opened by leerob 1
  • Update env var name

    Update env var name

    Changing the database env var from DATABASE_URL to PLANETSCALE_PRISMA_DATABASE_URL will ensure that if the Vercel integration is being used that the application will be able to use the automatically set env var in Vercel

    Related: https://twitter.com/planetscaledata/status/1527699637913657345

    opened by tbarn 0
Owner
PlanetScale
The database for developers.
PlanetScale
This is a project manager X note taker built with Next js, Planetscale and Firebase.

Blaze is a project developed with NextJs, PlanetScale and Firebase. It's a task manager that doubles as a note taker To contribute to this project, Ki

ABDULLAH ABDULFATAH 35 Aug 8, 2022
Remix Stack for deploying to Vercel with remix-auth, Planetscale, Radix UI, TailwindCSS, formatting, linting etc. Written in Typescript.

Remix Synthwave Stack Learn more about Remix Stacks. npx create-remix --template ilangorajagopal/synthwave-stack What's in the stack Vercel deploymen

Ilango 56 Dec 25, 2022
A Fetch API-compatible PlanetScale database driver

PlanetScale Serverless Driver for JavaScript A Fetch API-compatible PlanetScale database driver for serverless and edge compute platforms that require

PlanetScale 255 Dec 27, 2022
Connect Web Integration illustrates the integration of Connect-Web in various JS frameworks and tooling

Connect Web Integration Connect Web Integration is a repository of example projects using Connect-Web with various JS frameworks and tooling. It provi

Buf 43 Dec 29, 2022
A web app to post emoji implemented in connect-go and connect-web.

emotter Emotter is an app to post and share single emoji. This is an example app of connect. Example https://emotter.syumai.com API: Cloud Run Web cli

syumai 11 Oct 30, 2022
Next.js + Tailwind + Typescript + Prisma + NextAuth starter project

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Steven Tey 106 Jan 3, 2023
Prisma +2 generator to emit Yup schemas from your Prisma schema

Prisma Yup Generator Automatically generate Yup schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 31 Dec 24, 2022
Prisma 2+ generator to emit Joi schemas from your Prisma schema

Prisma Joi Generator Automatically generate Joi schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 26 Dec 24, 2022
Prisma +2 generator to emit a tRPC shield from your Prisma schema

Prisma tRPC Shield Generator Automatically generate a tRPC Shield from your Prisma Schema. Updates every time npx prisma generate runs. Table of Conte

Omar Dulaimi 27 Dec 24, 2022
Prisma 2+ generator to emit Zod schemas from your Prisma schema

Prisma Zod Generator Automatically generate Zod schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 212 Dec 27, 2022