An app for managing books you have read or would like to read.
- Vercel for app deployment and Vercel analytics.
- PlanetScale for database deployment.
- Backblaze B2 Cloud Storage for file storage for images.
- Sentry for monitoring.
- Create a local connection to the PlanetScale database development branch:
pscale connect [database] [branch]
. This should return you a local address, e.g.127.0.0.1:3306
. - Setup the environment variables.
- Install the Vercel CLI
- Run
vercel link
in the root of the project to link it to our Vercel project. - Run
vercel env pull
to download the development environment variables.
- Run
pnpm run prisma-generate
to generate the Prisma client files from the Prisma schema. - Start the development environment:
pnpm dev
. - Go to http://localhost:3000 to see the app.
We use Prisma for our database schema and client management, and PlanetScale for database hosting.
The source of truth for our database schema is the Prisma schema under prisma/schema.prisma
.
Command | Description |
---|---|
pscale connect [database] [branch] |
Create a local connection to a PlanetScale database. Used for local dev. |
pnpx prisma generate |
Generate Prisma client from the Prisma schemas. |
pnpx prisma db pull |
Update the Prisma schema to be in sync with the currently configured remote database. Can be useful if you want to change the database rather than the Prisma schema |
pnpx prisma db push |
Update the currently configured remote database with the latest Prisma schema. |
pnpx prisma studio |
Load Prisma Studio for viewing and changing database data. |
- Connect to the development branch with
pscale connect
. - Make schema changes to the PlanetScale branch
- Make any changes required to the Prisma schema file (under
prisma/schema.prisma
). - Push changes to your development database branch with
pnpx prisma db push
while development is ongoing. - Make sure you notify others you are changing the database to ensure no conflicts.
- Make any changes required to the Prisma schema file (under
- Open pull/deploy requests when your changes are ready for review
- Open a pull request in GitHub for any code and schema changes.
- Merge changes after approval
- Merge the PlanetScale deploy request first to ensure the database is updated.
- Merge the GitHub pull request.
In general try and follow these best practices for schema updates.
In the future automating some of this via CI would be good
To allow the Prisma client to be built for the Vercel deployments we customised the Vercel build command in
package.json
as follows:
"vercel-build": "prisma generate && next build"
Note that Vercel has been configured so preview branches will use the PlanetScale development database branch. This can be found under Vercel / Settings / Environment Variables. This means in the current state you need to be careful not to break the development branch for others.
- Create a GitHub pull request to
main
. - Create a PlanetScale deploy request from development to production.
- Merge the PlanetScale deploy request first to update the database.
- Then merge the GitHub pull request to update the app.
We save our book cover images to Backblaze B2 Cloud Storage.
Currently when cover images are updated the old images are not deleted from Backblaze. This was not done at request time to keep the request as quick as possible.
Instead a housekeeping script was created which deletes image files from Backblaze that are no longer referenced in the database. The housekeeping script is under ./server/backblaze-housekeeping.ts.
Ideally the housekeeping script should be set to run on a schedule.
We use Playwright for our end to end tests. The following commands are useful:
pnpm run test:e2e
: Run the E2E tests in the terminal.pnpm run test:e2e:ui
: Run the E2E tests with the Playwright UI. Useful for dev.pnpm run test:e2e:generate
: Run the Playwright test generator. Useful for creating tests.