Added drizzle orm documentation

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-10 17:57:34 +01:00
parent 39695232c6
commit 43617f3944

View file

@ -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.