mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 12:22:50 +02:00
allow overriding ooye data directory
This commit is contained in:
parent
d8e6de62e5
commit
42b331135d
11 changed files with 37 additions and 18 deletions
|
@ -12,6 +12,7 @@ if (!channelID) {
|
||||||
|
|
||||||
const assert = require("assert/strict")
|
const assert = require("assert/strict")
|
||||||
const sqlite = require("better-sqlite3")
|
const sqlite = require("better-sqlite3")
|
||||||
|
const path = require("path")
|
||||||
const backfill = new sqlite("scripts/backfill.db")
|
const backfill = new sqlite("scripts/backfill.db")
|
||||||
backfill.prepare("CREATE TABLE IF NOT EXISTS backfill (channel_id TEXT NOT NULL, message_id INTEGER NOT NULL, PRIMARY KEY (channel_id, message_id))").run()
|
backfill.prepare("CREATE TABLE IF NOT EXISTS backfill (channel_id TEXT NOT NULL, message_id INTEGER NOT NULL, PRIMARY KEY (channel_id, message_id))").run()
|
||||||
|
|
||||||
|
@ -19,9 +20,10 @@ const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
const db = new sqlite("ooye.db")
|
const db = getDatabase()
|
||||||
Object.assign(passthrough, {sync, db})
|
Object.assign(passthrough, {sync, db})
|
||||||
|
|
||||||
const DiscordClient = require("../src/d2m/discord-client")
|
const DiscordClient = require("../src/d2m/discord-client")
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
// Trigger the database migration flow and exit after committing.
|
// Trigger the database migration flow and exit after committing.
|
||||||
// You can use this to run migrations locally and check the result using sqlitebrowser.
|
// You can use this to run migrations locally and check the result using sqlitebrowser.
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
const migrate = require("../src/db/migrate")
|
const migrate = require("../src/db/migrate")
|
||||||
|
|
||||||
Object.assign(passthrough, {db})
|
Object.assign(passthrough, {db})
|
||||||
|
|
|
@ -16,7 +16,8 @@ const oldAT = reg.old_bridge.as_token
|
||||||
const newAT = reg.as_token
|
const newAT = reg.as_token
|
||||||
|
|
||||||
const oldDB = new sqlite(reg.old_bridge.database)
|
const oldDB = new sqlite(reg.old_bridge.database)
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
db.exec(`CREATE TABLE IF NOT EXISTS half_shot_migration (
|
db.exec(`CREATE TABLE IF NOT EXISTS half_shot_migration (
|
||||||
discord_channel TEXT NOT NULL,
|
discord_channel TEXT NOT NULL,
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
const {getDatabase} = require("../src/db/database")
|
||||||
const db = new sqlite("db/ooye.db")
|
const db = getDatabase()
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
Object.assign(passthrough, {db, sync})
|
Object.assign(passthrough, {db, sync})
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ if (fs.existsSync("db")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
const migrate = require("../src/db/migrate")
|
const migrate = require("../src/db/migrate")
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
const {createServer} = require("http")
|
const {createServer} = require("http")
|
||||||
const EventEmitter = require("events")
|
const EventEmitter = require("events")
|
||||||
const {createApp, createRouter, toNodeListener} = require("h3")
|
const {createApp, createRouter, toNodeListener} = require("h3")
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const migrate = require("../src/db/migrate")
|
const migrate = require("../src/db/migrate")
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("../src/matrix/read-registration")
|
const {reg} = require("../src/matrix/read-registration")
|
||||||
const passthrough = require("../src/passthrough")
|
const passthrough = require("../src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("../src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync()
|
const sync = new HeatSync()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const sqlite = require("better-sqlite3")
|
const {getDatabase} = require("../src/db/database")
|
||||||
const db = new sqlite("ooye.db", {fileMustExist: true})
|
const db = getDatabase({fileMustExist: true})
|
||||||
db.pragma("journal_mode = wal")
|
db.pragma("journal_mode = wal")
|
||||||
db.close()
|
db.close()
|
||||||
|
|
16
src/db/database.js
Normal file
16
src/db/database.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
|
const sqlite = require("better-sqlite3")
|
||||||
|
const path = require("path")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new SQLite database instance
|
||||||
|
* @param {import("better-sqlite3").Options} [options] - SQLite options
|
||||||
|
* @returns {import("better-sqlite3").Database} Database instance
|
||||||
|
*/
|
||||||
|
function getDatabase(options = {}) {
|
||||||
|
const dataDir = process.env.OOYE_DATA_DIR || process.cwd()
|
||||||
|
return new sqlite(path.join(dataDir, "ooye.db"), options)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {getDatabase}
|
4
start.js
4
start.js
|
@ -2,13 +2,13 @@
|
||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const sqlite = require("better-sqlite3")
|
|
||||||
const migrate = require("./src/db/migrate")
|
const migrate = require("./src/db/migrate")
|
||||||
const HeatSync = require("heatsync")
|
const HeatSync = require("heatsync")
|
||||||
|
|
||||||
const {reg} = require("./src/matrix/read-registration")
|
const {reg} = require("./src/matrix/read-registration")
|
||||||
const passthrough = require("./src/passthrough")
|
const passthrough = require("./src/passthrough")
|
||||||
const db = new sqlite("ooye.db")
|
const {getDatabase} = require("./src/db/database")
|
||||||
|
const db = getDatabase()
|
||||||
|
|
||||||
const sync = new HeatSync({watchFunction: fs.watchFile})
|
const sync = new HeatSync({watchFunction: fs.watchFile})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue