-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add schemalint github actioni for best practice reference
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Linting rules on database schema. | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'initdb/**' | ||
branches: | ||
- 'main' | ||
push: | ||
branches: | ||
- 'main' | ||
paths: | ||
- 'initdb/**' | ||
tags: | ||
- "*" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
schemalint: | ||
name: schemalint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the source | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set env | ||
run: cp .env.example .env | ||
|
||
- name: Pull Docker images | ||
run: docker-compose pull db api | ||
|
||
- name: Run PostgSail Database & schemalint | ||
# Environment variables | ||
env: | ||
# The hostname used to communicate with the PostgreSQL service container | ||
PGHOST: localhost | ||
PGPORT: 5432 | ||
PGDATABASE: signalk | ||
PGUSER: username | ||
PGPASSWORD: password | ||
run: | | ||
set -eu | ||
source .env | ||
docker-compose stop || true | ||
docker-compose rm || true | ||
docker-compose up -d db && sleep 30 && docker-compose up -d api && sleep 5 | ||
docker-compose ps -a | ||
echo ${PGSAIL_API_URL} | ||
curl ${PGSAIL_API_URL} | ||
npm i -D schemalint | ||
npx schemalint | ||
- name: Show the logs | ||
if: always() | ||
run: | | ||
docker-compose logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
connection: { | ||
host: process.env.PGHOST, | ||
user: process.env.PGUSER, | ||
password: process.env.PGPASSWORD, | ||
database: process.env.PGDATABASE, | ||
charset: "utf8", | ||
}, | ||
|
||
rules: { | ||
"name-casing": ["error", "snake"], | ||
"prefer-jsonb-to-json": ["error"], | ||
"prefer-text-to-varchar": ["error"], | ||
"prefer-timestamptz-to-timestamp": ["error"], | ||
"prefer-identity-to-serial": ["error"], | ||
"name-inflection": ["error", "singular"], | ||
}, | ||
|
||
schemas: [{ name: "public" }, { name: "api" }], | ||
|
||
ignores: [], | ||
}; |