renaming api module to webapi

This commit is contained in:
Julian Krauser 2025-01-22 09:39:31 +01:00
parent 0b40b9d92c
commit 313785b4ac
21 changed files with 247 additions and 238 deletions

View file

@ -1,17 +1,17 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from "typeorm";
import { DB_TYPE } from "../env.defaults";
export class AddApiTokens1737453096674 implements MigrationInterface {
name = "AddApiTokens1737453096674";
export class AddWebapiTokens1737453096674 implements MigrationInterface {
name = "AddWebApiTokens1737453096674";
public async up(queryRunner: QueryRunner): Promise<void> {
const variableType_int = DB_TYPE == "mysql" ? "int" : "integer";
await queryRunner.createTable(
new Table({
name: "api",
name: "webapi",
columns: [
{ name: "id", type: variableType_int, isPrimary: true, isNullable: false },
{ name: "id", type: variableType_int, isPrimary: true, isGenerated: true, generationStrategy: "increment" },
{ 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 },
@ -24,9 +24,9 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
await queryRunner.createTable(
new Table({
name: "api_permission",
name: "webapi_permission",
columns: [
{ name: "apiId", type: variableType_int, isPrimary: true, isNullable: false },
{ name: "webapiId", type: variableType_int, isPrimary: true, isNullable: false },
{ name: "permission", type: "varchar", length: "255", isPrimary: true, isNullable: false },
],
}),
@ -34,11 +34,11 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
);
await queryRunner.createForeignKey(
"api_permission",
"webapi_permission",
new TableForeignKey({
columnNames: ["apiId"],
columnNames: ["webapiId"],
referencedColumnNames: ["id"],
referencedTableName: "api",
referencedTableName: "webapi",
onDelete: "CASCADE",
onUpdate: "RESTRICT",
})
@ -46,10 +46,10 @@ export class AddApiTokens1737453096674 implements MigrationInterface {
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("api_permission");
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("apiToken") !== -1);
await queryRunner.dropForeignKey("api_permission", foreignKey);
await queryRunner.dropTable("api_permission");
await queryRunner.dropTable("api");
const table = await queryRunner.getTable("webapi_permission");
const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf("webapiId") !== -1);
await queryRunner.dropForeignKey("webapi_permission", foreignKey);
await queryRunner.dropTable("webapi_permission");
await queryRunner.dropTable("webapi");
}
}