permission system - permission formatting

This commit is contained in:
Julian Krauser 2024-08-26 13:47:08 +02:00
parent d889f92643
commit 2f5d9d3f01
15 changed files with 352 additions and 18 deletions

View file

@ -0,0 +1,46 @@
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");
}
}