Skip to content

Commit 5773ef6

Browse files
committed
docs: added documentation on how to use migrations
1 parent 60ba0d6 commit 5773ef6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ The official Competitive Coding website for BITS Pilani, Hyderabad Campus. Surge
6464
docker compose --profile prod down
6565
```
6666

67+
## Migrations
68+
**Make sure you have the dev profile up and running before running migrations.**
69+
70+
71+
The two containers required to run and generate migrations are:
72+
- `backend-dev`
73+
- `postgres`
74+
75+
After the above mentioned containers are running you can use the following commands
76+
77+
### Apply existing migrations
78+
```bash
79+
docker compose exec backend-dev npx drizzle-kit migrate
80+
```
81+
82+
Runs migrations which haven't been applied yet. A list of migrations which have been applied is stored in a table in the database itself. Read more about this [here](https://github.com/jbranchaud/til/blob/master/drizzle/drizzle-tracks-migrations-in-a-log-table.md).
83+
84+
### Apply current schema to the database
85+
```bash
86+
docker compose exec backend-dev npx drizzle-kit push
87+
```
88+
This command **does not** generate migrations! Make sure to generate migrations for any major changes to ensure that the history of the database schema is always preserved.
89+
90+
91+
### Generate migrations from schema
92+
```bash
93+
docker compose exec backend-dev npx drizzle-kit generate
94+
```
95+
This compares the current state of the database with the schema and generates migrations.
96+
97+
6798
## Contribution
6899

69100
Follow the [Contributing Guide](./CONTRIBUTING.md).

0 commit comments

Comments
 (0)