This NextJS app uses:
- PlanetScale for the MySQL database, and
- Prisma for the database ORM
The database schema is stored within the prisma.schema
file.
After the desired database schema changes have been made locally and verified working on a local database,
Note: Ensure you are connected to the correct PlanetScale organization (via
pscale org show
andpscale org switch <org-name>
).
- Create a new branch on the PlanetScale database:
pscale branch create solfate-main <feature-branch-name>
- Locally connect to the newly created database branch
pscale connect solfate-main <feature-branch-name> --port 3309
- Ensure your ENV file has the
DATABASE_URL
set to connect to PlanetScale via the local tunnel:
DATABASE_URL="mysql://[email protected]:3309/solfate-main"
- Push the schema changes to the remote database:
yarn prisma db push
- Open a "deploy request" on the PlanetScale database to handle any breaking schema changes:
pscale deploy-request create solfate-main <feature-branch-name>
- When the database changes are satisfied and breaking changes are ready, complete the database deploy request, making the changes live on the production database:
pscale deploy-request deploy solfate-main <number|feature-branch-name>
Done!
Much like any code base, there are some caveats and "foot-guns" scattered throughout this repo:
This repo is configured to deploy to Vercel. As such, there maybe be hard coded values or Vercel specific environment variables used.
During "preview" deployments, Vercel will auto generate unique subdomains for the web app. As such, some functionality may not work correctly due misaligned domains.
NextAuth normally requires the NEXTAUTH_URL
env variable set. On Vercel, this
is not required to be set since NextAuth will auto-magically use the deployment
URL created by Vercel and set in the VERCEL_*
env variables.
We use secure cookies with NextAuth, which requires the correct domain. If the
domain value is set incorrectly, then no one will be able to sign in. We are
setting this to the primary site domain on production deployments, and the
generated VERCEL_BRANCH_URL
for preview deployments. All preview deployments
are expected to be viewed from the Vercel branch URL in order for auth based
functionality to work.
This web app supports connecting a few a external social accounts via OAuth providers (like Twitter and GitHub). Most OAuth applications require a hardcoded callback and/or webhook URL for the deployed website, none of which support wildcard domains.
Each OAuth provider has a hardcoded callback URL that may not matched the auto generated preview/branch deployment URLs created by Vercel. As such, many OAuth provider connections will not work on the preview deployments. They can be manually configured to work with the OAuth providers dashboards.