Skip to content

Commit d019195

Browse files
committed
Delete readId/writeId/adminId/searchEngines map columns during migration
1 parent b01261f commit d019195

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

server/src/database-backend/migrations.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default class DatabaseBackendMigrations {
140140
console.log("DB migration: Rename map writeId to adminId");
141141
const MapModel = this.backend.maps.MapModel;
142142
await queryInterface.renameColumn('Maps', 'writeId', 'adminId');
143-
await queryInterface.addColumn('Maps', 'writeId', MapModel.rawAttributes.writeId);
143+
await queryInterface.addColumn('Maps', 'writeId', { type: DataTypes.STRING, allowNull: false });
144144

145145
const maps = await MapModel.findAll<MapModel>();
146146
for(const map of maps) {
@@ -1023,15 +1023,15 @@ export default class DatabaseBackendMigrations {
10231023
const queryInterface = this.backend._conn.getQueryInterface();
10241024
const attrs = await queryInterface.describeTable(this.backend.maps.MapModel.getTableName());
10251025

1026-
if (!attrs["readId"] && !attrs["writeId"] && !attrs["adminId"]) {
1026+
if (!attrs["readId"] && !attrs["writeId"] && !attrs["adminId"] && !attrs["searchEngines"]) {
10271027
return;
10281028
}
10291029

10301030
console.log("DB migration: Create map link table");
10311031

10321032
// If some ID columns are already missing, the previous migration attempt aborted while deleting columns. This means
10331033
// that the MapLinks table is already ready.
1034-
if (attrs["readId"] && attrs["writeId"] && attrs["adminId"]) {
1034+
if (attrs["readId"] && attrs["writeId"] && attrs["adminId"] && attrs["searchEngines"]) {
10351035
const allMaps = await this.backend.maps.MapModel.findAll({
10361036
attributes: ["id", "salt", "jwtSecret", "readId", "writeId", "adminId", "searchEngines"]
10371037
});
@@ -1080,6 +1080,21 @@ export default class DatabaseBackendMigrations {
10801080
}, 8); // Maximum concurrency is 4 by default, can be increased through UV_THREADPOOL_SIZE, see https://nodejs.org/dist/latest-v16.x/docs/api/cli.html#uv_threadpool_sizesize
10811081
}
10821082

1083+
// Delete adminId before writeId to avoid problem in _renameColMigrations() (renames writeId to adminId
1084+
// if writeId exists and adminId doesn't) if this aborts in the middle.
1085+
if (attrs["adminId"]) {
1086+
await queryInterface.removeColumn(this.backend.maps.MapModel.getTableName(), "adminId");
1087+
}
1088+
if (attrs["writeId"]) {
1089+
await queryInterface.removeColumn(this.backend.maps.MapModel.getTableName(), "writeId");
1090+
}
1091+
if (attrs["readId"]) {
1092+
await queryInterface.removeColumn(this.backend.maps.MapModel.getTableName(), "readId");
1093+
}
1094+
if (attrs["searchEngines"]) {
1095+
await queryInterface.removeColumn(this.backend.maps.MapModel.getTableName(), "searchEngines");
1096+
}
1097+
10831098
console.log("DB migration: Create map link table finished");
10841099
}
10851100

0 commit comments

Comments
 (0)