mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Add a migration for data stores (no-changelog) (#18045)
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
import type { MigrationContext, ReversibleMigration } from '../migration-types';
|
||||||
|
|
||||||
|
const DATA_STORE_TABLE_NAME = 'data_store';
|
||||||
|
const DATA_STORE_COLUMN_TABLE_NAME = 'data_store_column';
|
||||||
|
|
||||||
|
export class CreateDataStoreTables1754475614601 implements ReversibleMigration {
|
||||||
|
async up({ schemaBuilder: { createTable, column } }: MigrationContext) {
|
||||||
|
await createTable(DATA_STORE_TABLE_NAME)
|
||||||
|
.withColumns(
|
||||||
|
column('id').varchar(36).primary,
|
||||||
|
column('name').varchar(128).notNull,
|
||||||
|
column('projectId').varchar(36).notNull,
|
||||||
|
column('sizeBytes').int.default(0).notNull,
|
||||||
|
)
|
||||||
|
.withForeignKey('projectId', {
|
||||||
|
tableName: 'project',
|
||||||
|
columnName: 'id',
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
.withUniqueConstraintOn(['projectId', 'name']).withTimestamps;
|
||||||
|
|
||||||
|
await createTable(DATA_STORE_COLUMN_TABLE_NAME)
|
||||||
|
.withColumns(
|
||||||
|
column('id').varchar(36).primary.notNull,
|
||||||
|
column('name').varchar(128).notNull,
|
||||||
|
column('type')
|
||||||
|
.varchar(32)
|
||||||
|
.notNull.comment(
|
||||||
|
'Expected: string, number, boolean, or date (not enforced as a constraint)',
|
||||||
|
),
|
||||||
|
column('index').int.notNull.comment('Column order, starting from 0 (0 = first column)'),
|
||||||
|
column('dataStoreId').varchar(36).notNull,
|
||||||
|
)
|
||||||
|
.withForeignKey('dataStoreId', {
|
||||||
|
tableName: DATA_STORE_TABLE_NAME,
|
||||||
|
columnName: 'id',
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
.withUniqueConstraintOn(['dataStoreId', 'name']).withTimestamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
async down({ schemaBuilder: { dropTable } }: MigrationContext) {
|
||||||
|
await dropTable(DATA_STORE_COLUMN_TABLE_NAME);
|
||||||
|
await dropTable(DATA_STORE_TABLE_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { TableForeignKeyOptions, TableIndexOptions, QueryRunner } from '@n8n/typeorm';
|
import type { TableForeignKeyOptions, TableIndexOptions, QueryRunner } from '@n8n/typeorm';
|
||||||
import { Table, TableColumn, TableForeignKey } from '@n8n/typeorm';
|
import { Table, TableColumn, TableForeignKey, TableUnique } from '@n8n/typeorm';
|
||||||
import { UnexpectedError } from 'n8n-workflow';
|
import { UnexpectedError } from 'n8n-workflow';
|
||||||
import LazyPromise from 'p-lazy';
|
import LazyPromise from 'p-lazy';
|
||||||
|
|
||||||
@@ -24,6 +24,8 @@ export class CreateTable extends TableOperation {
|
|||||||
|
|
||||||
private indices = new Set<TableIndexOptions>();
|
private indices = new Set<TableIndexOptions>();
|
||||||
|
|
||||||
|
private uniqueConstraints = new Set<TableUnique>();
|
||||||
|
|
||||||
private foreignKeys = new Set<TableForeignKeyOptions>();
|
private foreignKeys = new Set<TableForeignKeyOptions>();
|
||||||
|
|
||||||
withColumns(...columns: Column[]) {
|
withColumns(...columns: Column[]) {
|
||||||
@@ -45,6 +47,12 @@ export class CreateTable extends TableOperation {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
withUniqueConstraintOn(columnName: string | string[]) {
|
||||||
|
const columnNames = Array.isArray(columnName) ? columnName : [columnName];
|
||||||
|
this.uniqueConstraints.add(new TableUnique({ columnNames }));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
withForeignKey(
|
withForeignKey(
|
||||||
columnName: string,
|
columnName: string,
|
||||||
ref: {
|
ref: {
|
||||||
@@ -69,12 +77,13 @@ export class CreateTable extends TableOperation {
|
|||||||
|
|
||||||
async execute(queryRunner: QueryRunner) {
|
async execute(queryRunner: QueryRunner) {
|
||||||
const { driver } = queryRunner.connection;
|
const { driver } = queryRunner.connection;
|
||||||
const { columns, tableName: name, prefix, indices, foreignKeys } = this;
|
const { columns, tableName: name, prefix, indices, uniqueConstraints, foreignKeys } = this;
|
||||||
return await queryRunner.createTable(
|
return await queryRunner.createTable(
|
||||||
new Table({
|
new Table({
|
||||||
name: `${prefix}${name}`,
|
name: `${prefix}${name}`,
|
||||||
columns: columns.map((c) => c.toOptions(driver)),
|
columns: columns.map((c) => c.toOptions(driver)),
|
||||||
...(indices.size ? { indices: [...indices] } : {}),
|
...(indices.size ? { indices: [...indices] } : {}),
|
||||||
|
...(uniqueConstraints.size ? { uniques: [...uniqueConstraints] } : {}),
|
||||||
...(foreignKeys.size ? { foreignKeys: [...foreignKeys] } : {}),
|
...(foreignKeys.size ? { foreignKeys: [...foreignKeys] } : {}),
|
||||||
...('mysql' in driver ? { engine: 'InnoDB' } : {}),
|
...('mysql' in driver ? { engine: 'InnoDB' } : {}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ import { DropRoleTable1745934666077 } from '../common/1745934666077-DropRoleTabl
|
|||||||
import { AddProjectDescriptionColumn1747824239000 } from '../common/1747824239000-AddProjectDescriptionColumn';
|
import { AddProjectDescriptionColumn1747824239000 } from '../common/1747824239000-AddProjectDescriptionColumn';
|
||||||
import { AddLastActiveAtColumnToUser1750252139166 } from '../common/1750252139166-AddLastActiveAtColumnToUser';
|
import { AddLastActiveAtColumnToUser1750252139166 } from '../common/1750252139166-AddLastActiveAtColumnToUser';
|
||||||
import { AddInputsOutputsToTestCaseExecution1752669793000 } from '../common/1752669793000-AddInputsOutputsToTestCaseExecution';
|
import { AddInputsOutputsToTestCaseExecution1752669793000 } from '../common/1752669793000-AddInputsOutputsToTestCaseExecution';
|
||||||
|
import { CreateDataStoreTables1754475614601 } from '../common/1754475614601-CreateDataStoreTables';
|
||||||
import type { Migration } from '../migration-types';
|
import type { Migration } from '../migration-types';
|
||||||
import { UpdateParentFolderIdColumn1740445074052 } from '../mysqldb/1740445074052-UpdateParentFolderIdColumn';
|
import { UpdateParentFolderIdColumn1740445074052 } from '../mysqldb/1740445074052-UpdateParentFolderIdColumn';
|
||||||
|
|
||||||
@@ -185,4 +186,5 @@ export const mysqlMigrations: Migration[] = [
|
|||||||
AddProjectDescriptionColumn1747824239000,
|
AddProjectDescriptionColumn1747824239000,
|
||||||
AddLastActiveAtColumnToUser1750252139166,
|
AddLastActiveAtColumnToUser1750252139166,
|
||||||
AddInputsOutputsToTestCaseExecution1752669793000,
|
AddInputsOutputsToTestCaseExecution1752669793000,
|
||||||
|
CreateDataStoreTables1754475614601,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ import { AddWorkflowArchivedColumn1745934666076 } from '../common/1745934666076-
|
|||||||
import { DropRoleTable1745934666077 } from '../common/1745934666077-DropRoleTable';
|
import { DropRoleTable1745934666077 } from '../common/1745934666077-DropRoleTable';
|
||||||
import { AddProjectDescriptionColumn1747824239000 } from '../common/1747824239000-AddProjectDescriptionColumn';
|
import { AddProjectDescriptionColumn1747824239000 } from '../common/1747824239000-AddProjectDescriptionColumn';
|
||||||
import { AddLastActiveAtColumnToUser1750252139166 } from '../common/1750252139166-AddLastActiveAtColumnToUser';
|
import { AddLastActiveAtColumnToUser1750252139166 } from '../common/1750252139166-AddLastActiveAtColumnToUser';
|
||||||
|
import { CreateDataStoreTables1754475614601 } from '../common/1754475614601-CreateDataStoreTables';
|
||||||
import type { Migration } from '../migration-types';
|
import type { Migration } from '../migration-types';
|
||||||
|
|
||||||
export const postgresMigrations: Migration[] = [
|
export const postgresMigrations: Migration[] = [
|
||||||
@@ -183,4 +184,5 @@ export const postgresMigrations: Migration[] = [
|
|||||||
AddProjectDescriptionColumn1747824239000,
|
AddProjectDescriptionColumn1747824239000,
|
||||||
AddLastActiveAtColumnToUser1750252139166,
|
AddLastActiveAtColumnToUser1750252139166,
|
||||||
AddInputsOutputsToTestCaseExecution1752669793000,
|
AddInputsOutputsToTestCaseExecution1752669793000,
|
||||||
|
CreateDataStoreTables1754475614601,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ import { DropRoleTable1745934666077 } from '../common/1745934666077-DropRoleTabl
|
|||||||
import { AddProjectDescriptionColumn1747824239000 } from '../common/1747824239000-AddProjectDescriptionColumn';
|
import { AddProjectDescriptionColumn1747824239000 } from '../common/1747824239000-AddProjectDescriptionColumn';
|
||||||
import { AddLastActiveAtColumnToUser1750252139166 } from '../common/1750252139166-AddLastActiveAtColumnToUser';
|
import { AddLastActiveAtColumnToUser1750252139166 } from '../common/1750252139166-AddLastActiveAtColumnToUser';
|
||||||
import { AddInputsOutputsToTestCaseExecution1752669793000 } from '../common/1752669793000-AddInputsOutputsToTestCaseExecution';
|
import { AddInputsOutputsToTestCaseExecution1752669793000 } from '../common/1752669793000-AddInputsOutputsToTestCaseExecution';
|
||||||
|
import { CreateDataStoreTables1754475614601 } from '../common/1754475614601-CreateDataStoreTables';
|
||||||
import type { Migration } from '../migration-types';
|
import type { Migration } from '../migration-types';
|
||||||
|
|
||||||
const sqliteMigrations: Migration[] = [
|
const sqliteMigrations: Migration[] = [
|
||||||
@@ -177,6 +178,7 @@ const sqliteMigrations: Migration[] = [
|
|||||||
AddProjectDescriptionColumn1747824239000,
|
AddProjectDescriptionColumn1747824239000,
|
||||||
AddLastActiveAtColumnToUser1750252139166,
|
AddLastActiveAtColumnToUser1750252139166,
|
||||||
AddInputsOutputsToTestCaseExecution1752669793000,
|
AddInputsOutputsToTestCaseExecution1752669793000,
|
||||||
|
CreateDataStoreTables1754475614601,
|
||||||
];
|
];
|
||||||
|
|
||||||
export { sqliteMigrations };
|
export { sqliteMigrations };
|
||||||
|
|||||||
Reference in New Issue
Block a user