Skip to content

2color/ama-prisma

Repository files navigation

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 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. Quick walk-through of the app codebase

  2. PlanetScale import service intro

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

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

  6. Setup the PlanetScale import

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

  8. Switch PlanetScale DB to primary

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

  10. (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

  •  
  •  
  •  
  •