Skip to content

Voice Ask me anything app. Built with Next.js, Prisma, TypeScript, Tailwind, React Query, MediaRecorder API, and Cloudinary.

License

Notifications You must be signed in to change notification settings

2color/ama-prisma

Repository files navigation

Prisma & Next.js - Ask Me Anything page

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.

Development

Clone the repository:

git clone git@github.com: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

  1. PlanetScale import service intro

  2. 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"]
    }
  3. Create a migration (removing the foreign keys) with local DB: npx prisma migrate dev

  4. Run the migration against the RDS MySQL Production DB removing foreign keys in preparation for the migration

  5. Setup the PlanetScale import

  6. Add the imported PlanetScale DB to the Prisma Data Platform and verify using the Data Browser that the data has been successfully replicated.

  7. Switch PlanetScale DB to primary

  8. Update the production DATABASE_URL env var on Vercel to use the PlanetScale DB

  9. (optional) Add indices for foreign keys (See comment)

Migrations on PlanetScale

Initial migration

  1. Create a shadow DB branch: pscale branch create prisma-playground shadow
  2. Set SHADOW_DATABASE_URL in .env and configure the Prisma schema
  3. Create migration npx prisma migrate dev
  4. Promote branch to be the main pscale branch promote prisma-playground main

Further migrations

  1. Create a dev branch pscale branch create prisma-playground add-subtitle-to-posts
  2. pscale connect prisma-playground add-subtitle-to-posts --port 3309
  3. pscale connect prisma-playground shadow --port 3310
    DATABASE_URL="mysql://root@127.0.0.1:3309/prisma-playground"
    SHADOW_DATABASE_URL="mysql://root@127.0.0.1:3310/prisma-playground"
    
  4. Add changes to Prisma schema
  5. Create migration: npx prisma migrate dev
  6. 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

About

Voice Ask me anything app. Built with Next.js, Prisma, TypeScript, Tailwind, React Query, MediaRecorder API, and Cloudinary.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •