Skip to content

Commit

Permalink
fix mig with staging dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Ryo committed May 15, 2024
1 parent c2e083c commit 086f02c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server/migrations/1713446226165-user-village-country-relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class UserVillageCountryRelation1713446226165 implements MigrationInterfa
}
const userCountryCode = userTable?.columns.find((c) => c.name === 'countryCode');
if (userCountryCode) {
const usersCountry: { id: number; countryCode: string }[] = await queryRunner.query(`SELECT id, countryCode FROM user;`);
const usersCountry: { id: number; countryCode: string | null }[] = await queryRunner.query(`SELECT id, countryCode FROM user;`);
// save data stored
for (const userCountry of usersCountry) {
const countryId: { id: number }[] = await queryRunner.query(`SELECT id FROM country WHERE isoCode='${userCountry.countryCode}';`);
Expand All @@ -75,10 +75,12 @@ export class UserVillageCountryRelation1713446226165 implements MigrationInterfa
}
const classroomCountryCode = classroomTable?.columns.find((c) => c.name === 'countryCode');
if (classroomCountryCode) {
const classroomCountryCodes: { id: number; countryCode: string }[] = await queryRunner.query(`SELECT id, countryCode FROM classroom`);
const classroomCountryCodes: { id: number; countryCode: string | null }[] = await queryRunner.query(`SELECT id, countryCode FROM classroom`);
for (const classroom of classroomCountryCodes) {
const country: { id: number }[] = await queryRunner.query(`SELECT id FROM country WHERE isoCode='${classroom.countryCode}';`);
await queryRunner.query(`UPDATE classroom SET countryId=${country[0].id} WHERE id=${classroom.id};`);
if (classroom.countryCode) {
const country: { id: number }[] = await queryRunner.query(`SELECT id FROM country WHERE isoCode='${classroom.countryCode}';`);
await queryRunner.query(`UPDATE classroom SET countryId=${country[0].id} WHERE id=${classroom.id};`);
}
}
await queryRunner.query(`ALTER TABLE classroom DROP COLUMN countryCode`);
}
Expand Down

0 comments on commit 086f02c

Please sign in to comment.