run migrations inside the app

This commit is contained in:
2023-01-15 11:57:00 +01:00
parent 09844e5294
commit cd9f3f9cc4
2 changed files with 20 additions and 10 deletions

View File

@@ -1,5 +1,3 @@
#!/bin/bash
npm run typeorm -- migration:run
npm start
npm start

View File

@@ -1,3 +1,4 @@
import { Connection } from "typeorm";
import { Config, ConfigKey, setConfigValue } from "~entity/Config";
import { app } from "./app";
import { config } from "./config";
@@ -25,18 +26,29 @@ async function dumpConfig() {
console.log(`${entry.key} = ${entry.value}`);
}
}
async function migrate(connection: Connection) {
await connection.runMigrations();
console.log("Migrations ran");
}
async function startApp() {
app.listen(config.port);
console.log(`Listening at ${config.port}`);
}
connect()
.then((connection) => {
console.log(`Connected to ${connection.name}`);
const startApp = () => {
app.listen(config.port);
console.log(`Listening at ${config.port}`);
};
readConfig()
migrate(connection)
.then(() =>
dumpConfig()
.then(() => startApp())
readConfig()
.then(() =>
dumpConfig()
.then(() => startApp())
.catch((e) => console.log(e)),
)
.catch((e) => console.log(e)),
)
.catch((e) => console.log(e));