refactor(core): Decouple datastore from workflow execution context (#18963)

This commit is contained in:
Iván Ovejero
2025-08-29 14:33:03 +02:00
committed by GitHub
parent 7cfef64799
commit 140e1b082e
6 changed files with 12 additions and 13 deletions

View File

@@ -60,6 +60,7 @@ export class DataStoreColumnRepository extends Repository<DataTableColumn> {
dataTableId, dataTableId,
}); });
// @ts-ignore Workaround for intermittent typecheck issue with _QueryDeepPartialEntity
await em.insert(DataTableColumn, column); await em.insert(DataTableColumn, column);
const queryRunner = em.queryRunner; const queryRunner = em.queryRunner;

View File

@@ -28,6 +28,7 @@ export class DataStoreRepository extends Repository<DataTable> {
let dataTableId: string | undefined; let dataTableId: string | undefined;
await this.manager.transaction(async (em) => { await this.manager.transaction(async (em) => {
const dataStore = em.create(DataTable, { name, columns, projectId }); const dataStore = em.create(DataTable, { name, columns, projectId });
// @ts-ignore Workaround for intermittent typecheck issue with _QueryDeepPartialEntity
await em.insert(DataTable, dataStore); await em.insert(DataTable, dataStore);
dataTableId = dataStore.id; dataTableId = dataStore.id;

View File

@@ -2,7 +2,6 @@ import { Logger } from '@n8n/backend-common';
import type { ModuleInterface } from '@n8n/decorators'; import type { ModuleInterface } from '@n8n/decorators';
import { BackendModule, OnShutdown } from '@n8n/decorators'; import { BackendModule, OnShutdown } from '@n8n/decorators';
import { Container } from '@n8n/di'; import { Container } from '@n8n/di';
import { BaseEntity } from '@n8n/typeorm';
const YELLOW = '\x1b[33m'; const YELLOW = '\x1b[33m';
const CLEAR = '\x1b[0m'; const CLEAR = '\x1b[0m';
@@ -38,6 +37,12 @@ export class DataStoreModule implements ModuleInterface {
const { DataTable } = await import('./data-table.entity'); const { DataTable } = await import('./data-table.entity');
const { DataTableColumn } = await import('./data-table-column.entity'); const { DataTableColumn } = await import('./data-table-column.entity');
return [DataTable, DataTableColumn] as unknown as Array<new () => BaseEntity>; return [DataTable, DataTableColumn];
}
async context() {
const { DataStoreProxyService } = await import('./data-store-proxy.service');
return { dataStoreProxyProvider: Container.get(DataStoreProxyService) };
} }
} }

View File

@@ -377,15 +377,7 @@ export async function getBase(
const eventService = Container.get(EventService); const eventService = Container.get(EventService);
const moduleRegistry = Container.get(ModuleRegistry);
const dataStoreProxyProvider = moduleRegistry.isActive('data-table')
? Container.get(
(await import('@/modules/data-table/data-store-proxy.service')).DataStoreProxyService,
)
: undefined;
const additionalData: IWorkflowExecuteAdditionalData = { const additionalData: IWorkflowExecuteAdditionalData = {
dataStoreProxyProvider,
currentNodeExecutionIndex: 0, currentNodeExecutionIndex: 0,
credentialsHelper: Container.get(CredentialsHelper), credentialsHelper: Container.get(CredentialsHelper),
executeWorkflow, executeWorkflow,

View File

@@ -7,7 +7,7 @@ declare module 'n8n-workflow' {
interface IWorkflowExecuteAdditionalData { interface IWorkflowExecuteAdditionalData {
hooks?: ExecutionLifecycleHooks; hooks?: ExecutionLifecycleHooks;
externalSecretsProxy: ExternalSecretsProxy; externalSecretsProxy: ExternalSecretsProxy;
dataStoreProxyProvider?: DataStoreProxyProvider; 'data-table'?: { dataStoreProxyProvider: DataStoreProxyProvider };
dataStoreProjectId?: string; dataStoreProjectId?: string;
} }
} }

View File

@@ -10,8 +10,8 @@ export function getDataStoreHelperFunctions(
workflow: Workflow, workflow: Workflow,
node: INode, node: INode,
): Partial<DataStoreProxyFunctions> { ): Partial<DataStoreProxyFunctions> {
if (additionalData.dataStoreProxyProvider === undefined) return {}; const dataStoreProxyProvider = additionalData['data-table']?.dataStoreProxyProvider;
const dataStoreProxyProvider = additionalData.dataStoreProxyProvider; if (!dataStoreProxyProvider) return {};
return { return {
getDataStoreAggregateProxy: async () => getDataStoreAggregateProxy: async () =>
await dataStoreProxyProvider.getDataStoreAggregateProxy( await dataStoreProxyProvider.getDataStoreAggregateProxy(