Skip to content

Commit

Permalink
chore: improve docs for updating schemas and db error logging
Browse files Browse the repository at this point in the history
* docs: document how to update database schema

* chore: improve error logging

* Apply suggestions from code review

Co-authored-by: Vasco Santos <santos.vasco10@gmail.com>

Co-authored-by: Vasco Santos <santos.vasco10@gmail.com>
  • Loading branch information
flea89 and vasco-santos authored Nov 12, 2021
1 parent 0b7e508 commit 51021f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/db/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ Once you are done, the local setup can easily be stopped and cleaned using:
node scripts/cli.js db --stop --clean --project web3-storage
```

### 4. Alter DB schema

In order for your changes to the DB schema to be reflected in Postgres you need to run an `openapi-typescript` script:

```bash
node scripts/cli.js db-sql
```

`pg-rest-api-types.ts` stores the types of the various DB tables and their columns.
In order to get them updated after a change to your db structure you can run:

```bash
node scripts/cli.js pg-rest-api-types
```

Do not forget to update `db-client-types.ts` to reflect your changes to the schema.

If you're creating a new table, type or view please remember to update `reset.sql` as well.

## Database Diagram

![image](https://user-images.githubusercontent.com/7295071/137729026-50aebb55-e89c-45ed-b636-b3e39cc53cc0.png)
Expand Down
2 changes: 1 addition & 1 deletion packages/db/scripts/cmds/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function dbCmd ({ project, init, start, stop, clean }) {

if (start) {
if ((await isPortReachable(5432)) || (await isPortReachable(3000))) {
throw new Error('Another docker project already running')
throw new Error('Postgres is already running. Please check if you have any docker project or postgres deamon already running.')
}

await execa('docker-compose', [
Expand Down

0 comments on commit 51021f1

Please sign in to comment.