permission system - permission formatting
This commit is contained in:
parent
d889f92643
commit
2f5d9d3f01
15 changed files with 352 additions and 18 deletions
46
src/migrations/1724661484664-permissions.ts
Normal file
46
src/migrations/1724661484664-permissions.ts
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue