Skip to content

Commit

Permalink
solves RED-52
Browse files Browse the repository at this point in the history
  • Loading branch information
sombriks committed Jun 17, 2024
1 parent fa9b73d commit d7056f4
Show file tree
Hide file tree
Showing 56 changed files with 2,723 additions and 2,174 deletions.
12 changes: 8 additions & 4 deletions service-node-koa/app/config/_test_hooks.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {dbMigrate, knex} from "./db/index.mjs";
import { dbMigrate, knex } from "./db/index.mjs";

/**
* hooks to make sure there will be a testing database available and proper
* teardown after all tests are done https://mochajs.org/#root-hook-plugins
*/
export const mochaHooks = {
async beforeAll() { await dbMigrate() },
async afterAll() { await knex.destroy() }
}
async beforeAll() {
await dbMigrate();
},
async afterAll() {
await knex.destroy();
},
};
16 changes: 8 additions & 8 deletions service-node-koa/app/config/base-logging.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Cabin from 'cabin'
import Signale from 'signale/signale.js'
import Cabin from "cabin";
import Signale from "signale/signale.js";

export const logger = new Signale({
config: {
// displayFilename: true,
displayTimestamp: true,
displayDate: true,
}
config: {
// displayFilename: true,
displayTimestamp: true,
displayDate: true,
},
});
export const cabin = new Cabin({ logger })
export const cabin = new Cabin({ logger });
8 changes: 4 additions & 4 deletions service-node-koa/app/config/db/index.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Knex from "knex"
import cfg from "./knexfile.cjs"
import Knex from "knex";
import cfg from "./knexfile.cjs";

const nodeEnv = process.env.NODE_ENV || "development"
const nodeEnv = process.env.NODE_ENV || "development";

export const dbMigrate = () => knex.migrate.latest(cfg[nodeEnv]);

export const knex = Knex(cfg[nodeEnv])
export const knex = Knex(cfg[nodeEnv]);
86 changes: 42 additions & 44 deletions service-node-koa/app/config/db/knexfile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,50 @@
* @type { import('knex').Knex.Config }
*/
const _cfg = {
client: 'sqlite3',
useNullAsDefault: true,
connection: {
filename: `${__dirname}/../../../redline.sqlite3`
},
pool: {
min: 2,
max: 10
},
migrations: {
directory: `${__dirname}/migrations`,
loadExtensions: ['.mjs']
}
}
client: "sqlite3",
useNullAsDefault: true,
connection: {
filename: `${__dirname}/../../../redline.sqlite3`,
},
pool: {
min: 2,
max: 10,
},
migrations: {
directory: `${__dirname}/migrations`,
loadExtensions: [".mjs"],
},
};

/**
* @type { Object.<string, import('knex').Knex.Config> }
*/
module.exports = {
development: {
..._cfg,
pool: {
..._cfg.pool,
afterCreate: (conn, cb) =>
conn.run('PRAGMA foreign_keys = ON', cb) // does not work with postgres
}
},
test: {
..._cfg,
connection: {
filename: ':memory:'
},
pool: {
..._cfg.pool,
afterCreate: (conn, cb) =>
conn.run('PRAGMA foreign_keys = ON', cb) // does not work with postgres
}
},
staging: {
..._cfg,
client: 'pg',
connection: process.env.PG_CONNECTION_URL
},
production: {
..._cfg,
client: 'pg',
connection: process.env.PG_CONNECTION_URL
}
}
development: {
..._cfg,
pool: {
..._cfg.pool,
afterCreate: (conn, cb) => conn.run("PRAGMA foreign_keys = ON", cb), // does not work with postgres
},
},
test: {
..._cfg,
connection: {
filename: ":memory:",
},
pool: {
..._cfg.pool,
afterCreate: (conn, cb) => conn.run("PRAGMA foreign_keys = ON", cb), // does not work with postgres
},
},
staging: {
..._cfg,
client: "pg",
connection: process.env.PG_CONNECTION_URL,
},
production: {
..._cfg,
client: "pg",
connection: process.env.PG_CONNECTION_URL,
},
};
Loading

0 comments on commit d7056f4

Please sign in to comment.