Skip to content

Commit 5a28751

Browse files
authored
Merge pull request #83 from icefoganalytics/test
Aug 8 Build
2 parents f76f551 + 40f35e0 commit 5a28751

File tree

9 files changed

+589
-52
lines changed

9 files changed

+589
-52
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ You can boot the production environment locally via:
250250
5. Booting the development database.
251251

252252
```bash
253-
dev db
253+
dev up db
254254
255255
# Or
256256
docker compose -f docker-compose.development.yaml up --remove-orphans db
@@ -264,6 +264,8 @@ You can boot the production environment locally via:
264264

265265
> Note that you must always boot the production app after booting the database.
266266

267+
7. Log in to the app at http://localhost:3000/dashboard.
268+
267269
### User Acceptance Testing (UAT)
268270

269271
Jenkins pipeline [Jenkinsfile](./Jenkinsfile) builds and deploys.

docker-compose.development.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
environment:
1111
NODE_ENV: development
1212
DB_HOST: db
13+
DB_DEFAULT_SCHEMA: sfa
1314
API_PORT: ${API_PORT:-3000}
1415
BASE_URL: "http://localhost:${API_PORT:-3000}"
1516
ports:

src/api/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const DB_USER = process.env.DB_USER || "";
2626
export const DB_PASS = process.env.DB_PASS || "";
2727
export const DB_HOST = process.env.DB_HOST || "";
2828
export const DB_PORT = process.env.DB_PORT || "";
29+
export const DB_DEFAULT_SCHEMA = process.env.DB_DEFAULT_SCHEMA;
2930

3031
export const BASE_URL = process.env.BASE_URL || "";
3132
export const CLIENT_ID = process.env.CLIENT_ID || "";
@@ -41,6 +42,7 @@ export const DB_CONFIG = {
4142
database: DB_NAME,
4243
port: parseInt(DB_PORT),
4344
},
45+
defaultSchema: DB_DEFAULT_SCHEMA || 'dbo',
4446
};
4547

4648
export const MAIL_FROM = process.env.MAIL_FROM || "sfa@yukon.ca";

src/api/db/db-client.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
1-
import knex, { Knex } from "knex";
1+
import knex, { Knex } from "knex"
2+
import camelcaseKeys from "camelcase-keys"
3+
import { snakeCase } from "lodash"
24

3-
import { DB_CONFIG } from "../config";
5+
import { DB_CONFIG } from "@/config"
46

5-
const db = knex(DB_CONFIG);
7+
const db = knex({
8+
client: DB_CONFIG.client,
9+
connection: DB_CONFIG.connection,
10+
postProcessResponse: (result, queryContext) => {
11+
if (Array.isArray(result)) {
12+
// For SELECT queries
13+
return result.map((row) => camelcaseKeys(row, { deep: true }))
14+
} else {
15+
// for INSERT/UPDATE/DELETE queries
16+
return camelcaseKeys(result, { deep: true })
17+
}
18+
},
19+
wrapIdentifier: (value, origImpl, queryContext) => origImpl(snakeCase(value)),
20+
})
621

7-
export default db;
22+
const dbWithSchema: Knex = new Proxy(db, {
23+
apply: (target, thisArg, argumentsList) => {
24+
return target(...argumentsList).withSchema(DB_CONFIG.defaultSchema)
25+
},
26+
get: (target, prop: keyof Knex) => {
27+
if (typeof target[prop] === "function") {
28+
if (prop === "withSchema") {
29+
return (schema: string) => target[prop](schema) // format taken from src/api/node_modules/knex/types/index.d.ts
30+
} else {
31+
return (...args: any[]) => target[prop](...args).withSchema(DB_CONFIG.defaultSchema)
32+
}
33+
}
34+
return target[prop]
35+
},
36+
})
37+
38+
export default dbWithSchema

0 commit comments

Comments
 (0)