ff-admin-server/src/migrations/1725435669492-member_base_data.ts

107 lines
3.8 KiB
TypeScript
Raw Normal View History

2024-09-04 09:36:52 +00:00
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
export class MemberBaseData1725435669492 implements MigrationInterface {
name = "MemberBaseData1725435669492";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "award",
columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "award", type: "varchar", length: "255", isNullable: false },
2024-09-04 09:36:52 +00:00
],
}),
true
);
await queryRunner.createTable(
new Table({
name: "communication_type",
columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "type", type: "varchar", length: "255", isNullable: false },
{ name: "useColumns", type: "varchar", length: "255", isNullable: false, default: "''" },
2024-09-04 09:36:52 +00:00
],
}),
true
);
await queryRunner.createTable(
new Table({
name: "communication",
columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "preffered", type: "tinyint", isNullable: false, default: 0 },
{ name: "mobile", type: "varchar", length: "255", isNullable: false },
{ name: "email", type: "varchar", length: "255", isNullable: false },
{ name: "city", type: "varchar", length: "255", isNullable: false },
{ name: "street", type: "varchar", length: "255", isNullable: false },
{ name: "streetNumber", type: "int", isNullable: false },
{ name: "streetNumberAddition", type: "varchar", length: "255", isNullable: false },
{ name: "typeId", type: "int", isNullable: false },
2024-09-04 09:36:52 +00:00
],
}),
true
);
await queryRunner.createTable(
new Table({
name: "executive_position",
columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "position", type: "varchar", length: "255", isNullable: false },
2024-09-04 09:36:52 +00:00
],
}),
true
);
await queryRunner.createTable(
new Table({
name: "membership_status",
columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "status", type: "varchar", length: "255", isNullable: false },
2024-09-04 09:36:52 +00:00
],
}),
true
);
await queryRunner.createTable(
new Table({
name: "qualification",
columns: [
{ name: "id", type: "int", isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ name: "qualification", type: "varchar", length: "255", isNullable: false },
{ name: "description", type: "varchar", length: "255", isNullable: true },
2024-09-04 09:36:52 +00:00
],
}),
true
);
await queryRunner.createForeignKey(
"communication",
new TableForeignKey({
columnNames: ["typeId"],
referencedColumnNames: ["id"],
referencedTableName: "communication_type",
onDelete: "RESTRICT",
onUpdate: "RESTRICT",
2024-09-04 09:36:52 +00:00
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const communication = await queryRunner.getTable("communication");
const foreignKey = communication.foreignKeys.find((fk) => fk.columnNames.indexOf("typeId") !== -1);
await queryRunner.dropForeignKey("communication", foreignKey);
await queryRunner.dropTable("qualification");
await queryRunner.dropTable("membership_status");
await queryRunner.dropTable("executive_position");
await queryRunner.dropTable("communication");
await queryRunner.dropTable("communication_type");
await queryRunner.dropTable("award");
}
}