diff --git a/README.md b/README.md index cddcc6a..2018270 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,13 @@ Follow the instructions after setup runs. ### Run the server ```bash -npm start +npm run start +``` +You can also run this to skip checking the database version on startup. +```bash +npm run start -- --skip-migrate +# don't forget to migrate manually when you update +npm run migrate ``` ## Contributing diff --git a/package.json b/package.json index f77afd1..840082b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "start": "ts-node src/index.ts", "user": "ts-node src/cli.ts", - "setup": "sh install/setup.sh" + "setup": "sh install/setup.sh", + "migrate": "ts-node src/migrate.ts" }, "repository": { "type": "git", diff --git a/src/cleanup.ts b/src/cleanup.ts index 00e55ae..56c9dc9 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -1,10 +1,42 @@ import * as db from "./database"; +import {readdirSync} from "fs"; -async function init() { +async function init(m?: boolean) { + if(!m){ + console.log('Checking database version.'); + var tmp: string[] = await db.query('show tables like \"db_meta\"'); + if(tmp.length === 0){ + console.log('No database version info, running initial migration.'); + await require('./db/0').run(); + await bringUpToDate(); + } + else { + await bringUpToDate(); + } + } + else { + console.log('Skipping database version check.'); + } //If satyr is restarted in the middle of a stream //it causes problems //Live flags in the database stay live await db.query('update user_meta set live=false'); } +async function bringUpToDate(): Promise{ + var versions: Object[] = await db.query('select * from db_meta'); + var scripts: Buffer[] | string[] = readdirSync('./src/db/', {withFileTypes: false}); + var diff: number = scripts.length - versions.length + if(diff === 0){ + console.log('No migration needed.'); + } else { + console.log('Versions differ, migrating now.'); + for(let i=0;i {process.exit()}); \ No newline at end of file