Skip to content

Commit

Permalink
fix: check db integrity after building it.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Sep 16, 2024
1 parent 54b6577 commit b063595
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ jobs:
- name: Build app
run: npm run build --if-present

- name: Build Elm static Db
run: npm run db:build

- name: Run prettier, openapi & ruff formatting check
run: npm run lint:all

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.env
/dist
elm-stuff
/check-db-app.js
/compute-aggregated-app.js
/node_modules
/public/app.js
Expand Down
12 changes: 12 additions & 0 deletions check-db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { Elm } = require("./check-db-app");

const elmApp = Elm.CheckDb.init({});

elmApp.ports.logAndExit.subscribe(({ message, status }) => {
if (status > 0) {
console.error(`🚨 ERROR: ${message}`);
} else {
console.info(message);
}
process.exit(status);
});
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"build": "npm run server:build && rimraf dist && npm run build:init && parcel build index.html --public-url ./",
"build:init": "./bin/update-version.sh && mkdir -p dist && cp -r public/* dist/ && npm run db:build",
"build:standalone-app": "npm run build && npm run server:build && cp server-app.js dist/ && cp openapi.yaml dist/",
"processes:build": "elm make src/ComputeAggregated.elm --output=compute-aggregated-app.js && node compute-aggregated.js",
"decrypt": "./bin/decrypt",
"encrypt": "./bin/encrypt",
"db:build": "./bin/build-db",
"db:build": "./bin/build-db && npm run db:check",
"db:check": "elm make src/CheckDb.elm --optimize --output=check-db-app.js 1> /dev/null && node check-db.js",
"lint:openapi": "npx swagger-cli validate openapi.yaml",
"lint:prettier": "prettier --config .prettierrc --check",
"lint:prettier:all": "npm run lint:prettier -- .",
Expand All @@ -34,6 +34,7 @@
"fix:ruff:format": "pipenv run ruff format --force-exclude",
"fix:all": "npm run fix:ruff:all && npm run fix:prettier:all",
"format:json": "npx [email protected] --write . && pipenv run ruff check --select I --fix && pipenv run ruff format",
"processes:build": "elm make src/ComputeAggregated.elm --output=compute-aggregated-app.js && node compute-aggregated.js",
"server:build": "npm run db:build && elm make src/Server.elm --optimize --output=server-app.js",
"server:dev": "npm run server:build && nodemon server.js --config nodemon.json",
"server:debug": "elm make src/Server.elm --output=server-app.js && nodemon server.js --config nodemon.json",
Expand Down
25 changes: 25 additions & 0 deletions src/CheckDb.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
port module CheckDb exposing (main)

import Static.Db as StaticDb
import Static.Json as StaticJson


main : Program () () ()
main =
Platform.worker
{ init =
always <|
( ()
, case StaticDb.db StaticJson.rawJsonProcesses of
Err error ->
logAndExit { message = "Db is dubious: " ++ error, status = 1 }

Ok _ ->
logAndExit { message = "Db is fine", status = 0 }
)
, subscriptions = always Sub.none
, update = \_ _ -> ( (), Cmd.none )
}


port logAndExit : { message : String, status : Int } -> Cmd msg

0 comments on commit b063595

Please sign in to comment.