refactor(core): Remove roleId indirection (no-changelog) (#8413)
This commit is contained in:
committed by
GitHub
parent
1affebd85e
commit
d6deceacde
@@ -1,5 +1,5 @@
|
||||
import type { TableForeignKeyOptions, TableIndexOptions, QueryRunner } from 'typeorm';
|
||||
import { Table, TableColumn } from 'typeorm';
|
||||
import { Table, TableColumn, TableForeignKey } from 'typeorm';
|
||||
import LazyPromise from 'p-lazy';
|
||||
import { Column } from './Column';
|
||||
import { ApplicationError } from 'n8n-workflow';
|
||||
@@ -118,6 +118,42 @@ export class DropColumns extends TableOperation {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ForeignKeyOperation extends TableOperation {
|
||||
protected foreignKey: TableForeignKey;
|
||||
|
||||
constructor(
|
||||
tableName: string,
|
||||
columnName: string,
|
||||
[referencedTableName, referencedColumnName]: [string, string],
|
||||
prefix: string,
|
||||
queryRunner: QueryRunner,
|
||||
customConstraintName?: string,
|
||||
) {
|
||||
super(tableName, prefix, queryRunner);
|
||||
|
||||
this.foreignKey = new TableForeignKey({
|
||||
name: customConstraintName,
|
||||
columnNames: [columnName],
|
||||
referencedTableName: `${prefix}${referencedTableName}`,
|
||||
referencedColumnNames: [referencedColumnName],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class AddForeignKey extends ForeignKeyOperation {
|
||||
async execute(queryRunner: QueryRunner) {
|
||||
const { tableName, prefix } = this;
|
||||
return await queryRunner.createForeignKey(`${prefix}${tableName}`, this.foreignKey);
|
||||
}
|
||||
}
|
||||
|
||||
export class DropForeignKey extends ForeignKeyOperation {
|
||||
async execute(queryRunner: QueryRunner) {
|
||||
const { tableName, prefix } = this;
|
||||
return await queryRunner.dropForeignKey(`${prefix}${tableName}`, this.foreignKey);
|
||||
}
|
||||
}
|
||||
|
||||
class ModifyNotNull extends TableOperation {
|
||||
constructor(
|
||||
tableName: string,
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import type { QueryRunner } from 'typeorm';
|
||||
import { Column } from './Column';
|
||||
import { AddColumns, AddNotNull, CreateTable, DropColumns, DropNotNull, DropTable } from './Table';
|
||||
import {
|
||||
AddColumns,
|
||||
AddForeignKey,
|
||||
AddNotNull,
|
||||
CreateTable,
|
||||
DropColumns,
|
||||
DropForeignKey,
|
||||
DropNotNull,
|
||||
DropTable,
|
||||
} from './Table';
|
||||
import { CreateIndex, DropIndex } from './Indices';
|
||||
|
||||
export const createSchemaBuilder = (tablePrefix: string, queryRunner: QueryRunner) => ({
|
||||
@@ -26,6 +35,36 @@ export const createSchemaBuilder = (tablePrefix: string, queryRunner: QueryRunne
|
||||
dropIndex: (tableName: string, columnNames: string[], customIndexName?: string) =>
|
||||
new DropIndex(tableName, columnNames, tablePrefix, queryRunner, customIndexName),
|
||||
|
||||
addForeignKey: (
|
||||
tableName: string,
|
||||
columnName: string,
|
||||
reference: [string, string],
|
||||
customConstraintName?: string,
|
||||
) =>
|
||||
new AddForeignKey(
|
||||
tableName,
|
||||
columnName,
|
||||
reference,
|
||||
tablePrefix,
|
||||
queryRunner,
|
||||
customConstraintName,
|
||||
),
|
||||
|
||||
dropForeignKey: (
|
||||
tableName: string,
|
||||
columnName: string,
|
||||
reference: [string, string],
|
||||
customConstraintName?: string,
|
||||
) =>
|
||||
new DropForeignKey(
|
||||
tableName,
|
||||
columnName,
|
||||
reference,
|
||||
tablePrefix,
|
||||
queryRunner,
|
||||
customConstraintName,
|
||||
),
|
||||
|
||||
addNotNull: (tableName: string, columnName: string) =>
|
||||
new AddNotNull(tableName, columnName, tablePrefix, queryRunner),
|
||||
dropNotNull: (tableName: string, columnName: string) =>
|
||||
|
||||
Reference in New Issue
Block a user