Skip to content

Commit

Permalink
fix: mistake in user-type-enums migration (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSamuel authored Sep 4, 2024
1 parent 285b3ea commit 2aeeb7c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/migrations/1725196803203-user-type-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
*/
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

const UserTypeMapping: Record<string, number> = {
MEMBER: 1,
ORGAN: 2,
VOUCHER: 3,
LOCAL_USER: 4,
LOCAL_ADMIN: 5,
INVOICE: 6,
POINT_OF_SALE: 7,
const UserTypeMapping: Record<string, string> = {
MEMBER: '1',
ORGAN: '2',
VOUCHER: '3',
LOCAL_USER: '4',
LOCAL_ADMIN: '5',
INVOICE: '6',
POINT_OF_SALE: '7',
};

export class UserTypeEnums1725196803203 implements MigrationInterface {
Expand All @@ -50,13 +50,12 @@ export class UserTypeEnums1725196803203 implements MigrationInterface {
await queryRunner.query('ALTER TABLE role_user_type MODIFY userType varchar(64) NOT NULL');
}

const promises: Promise<void>[] = [];
Object.entries(UserTypeMapping).forEach(([key, value]) => {
promises.push(queryRunner.query('UPDATE user SET type = ? WHERE type = ?', [key, value]));
promises.push(queryRunner.query('UPDATE role_user_type SET userType = ? WHERE userType = ?', [key, value]));
});

await Promise.all(promises);
for (let userTypeMappingKey in UserTypeMapping) {
console.warn(`Updating user type ${userTypeMappingKey} to ${UserTypeMapping[userTypeMappingKey]}`);
console.warn('UPDATE user SET type = ? WHERE type = ?', [userTypeMappingKey, UserTypeMapping[userTypeMappingKey]]);
await queryRunner.query('UPDATE user SET type = ? WHERE type = ?', [userTypeMappingKey, UserTypeMapping[userTypeMappingKey]]);
await queryRunner.query('UPDATE role_user_type SET userType = ? WHERE userType = ?', [userTypeMappingKey, UserTypeMapping[userTypeMappingKey]]);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
Expand Down

0 comments on commit 2aeeb7c

Please sign in to comment.