Skip to content

Commit

Permalink
5億年かかるマイグレを修正 (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
riku6460 authored Oct 20, 2023
1 parent 2053f64 commit 26ccb2c
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions packages/backend/migration/1696807733453-userListUserId.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export class UserListUserId1696807733453 {

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_list_membership" ADD "userListUserId" character varying(32) NOT NULL DEFAULT ''`);
const memberships = await queryRunner.query(`SELECT "id", "userListId" FROM "user_list_membership"`);
for(let i = 0; i < memberships.length; i++) {
const userList = await queryRunner.query(`SELECT "userId" FROM "user_list" WHERE "id" = $1`, [memberships[i].userListId]);
await queryRunner.query(`UPDATE "user_list_membership" SET "userListUserId" = $1 WHERE "id" = $2`, [userList[0].userId, memberships[i].id]);
}
await queryRunner.query(`UPDATE "user_list_membership" SET "userListUserId" = "user_list"."userId" FROM "user_list" WHERE "user_list_membership"."userListId" = "user_list"."id"`);
}

async down(queryRunner) {
Expand Down

0 comments on commit 26ccb2c

Please sign in to comment.