wrapping up: membership id transfer
This commit is contained in:
parent
c173f917e3
commit
632a8290ac
4 changed files with 45 additions and 26 deletions
|
@ -66,6 +66,7 @@ import { PostalCode1735927918979 } from "./migrations/1735927918979-postalCode";
|
||||||
import { ProtocolAbsent1736072179716 } from "./migrations/1736072179716-protocolAbsent";
|
import { ProtocolAbsent1736072179716 } from "./migrations/1736072179716-protocolAbsent";
|
||||||
import { Memberlist1736079005086 } from "./migrations/1736079005086-memberlist";
|
import { Memberlist1736079005086 } from "./migrations/1736079005086-memberlist";
|
||||||
import { ExtendViewValues1736084198860 } from "./migrations/1736084198860-extendViewValues";
|
import { ExtendViewValues1736084198860 } from "./migrations/1736084198860-extendViewValues";
|
||||||
|
import { FinishInternalIdTransfer1736505324488 } from "./migrations/1736505324488-finishInternalIdTransfer";
|
||||||
|
|
||||||
const dataSource = new DataSource({
|
const dataSource = new DataSource({
|
||||||
type: DB_TYPE as any,
|
type: DB_TYPE as any,
|
||||||
|
@ -142,6 +143,7 @@ const dataSource = new DataSource({
|
||||||
ProtocolAbsent1736072179716,
|
ProtocolAbsent1736072179716,
|
||||||
Memberlist1736079005086,
|
Memberlist1736079005086,
|
||||||
ExtendViewValues1736084198860,
|
ExtendViewValues1736084198860,
|
||||||
|
FinishInternalIdTransfer1736505324488,
|
||||||
],
|
],
|
||||||
migrationsRun: true,
|
migrationsRun: true,
|
||||||
migrationsTransactionMode: "each",
|
migrationsTransactionMode: "each",
|
||||||
|
|
|
@ -7,12 +7,6 @@ export class membership {
|
||||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
@Column({ type: "varchar", length: 255, unique: true, nullable: true })
|
|
||||||
internalId?: string;
|
|
||||||
|
|
||||||
@Column({ type: "date" })
|
@Column({ type: "date" })
|
||||||
start: Date;
|
start: Date;
|
||||||
|
|
||||||
|
|
|
@ -18,27 +18,27 @@ export class InternalId1735822722235 implements MigrationInterface {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
let memberships = await queryRunner.manager.getRepository(membership).find();
|
// let memberships = await queryRunner.manager.getRepository(membership).find();
|
||||||
console.log(memberships);
|
// console.log(memberships);
|
||||||
let internalIds = memberships.reduce<{ [key: number]: Array<string> }>((acc, cur) => {
|
// let internalIds = memberships.reduce<{ [key: number]: Array<string> }>((acc, cur) => {
|
||||||
let memberId = cur.memberId;
|
// let memberId = cur.memberId;
|
||||||
let setIds = acc[memberId] ?? [];
|
// let setIds = acc[memberId] ?? [];
|
||||||
if (cur?.internalId) {
|
// if (cur?.internalId) {
|
||||||
setIds.push(cur.internalId);
|
// setIds.push(cur.internalId);
|
||||||
}
|
// }
|
||||||
acc[memberId] = setIds;
|
// acc[memberId] = setIds;
|
||||||
return acc;
|
// return acc;
|
||||||
}, {});
|
// }, {});
|
||||||
|
|
||||||
console.log(internalIds);
|
// console.log(internalIds);
|
||||||
for (const [id, value] of Object.entries(internalIds)) {
|
// for (const [id, value] of Object.entries(internalIds)) {
|
||||||
const ids = value.filter((v) => v != null).join(", ");
|
// const ids = value.filter((v) => v != null).join(", ");
|
||||||
if (ids) {
|
// if (ids) {
|
||||||
let m = await queryRunner.manager.getRepository(member).findOneByOrFail({ id: parseInt(id) });
|
// let m = await queryRunner.manager.getRepository(member).findOneByOrFail({ id: parseInt(id) });
|
||||||
m.internalId = ids;
|
// m.internalId = ids;
|
||||||
await queryRunner.manager.getRepository(member).save(m);
|
// await queryRunner.manager.getRepository(member).save(m);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
|
23
src/migrations/1736505324488-finishInternalIdTransfer.ts
Normal file
23
src/migrations/1736505324488-finishInternalIdTransfer.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";
|
||||||
|
|
||||||
|
export class FinishInternalIdTransfer1736505324488 implements MigrationInterface {
|
||||||
|
name = "FinishInternalIdTransfer1736505324488";
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.dropColumn("membership", "internalId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.addColumn(
|
||||||
|
"membership",
|
||||||
|
new TableColumn({
|
||||||
|
name: "internalId",
|
||||||
|
type: "varchar",
|
||||||
|
length: "255",
|
||||||
|
default: null,
|
||||||
|
isNullable: true,
|
||||||
|
isUnique: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue