46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
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");
|
|
}
|
|
}
|