This project has been deployed on 100% serverless infrastructure:
https://redwood-planetscale-example.netlify.app
This project uses the
prisma migrate dev
flow, requiring a Shadow DB for local dev. This is not the flow recommended by Planetscale, but it is a more intuitive introduction for devs already using Redwood with Prisma.
Follow this guide:
Be sure to login via pscale auth login
Note We will use MySQL for local testing (optional), in which case we recommend installing mysql, which includes the mysql-client. For example on MacOS, to install mysql run
brew install mysql
Brew creates a
root
user (no password) and defaults to localhost. We'll use those for local dev and config. E.g. access msql shell viamsql -uroot
This project uses Yarn 3, dbAuth, and SQLite. You need to:
- install packages
- apply migrations to the dev DB
- create a local dbAuth secret
- create a local MySQL test DB (optional)
- the test runner does not need a hosted DB; just use MySQL locally
Follow these steps:
yarn install
echo "SESSION_SECRET=$(yarn --silent rw g secret --raw)" >> .env
mysql -uroot
mysql> create database planetscale_test;
Note The Test DB connection string for DB
planetscale_test
is already set in .env.defaulsTEST_DATABASE_URL
For this example, we are using Planetscale for local dev as well as deployment. We are also using Prisma Migrate, which requires a Shadow DB branch. Reference:
Via the Planetscale Dashboard or CLI:
- create a Planetscale DB
- create two new branches from
main
: shadow and development
For the shadow and development branches, we need a connection string from the Dashboard:
- Make sure you choose the "Connect with Prisma" option. And get a new user:password.
- Copy the connection strings into
.env
- For the shadow branch, change the env var from
DATABASE_URL
toSHADOW_DATABASE_URL
Now we can apply the Prisma Schema to the development branch and seed the DB:
yarn redwood prisma migrate dev
Once everything is working, you're ready for local dev 🚀
yarn rw dev
Your browser should open automatically to http://localhost:8910
to see the web app. Lambda functions run on http://localhost:8911
and are also proxied to http://localhost:8910/.redwood/functions/*
.
Deployment with Planetscale is similar to a git pull and merge workflow. First, create a request to merge development into main. This can be done via the Dashboard or CLI:
pscale deploy-request create <database> development
Then approve and deploy via the Dashboard or CLI:
pscale deploy-request deploy <database> <deploy-request-number>
You can deploy to a provider of your choice, either serverles or traditional server. Because Planetscale is a serverless option, we chose Netlify for this example project:
yarn rw setup deploy netlify
We need to update the deploy command in netlify.toml
to not run the Prisma deploy migration (it's already done in the previous Planetscale branch merge and deploy). Modify netlify.toml
:
- command = "yarn rw deploy netlify"
command = "yarn rw deploy netlify --no-prisma"
Push your commits to a git repo, and then set up your site on the Netlify Dashboard. The last setting to manage is adding two Environment Variables:
DATABASE_URL From the Planetscale dashboard, get the Prisma connection string for the main branch.
SESSION_SECRET This project uses Redwood dbAuth for Authentication, which requires a secret. Run the following command:
yarn redwood generate secret
Then copy and paste the output as the value for the env var.
Deploy 🚀
- Tutorial: getting started and complete overview guide.
- Docs: using the Redwood Router, handling assets and files, list of command-line tools, and more.
- Redwood Community: get help, share tips and tricks, and collaborate on everything about RedwoodJS.