Skip to content

Commit 6de29b3

Browse files
authored
Merge pull request #4 from secure-dashboards/feat/add-schemas
2 parents 0e25ab2 + 9a87a3c commit 6de29b3

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Check Migrations
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths:
7+
- 'src/database/migrations/**'
8+
9+
jobs:
10+
check-migrations:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Check and add comment to PR
18+
uses: actions/github-script@v4
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
script: |
22+
const { data: comments } = await github.rest.issues.listComments({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
issue_number: context.issue.number,
26+
});
27+
28+
const commentExists = comments.some(comment =>
29+
comment.body.includes("It looks like you've made changes to the migrations.")
30+
);
31+
32+
if (!commentExists) {
33+
await github.rest.issues.createComment({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
issue_number: context.issue.number,
37+
body: "It looks like you've made changes to the migrations. Have you run `npm run db:generate-schema` to ensure the updated schemas are included in your PR?"
38+
});
39+
}

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ To seed the database with initial data, use the following command:
5454
npm run db:seed
5555
```
5656

57+
### Examine the database schema
58+
59+
You can find an updated version of the schemas in [/src/database/schema/schema.sql](src/database/schema/schema.sql) so you don't have to start the infra and run the migrations if you just want to know about the database structure.
60+
61+
### Update the database schema
62+
63+
To update the schema, use the following command:
64+
65+
```bash
66+
npm run db:generate-schema
67+
```
68+
5769
## Linting
5870

5971
To lint the files, use the following command:

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,24 @@ services:
1919
ports:
2020
- 8080:8080
2121

22+
schema-dump:
23+
image: postgres:17.2
24+
depends_on:
25+
- db
26+
environment:
27+
POSTGRES_DB: dashboard
28+
POSTGRES_USER: openjs
29+
POSTGRES_PASSWORD: password
30+
PGPASSWORD: password # bypass the password prompt
31+
volumes:
32+
- openjs_dashboard_data:/var/lib/postgresql/data
33+
- ./src/database/schema:/schema
34+
entrypoint: >
35+
bash -c "
36+
pg_dump --host=db --username=openjs --schema-only --no-owner --dbname=dashboard > /schema/schema.sql &&
37+
chmod 644 /schema/schema.sql
38+
"
39+
40+
2241
volumes:
2342
openjs_dashboard_data:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"infra:stop": "docker-compose down",
1313
"db:migrate": "knex migrate:latest",
1414
"db:rollback": "knex migrate:rollback",
15+
"db:generate-schema": "docker-compose run schema-dump",
1516
"db:seed": "knex seed:run"
1617
},
1718
"keywords": [],

0 commit comments

Comments
 (0)