From bd5bc543095f2419c564691a22b151747a28f3bc Mon Sep 17 00:00:00 2001 From: Will Hunt <will@half-shot.uk> Date: Sat, 9 Feb 2019 12:50:12 +0000 Subject: [PATCH] Test v8 migrations --- src/db/schema/v8.ts | 9 +++++ test/db/test_roomstore.ts | 72 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/src/db/schema/v8.ts b/src/db/schema/v8.ts index 44fca26..96890f9 100644 --- a/src/db/schema/v8.ts +++ b/src/db/schema/v8.ts @@ -62,18 +62,27 @@ export class Schema implements IDbSchema { } log.warn("Migrating rooms from roomstore, this may take a while..."); const rooms = await this.roomStore.select({}); + log.info(`Found ${rooms.length} rooms in the DB`); // Matrix room only entrys are useless. const entrys = rooms.filter((r) => r.remote); + log.info(`Filtered out rooms without remotes. Have ${entrys.length} entries`); + let migrated = 0; for (const e of entrys) { const matrix = new MatrixStoreRoom(e.matrix_id); try { const remote = new RemoteStoreRoom(e.remote_id, e.remote); await store.roomStore.linkRooms(matrix, remote); log.info(`Migrated ${matrix.roomId}`); + migrated++; } catch (ex) { log.error(`Failed to link ${matrix.roomId}: `, ex); } } + if (migrated !== entrys.length) { + log.error(`Didn't migrate all rooms, ${entrys.length - migrated} failed to be migrated.`); + } else { + log.info("Migrated all rooms successfully"); + } } public async rollBack(store: DiscordStore): Promise<void> { diff --git a/test/db/test_roomstore.ts b/test/db/test_roomstore.ts index 45f9f75..fea079e 100644 --- a/test/db/test_roomstore.ts +++ b/test/db/test_roomstore.ts @@ -193,3 +193,75 @@ describe("RoomStore", () => { }); }); }); +describe("RoomStore.schema.v8", () => { + it("will successfully migrate rooms", async () => { + const SCHEMA_VERSION = 8; + store = new DiscordStore(":memory:"); + const roomStore = { + select: () => { + return [ + { + _id: "DGFUYs4hlXNDmmw0", + id: "123", + matrix: {extras: {}}, + matrix_id: "!badroom:localhost", + }, + { + _id: "Dd37MWDw57dAQz5p", + data: {}, + id: "!xdnLTCNErGnwsGnmnm:localhost discord_282616294245662720_514843269599985674_bridged", + matrix: { + extras: {}, + }, + matrix_id: "!bridged1:localhost", + remote: { + discord_channel: "514843269599985674", + discord_guild: "282616294245662720", + discord_type: "text", + plumbed: false, + }, + remote_id: "discord_282616294245662720_514843269599985674_bridged", + }, + { + _id: "H3XEftQWj8BZYuCe", + data: {}, + id: "!oGkfjmeNEkJdFasVRF:localhost discord_282616294245662720_520332167952334849", + matrix: { + extras: {}, + }, + matrix_id: "!bridged2:localhost", + remote: { + discord_channel: "514843269599985674", + discord_guild: "282616294245662720", + discord_type: "text", + plumbed: true, + update_icon: true, + update_name: false, + update_topic: true, + }, + remote_id: "discord_282616294245662720_520332167952334849", + }, + ]; + }, + }; + await store.init(SCHEMA_VERSION, roomStore); + expect(await store.roomStore.getEntriesByMatrixId("!badroom:localhost")).to.be.empty; + const bridge1 = (await store.roomStore.getEntriesByMatrixId("!bridged1:localhost"))[0]; + expect(bridge1).to.exist; + expect(bridge1.remote).to.not.be.null; + expect(bridge1.remote!.data.discord_channel).to.be.equal("514843269599985674"); + expect(bridge1.remote!.data.discord_guild).to.be.equal("282616294245662720"); + expect(bridge1.remote!.data.discord_type).to.be.equal("text"); + expect(!!bridge1.remote!.data.plumbed).to.be.false; + const bridge2 = (await store.roomStore.getEntriesByMatrixId("!bridged2:localhost"))[0]; + expect(bridge2).to.exist; + expect(bridge2.remote).to.not.be.null; + expect(bridge2.remote!.data.discord_channel).to.be.equal("514843269599985674"); + expect(bridge2.remote!.data.discord_guild).to.be.equal("282616294245662720"); + expect(bridge2.remote!.data.discord_type).to.be.equal("text"); + expect(!!bridge2.remote!.data.plumbed).to.be.true; + expect(!!bridge2.remote!.data.update_icon).to.be.true; + expect(!!bridge2.remote!.data.update_name).to.be.false; + expect(!!bridge2.remote!.data.update_topic).to.be.true; + }); +}); -- GitLab