ama-prisma
ama-prisma copied to clipboard
Voice Ask me anything app. Built with Next.js, Prisma, TypeScript, Tailwind, React Query, MediaRecorder API, and Cloudinary.
Prisma & Next.js - Ask Me Anything page
Ask Me Anything App!
Built with:
- Prisma
- Next.js
- Tailwind
- MySQL
Based on Brian Lovin's AMA page rebuilt with Prisma.
Development
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
Migrating to PlanetScale from AWS RDS
-
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_URLenv var on Vercel to use the PlanetScale DB -
(optional) Add indices for foreign keys (See comment)
Migrations on PlanetScale
Initial migration
- Create a shadow DB branch:
pscale branch create prisma-playground shadow - Set
SHADOW_DATABASE_URLin.envand configure the Prisma schema - Create migration
npx prisma migrate dev - Promote branch to be the main
pscale branch promote prisma-playground main
Further migrations
- Create a dev branch
pscale branch create prisma-playground add-subtitle-to-posts pscale connect prisma-playground add-subtitle-to-posts --port 3309pscale connect prisma-playground shadow --port 3310DATABASE_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
Database commands
Connect to local mysql
mysql --protocol TCP -h localhost -P 3306 -u root -p prisma-ama
Dump DB
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
Import DB
mysql --protocol TCP -h localhost -P 3306 -u root -p prisma-ama < dump-7-12-2021.sql