Skip to content
Extraits de code Groupes Projets
Valider bd5bc543 rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Test v8 migrations

parent 3fd2b98e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -62,18 +62,27 @@ export class Schema implements IDbSchema { ...@@ -62,18 +62,27 @@ export class Schema implements IDbSchema {
} }
log.warn("Migrating rooms from roomstore, this may take a while..."); log.warn("Migrating rooms from roomstore, this may take a while...");
const rooms = await this.roomStore.select({}); const rooms = await this.roomStore.select({});
log.info(`Found ${rooms.length} rooms in the DB`);
// Matrix room only entrys are useless. // Matrix room only entrys are useless.
const entrys = rooms.filter((r) => r.remote); 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) { for (const e of entrys) {
const matrix = new MatrixStoreRoom(e.matrix_id); const matrix = new MatrixStoreRoom(e.matrix_id);
try { try {
const remote = new RemoteStoreRoom(e.remote_id, e.remote); const remote = new RemoteStoreRoom(e.remote_id, e.remote);
await store.roomStore.linkRooms(matrix, remote); await store.roomStore.linkRooms(matrix, remote);
log.info(`Migrated ${matrix.roomId}`); log.info(`Migrated ${matrix.roomId}`);
migrated++;
} catch (ex) { } catch (ex) {
log.error(`Failed to link ${matrix.roomId}: `, 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> { public async rollBack(store: DiscordStore): Promise<void> {
......
...@@ -193,3 +193,75 @@ describe("RoomStore", () => { ...@@ -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;
});
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter