ff-admin-server/src/migrations/1724661484664-permissions.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
export class Permissions1724661484664 implements MigrationInterface {
name = "Permissions1724661484664";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "permission",
columns: [
{
name: "permission",
type: "varchar",
length: "255",
isPrimary: true,
isNullable: false,
},
{
name: "userId",
type: "int",
isPrimary: true,
isNullable: false,
},
],
}),
true
);
await queryRunner.createForeignKey(
"permission",
new TableForeignKey({
columnNames: ["userId"],
referencedColumnNames: ["id"],
referencedTableName: "user",
onDelete: "No Action",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("permission");
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("userId") !== -1);
await queryRunner.dropForeignKey("permission", foreignKey);
await queryRunner.dropTable("permission");
}
}