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()
|
@Entity()
|
||||||
export class api {
|
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;
|
token: string;
|
||||||
|
|
||||||
@Column({ type: "varchar", length: 255 })
|
@Column({ type: "varchar", length: 255 })
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { api } from "./api";
|
||||||
@Entity()
|
@Entity()
|
||||||
export class apiPermission {
|
export class apiPermission {
|
||||||
@PrimaryColumn({ type: "int" })
|
@PrimaryColumn({ type: "int" })
|
||||||
apiToken: number;
|
apiId: number;
|
||||||
|
|
||||||
@PrimaryColumn({ type: "varchar", length: 255 })
|
@PrimaryColumn({ type: "varchar", length: 255 })
|
||||||
permission: PermissionString;
|
permission: PermissionString;
|
||||||
|
|
|
@ -11,11 +11,12 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
|
||||||
new Table({
|
new Table({
|
||||||
name: "api",
|
name: "api",
|
||||||
columns: [
|
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: "title", type: "varchar", length: "255", isNullable: false },
|
||||||
{ name: "createdAt", type: "datetime", default: "CURRENT_TIMESTAMP(6)", isNullable: false },
|
{ name: "createdAt", type: "datetime", default: "CURRENT_TIMESTAMP(6)", isNullable: false },
|
||||||
{ name: "lastUsage", type: "datetime", isNullable: true },
|
{ name: "lastUsage", type: "datetime", isNullable: true, default: null },
|
||||||
{ name: "expiry", type: "datetime", isNullable: true },
|
{ name: "expiry", type: "datetime", isNullable: true, default: null },
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
true
|
true
|
||||||
|
@ -25,17 +26,18 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
|
||||||
new Table({
|
new Table({
|
||||||
name: "api_permission",
|
name: "api_permission",
|
||||||
columns: [
|
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 },
|
{ name: "permission", type: "varchar", length: "255", isPrimary: true, isNullable: false },
|
||||||
],
|
],
|
||||||
})
|
}),
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
await queryRunner.createForeignKey(
|
await queryRunner.createForeignKey(
|
||||||
"api_permission",
|
"api_permission",
|
||||||
new TableForeignKey({
|
new TableForeignKey({
|
||||||
columnNames: ["apiToken"],
|
columnNames: ["apiId"],
|
||||||
referencedColumnNames: ["token"],
|
referencedColumnNames: ["id"],
|
||||||
referencedTableName: "api",
|
referencedTableName: "api",
|
||||||
onDelete: "CASCADE",
|
onDelete: "CASCADE",
|
||||||
onUpdate: "RESTRICT",
|
onUpdate: "RESTRICT",
|
||||||
|
|
Loading…
Reference in a new issue