Modify the migration script to import existing data.

pull/20/head
knotteye 2021-01-10 11:01:28 -06:00
parent a882285bac
commit 814d826ec9
4 changed files with 25 additions and 6 deletions

8
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "satyr", "name": "satyr",
"version": "0.10.1", "version": "0.10.2",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -1110,9 +1110,9 @@
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.8",
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
}, },
"ipaddr.js": { "ipaddr.js": {
"version": "1.9.0", "version": "1.9.0",

View File

@ -10,6 +10,7 @@
"setup": "sh install/setup.sh", "setup": "sh install/setup.sh",
"migrate": "ts-node src/migrate.ts", "migrate": "ts-node src/migrate.ts",
"invite": "ts-node src/cli.ts --invite", "invite": "ts-node src/cli.ts --invite",
"v3-manual": "ts-node src/v3manual.ts",
"make-templates": "nunjucks-precompile -i [\"\\.html$\",\"\\.njk$\"] templates > site/templates.js" "make-templates": "nunjucks-precompile -i [\"\\.html$\",\"\\.njk$\"] templates > site/templates.js"
}, },
"repository": { "repository": {

View File

@ -1,9 +1,21 @@
import * as db from "../database"; import * as db from "../database";
import * as dirty from "dirty";
async function run () { 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('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'); 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)'); 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 } export { run }

6
src/v3manual.ts Normal file
View File

@ -0,0 +1,6 @@
import * as db from "./database";
async function main() {
await db.init();
await require('./db/3.ts').run();
}
main();