extend api table by id
This commit is contained in:
parent
26d2f288e9
commit
ca6dbafaf1
3 changed files with 14 additions and 9 deletions
|
@ -2,7 +2,10 @@ import { Column, CreateDateColumn, Entity, PrimaryColumn } from "typeorm";
|
|||
|
||||
@Entity()
|
||||
export class api {
|
||||
@PrimaryColumn({ type: "varchar", length: 255 })
|
||||
@PrimaryColumn({ generated: "increment", type: "int" })
|
||||
id: number;
|
||||
|
||||
@Column({ type: "varchar", length: 255, unique: true, select: false })
|
||||
token: string;
|
||||
|
||||
@Column({ type: "varchar", length: 255 })
|
||||
|
|
|
@ -5,7 +5,7 @@ import { api } from "./api";
|
|||
@Entity()
|
||||
export class apiPermission {
|
||||
@PrimaryColumn({ type: "int" })
|
||||
apiToken: number;
|
||||
apiId: number;
|
||||
|
||||
@PrimaryColumn({ type: "varchar", length: 255 })
|
||||
permission: PermissionString;
|
||||
|
|
|
@ -11,11 +11,12 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
|
|||
new Table({
|
||||
name: "api",
|
||||
columns: [
|
||||
{ name: "token", type: "varchar", length: "255", isPrimary: true, isNullable: false },
|
||||
{ name: "id", type: variableType_int, isPrimary: true, isNullable: false },
|
||||
{ name: "token", type: "varchar", length: "255", isUnique: true, isNullable: false },
|
||||
{ name: "title", type: "varchar", length: "255", isNullable: false },
|
||||
{ name: "createdAt", type: "datetime", default: "CURRENT_TIMESTAMP(6)", isNullable: false },
|
||||
{ name: "lastUsage", type: "datetime", isNullable: true },
|
||||
{ name: "expiry", type: "datetime", isNullable: true },
|
||||
{ name: "lastUsage", type: "datetime", isNullable: true, default: null },
|
||||
{ name: "expiry", type: "datetime", isNullable: true, default: null },
|
||||
],
|
||||
}),
|
||||
true
|
||||
|
@ -25,17 +26,18 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
|
|||
new Table({
|
||||
name: "api_permission",
|
||||
columns: [
|
||||
{ name: "apiToken", type: "varchar", length: "255", isPrimary: true, isNullable: false },
|
||||
{ name: "apiId", type: variableType_int, isPrimary: true, isNullable: false },
|
||||
{ name: "permission", type: "varchar", length: "255", isPrimary: true, isNullable: false },
|
||||
],
|
||||
})
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
"api_permission",
|
||||
new TableForeignKey({
|
||||
columnNames: ["apiToken"],
|
||||
referencedColumnNames: ["token"],
|
||||
columnNames: ["apiId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "api",
|
||||
onDelete: "CASCADE",
|
||||
onUpdate: "RESTRICT",
|
||||
|
|
Loading…
Reference in a new issue