mirror of
https://github.com/usatiuk/photos.git
synced 2025-10-28 23:37:48 +01:00
run migrations inside the app
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
npm run typeorm -- migration:run
|
npm start
|
||||||
|
|
||||||
npm start
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Connection } from "typeorm";
|
||||||
import { Config, ConfigKey, setConfigValue } from "~entity/Config";
|
import { Config, ConfigKey, setConfigValue } from "~entity/Config";
|
||||||
import { app } from "./app";
|
import { app } from "./app";
|
||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
@@ -25,18 +26,29 @@ async function dumpConfig() {
|
|||||||
console.log(`${entry.key} = ${entry.value}`);
|
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()
|
connect()
|
||||||
.then((connection) => {
|
.then((connection) => {
|
||||||
console.log(`Connected to ${connection.name}`);
|
console.log(`Connected to ${connection.name}`);
|
||||||
const startApp = () => {
|
|
||||||
app.listen(config.port);
|
|
||||||
console.log(`Listening at ${config.port}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
readConfig()
|
migrate(connection)
|
||||||
.then(() =>
|
.then(() =>
|
||||||
dumpConfig()
|
readConfig()
|
||||||
.then(() => startApp())
|
.then(() =>
|
||||||
|
dumpConfig()
|
||||||
|
.then(() => startApp())
|
||||||
|
.catch((e) => console.log(e)),
|
||||||
|
)
|
||||||
.catch((e) => console.log(e)),
|
.catch((e) => console.log(e)),
|
||||||
)
|
)
|
||||||
.catch((e) => console.log(e));
|
.catch((e) => console.log(e));
|
||||||
|
|||||||
Reference in New Issue
Block a user