Skip to content

Commit 4916602

Browse files
committed
Experiment with migration
1 parent 1e323f1 commit 4916602

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

server/src/database-backend/migrations.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -819,23 +819,25 @@ export default class DatabaseBackendMigrations {
819819
if (mapIdMigrationCompleted === "1") {
820820
console.log("DB migration: Generate values for Map.id");
821821

822-
// Copy back readId to id, in case the last ID generation failed (otherwise we might create duplicate IDs below).
823-
await queryInterface.bulkUpdate("Maps", { id: col("readId") }, {});
822+
// Copy back readId to id, in case the last ID generation failed (otherwise the ID generation below would crash with duplicate
823+
// primary keys).
824+
// We prefix the ID so that existing IDs that happen to be a number don't collide with the IDs we generate.
825+
await queryInterface.bulkUpdate("Maps", { id: fn("concat", "-", col("readId")) }, {});
824826

825827
const maps = await this.backend.maps.MapModel.findAll({
826828
attributes: ["id"]
827829
});
828830

829831
// First generate increasing ID numbers as strings in the existing column
830-
// for (let i = 0; i < maps.length; i++) {
831-
// await this.backend.maps.MapModel.update({
832-
// id: `${i + 1}` as any
833-
// }, {
834-
// where: {
835-
// id: maps[i].id
836-
// }
837-
// });
838-
// }
832+
for (let i = 0; i < maps.length; i++) {
833+
await this.backend.maps.MapModel.update({
834+
id: `${i + 1}` as any
835+
}, {
836+
where: {
837+
id: maps[i].id
838+
}
839+
});
840+
}
839841

840842
await this.backend.meta.setMeta("mapIdMigrationCompleted", "2");
841843
mapIdMigrationCompleted = "2";

0 commit comments

Comments
 (0)