Skip to content

Commit

Permalink
fix: ensure DB migration runs (#1120)
Browse files Browse the repository at this point in the history
* ensure DB migration runs

* add beta to branch QA
  • Loading branch information
jenbutongit authored Sep 15, 2023
1 parent a7e93f3 commit e440f3f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/branch--lint-unit-and-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- beta
paths-ignore:
- "docs/**"
- "**/README.md"
Expand Down
2 changes: 0 additions & 2 deletions submitter/src/submission/createServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import hapi, { ServerOptions } from "@hapi/hapi";
import { pluginLogging } from "./plugins/logging";
import { pluginQueue } from "./plugins/queue";
import config from "../config";
import { QueueService, WebhookService } from "./services";
import Schmervice from "schmervice";
Expand Down Expand Up @@ -37,7 +36,6 @@ export async function createServer(): Promise<hapi.Server> {
const server = hapi.server(serverOptions);

await server.register(pluginLogging);
await server.register(pluginQueue);
await server.register(Schmervice);

server.registerService([WebhookService, QueueService]);
Expand Down
12 changes: 9 additions & 3 deletions submitter/src/submission/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { createServer } from "./createServer";
import { setupDatabase } from "./setupDatabase";

async function initApp() {
const server = await createServer();
await setupDatabase();

await server.start();
process.send && process.send("online");
const server = await createServer();
try {
await server.start();
process?.send?.("online");
} catch (e) {
throw e;
}
}

initApp().catch((err) => {
Expand Down
30 changes: 0 additions & 30 deletions submitter/src/submission/plugins/queue.ts

This file was deleted.

4 changes: 3 additions & 1 deletion submitter/src/submission/retention/redactSubmissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ let RETENTION_PERIOD = 365;

try {
RETENTION_PERIOD = parseInt(config.retentionPeriod);
logger.info(`config.retentionPeriod set to ${config.rentionPeriod}`);
logger.info(
`config.retentionPeriod set to ${config.rentionPeriod}, defaulting to ${RETENTION_PERIOD} instead`
);
} catch (e) {
logger.error(R_ERRORS.CONFIG);
}
Expand Down
29 changes: 29 additions & 0 deletions submitter/src/submission/setupDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { spawnSync } from "child_process";
import pino from "pino";
const logger = pino();

export function setupDatabase() {
const schemaLocation = require.resolve(
"@xgovformbuilder/queue-model/schema.prisma"
);

const child = spawnSync(
"prisma",
["migrate", "deploy", "--schema", schemaLocation],
{
encoding: "utf-8",
stdio: "inherit",
}
);

if (child.status === 1) {
logger.error("Could not connect to database, exiting");
logger.error(child.error);
process.exit(1);
}

if (child.stdout) {
logger.info(child.stdout);
logger.info("Database migration was successful, continuing");
}
}

0 comments on commit e440f3f

Please sign in to comment.