Skip to content

Commit bc75964

Browse files
authored
docs: DB schema migration (#363)
1 parent 5ae438a commit bc75964

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

website/docs/4-developer/README.md

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,42 @@ To initialize or update the database schema, open a shell into the API container
7777
docker exec -it dev-api-1 /bin/bash
7878
```
7979

80+
:::note
81+
You can also use docker desktop or VSCode's docker plugin to attach a shell to the container.
82+
83+
<img src={require("./open-shell-vscode.png").default} alt="attach shell to container" width="300" />
84+
85+
:::
86+
8087
and then **from the shell of the API container** run:
8188

82-
> Known issues: if you get the error below during the migration,
83-
>
84-
> ```bash
85-
> EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
86-
> EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
87-
> ```
88-
>
89-
> then please change the ownership of the folder `node_modules` (**from the shell of the API container**):
90-
>
91-
> ```bash
92-
> chown node:node node_modules/ -R
93-
> ```
94-
>
95-
> Afterwards, re-run
96-
>
97-
> ```bash
98-
> npx prisma migrate dev
99-
> ```
100-
101-
### Preparing for database migration
89+
```bash
90+
npx prisma migrate dev
91+
```
92+
93+
:::note
94+
Known issues: if you get the error below during the migration,
95+
96+
```bash
97+
EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
98+
EACCES: permission denied, unlink '/app/node_modules/.prisma/client/index.js'
99+
```
100+
101+
then please change the ownership of the folder `node_modules` (**from the shell of the API container**):
102+
103+
```bash
104+
chown node:node node_modules/ -R
105+
```
106+
107+
Afterwards, re-run
108+
109+
```bash
110+
npx prisma migrate dev
111+
```
112+
113+
:::
114+
115+
### Database Schema Migration
102116

103117
If you are a developer who wants to change the database schema for adding a feature, you can update the schema file `CODEPOD_ROOT/api/prisma/schema.prisma` and then run
104118

@@ -109,6 +123,15 @@ npx prisma migrate dev --name add_a_new_field
109123
to generate a migration, like [this](https://github.com/codepod-io/codepod/blob/main/api/prisma/migrations/20230223102734_add_updated_at/migration.sql).
110124
The schema change along with this migration need to be checked in (add, commit, and push) to git.
111125

126+
Once the DB schema is changed, other developers need to pull the changes, and
127+
apply the migration by running the following command in the `api` container:
128+
129+
```
130+
npx prisma migrate dev
131+
```
132+
133+
and then restart the `api` container to take effect of the new DB schema.
134+
112135
## Auto-completion & Linting
113136

114137
Although we developed this project using docker, we still want features like auto-completion and linting while coding. For that to work, you need to install the all the relevant node packages, i.e.

0 commit comments

Comments
 (0)