1
0
Fork 0

Fix trying to access database before migrations ran

This commit is contained in:
Cadence Ember 2024-09-01 15:26:25 +12:00
parent a218774c13
commit c689ec00b7

View file

@ -5,11 +5,6 @@ const reg = require("./read-registration")
const ks = require("./kstate") const ks = require("./kstate")
const {applyKStateDiffToRoom, roomToKState} = require("../d2m/actions/create-room") const {applyKStateDiffToRoom, roomToKState} = require("../d2m/actions/create-room")
// Migrate reg.ooye.invite setting to database
for (const mxid of reg.ooye.invite) {
db.prepare("INSERT OR IGNORE INTO member_power (mxid, room_id, power_level) VALUES (?, ?, 100)").run(mxid, "*")
}
/** Apply global power level requests across ALL rooms where the member cache entry exists but the power level has not been applied yet. */ /** Apply global power level requests across ALL rooms where the member cache entry exists but the power level has not been applied yet. */
function _getAffectedRooms() { function _getAffectedRooms() {
return from("member_cache").join("member_power", "mxid") return from("member_cache").join("member_power", "mxid")
@ -19,6 +14,11 @@ function _getAffectedRooms() {
} }
async function applyPower() { async function applyPower() {
// Migrate reg.ooye.invite setting to database
for (const mxid of reg.ooye.invite) {
db.prepare("INSERT OR IGNORE INTO member_power (mxid, room_id, power_level) VALUES (?, ?, 100)").run(mxid, "*")
}
const rows = _getAffectedRooms() const rows = _getAffectedRooms()
for (const row of rows) { for (const row of rows) {
const kstate = await roomToKState(row.room_id) const kstate = await roomToKState(row.room_id)