wrapping up: membership id transfer

This commit is contained in:
Julian Krauser 2025-01-10 11:51:55 +01:00
parent c173f917e3
commit 9dac14470f
3 changed files with 43 additions and 26 deletions

View file

@ -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;

View file

@ -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> {

View 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,
})
);
}
}