newsletter config CRUD
This commit is contained in:
parent
01ce3fdd39
commit
7d36ed3121
14 changed files with 274 additions and 1 deletions
39
src/migrations/1735207446910-newsletterConfig.ts
Normal file
39
src/migrations/1735207446910-newsletterConfig.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
|
||||
import { DB_TYPE } from "../env.defaults";
|
||||
|
||||
export class NewsletterConfig1735207446910 implements MigrationInterface {
|
||||
name = "NewsletterConfig1735207446910";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "newsletter_config",
|
||||
columns: [
|
||||
{ name: "comTypeId", type: variableType_int, isPrimary: true, isNullable: false },
|
||||
{ name: "config", type: "varchar", length: "255", isNullable: false },
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
"newsletter_config",
|
||||
new TableForeignKey({
|
||||
columnNames: ["comTypeId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "communication_type",
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const table = await queryRunner.getTable("newsletter_config");
|
||||
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("comTypeId") !== -1);
|
||||
await queryRunner.dropForeignKey("newsletter_config", foreignKey);
|
||||
await queryRunner.dropTable("newsletter_config");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue