Caution
This project hasn't been updated since PlanetScale removed their free plan. Therefore, I no longer host a working version. If time allows in the future, I'll switch this over to use SQlite on Cloudflare D1
Ask Me Anything App!
Built with:
- Prisma
- Next.js
- Tailwind
- MySQL
Based on Brian Lovin's old AMA page rebuilt with Prisma, MySQL, and Cloudinary.
Clone the repository:
git clone [email protected]:2color/prisma-ama.git
cd
into the directory:
cd prisma-ama
Install dependencies:
npm i
Start the client:
npm run dev
Open the site:
localhost:3000
-
Adjust the Prisma schema (with RDS MySQL) and set referential integrity to prisma
datasource db { provider = "mysql" url = env("DATABASE_URL") referentialIntegrity = "prisma" } generator client { provider = "prisma-client-js" previewFeatures = ["dataProxy", "referentialIntegrity"] }
-
Create a migration (removing the foreign keys) with local DB:
npx prisma migrate dev
-
Run the migration against the RDS MySQL Production DB removing foreign keys in preparation for the migration
-
Setup the PlanetScale import
-
Add the imported PlanetScale DB to the Prisma Data Platform and verify using the Data Browser that the data has been successfully replicated.
-
Switch PlanetScale DB to primary
-
Update the production
DATABASE_URL
env var on Vercel to use the PlanetScale DB -
(optional) Add indices for foreign keys (See comment)
- Create a shadow DB branch:
pscale branch create prisma-playground shadow
- Set
SHADOW_DATABASE_URL
in.env
and configure the Prisma schema - Create migration
npx prisma migrate dev
- Promote branch to be the main
pscale branch promote prisma-playground main
- Create a dev branch
pscale branch create prisma-playground add-subtitle-to-posts
pscale connect prisma-playground add-subtitle-to-posts --port 3309
pscale connect prisma-playground shadow --port 3310
DATABASE_URL="mysql://[email protected]:3309/prisma-playground" SHADOW_DATABASE_URL="mysql://[email protected]:3310/prisma-playground"
- Add changes to Prisma schema
- Create migration:
npx prisma migrate dev
pscale deploy-request create prisma-playground add-subtitle-to-posts
mysql --protocol TCP -h localhost -P 3306 -u root -p prisma-ama
mysqldump --host eu-central-1.rds.amazonaws.com --user admin -p DB_NAME --no-create-db --set-gtid-purged=OFF > dump-7-12-2021.sql
mysql --protocol TCP -h localhost -P 3306 -u root -p prisma-ama < dump-7-12-2021.sql