From 43617f39448496047a0c2b04431ff13244a0bb2a Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 10 Jul 2023 17:57:34 +0100 Subject: [PATCH] Added drizzle orm documentation --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index f4da3c4..ead1687 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,39 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. + +# Drizzle ORM + +We're using Drizzle ORM to interface with our AWS Postgres database. Documentation on getting set up can be found [here](https://orm.drizzle.team/docs/installation-and-db-connection/postgresql/node-postgres) + +## Schemas + +In order to get started with Drizzle, a schema needs to be created. Schemas can be added src/app/db/schema as typescript files. See the documentation on how to set +up schemas but effectively, Drizzle allows you to define schemas as typescript code, which allows for simple, type safe schema definitions. + +## Creating Migrations + +To create a migration, a command has been set up in package.json. Simply run + +```bash +npm run migration:generate +``` + +Or with yarn/pnmp accordingly. + +Note, there seems to be a bug with Drizzle which is documented [here](https://github.com/drizzle-team/drizzle-orm/issues/803). + +The workaround is to open up `tsconfig.json` and comment out `"target": "es5"`, and replace it with `"target": "ESNext"`. This should hopefully only +be a temporary workaround required. + +## Pushing migrations + +To push migrations, another command has been set up in package.json, since drizzle-kit currently does not support pushing for Postgres out of the box. + +Run + +```base +npm run migration:push +``` + +Which will commit changes to the database. The database changes will be pushed to the **public** schema, whereas a meta record will be pushed to the **\_\_drizzle_migrations** schema.