mirror of
https://git.waldn.net/git/knotteye/satyr.git
synced 2025-10-22 03:42:42 +00:00
Modify the migration script to import existing data.
This commit is contained in:
16
src/db/3.ts
16
src/db/3.ts
@@ -1,9 +1,21 @@
|
||||
import * as db from "../database";
|
||||
import * as dirty from "dirty";
|
||||
|
||||
async function run () {
|
||||
await db.query('CREATE TABLE IF NOT EXISTS ch_bans(channel VARCHAR(25), target VARCHAR(45), time BIGINT, length INT DEFAULT 30)');
|
||||
await db.query('INSERT INTO ch_bans(channel) SELECT username FROM users');
|
||||
await db.query('INSERT INTO db_meta (version) VALUES (3)');
|
||||
console.log('!!! This migration has a race condition when run from the `npm run migrate` command. If thats how this was called, please re-run this migration manually.\n!!! Run `npm run v3-manual` to do so');
|
||||
var bansdb = new dirty('./config/bans.db')
|
||||
bansdb.on('load', async () => {
|
||||
bansdb.forEach(async (key, val) => {
|
||||
let ips = Object.keys(val);
|
||||
for(var i=0;i<ips.length;i++){
|
||||
await db.query('INSERT INTO ch_bans (channel, target, time, length) VALUES ('+db.raw.escape(key)+', '+db.raw.escape(ips[i])+', '+val[ips[i]].time+', '+val[ips[i]].length+')');
|
||||
}
|
||||
});
|
||||
await db.query('INSERT INTO db_meta (version) VALUES (3)');
|
||||
console.log('Done migrating bans.db');
|
||||
console.log('If this was a manual migration, you can kill the process now.');
|
||||
});
|
||||
}
|
||||
|
||||
export { run }
|
6
src/v3manual.ts
Normal file
6
src/v3manual.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as db from "./database";
|
||||
async function main() {
|
||||
await db.init();
|
||||
await require('./db/3.ts').run();
|
||||
}
|
||||
main();
|
Reference in New Issue
Block a user