mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Fix sorting of executions not working on postgres and mysql (#15423)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { ExecutionRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
import { createExecution } from '@test-integration/db/executions';
|
||||
import { createWorkflow } from '@test-integration/db/workflows';
|
||||
@@ -23,12 +24,30 @@ describe('UserRepository', () => {
|
||||
});
|
||||
|
||||
describe('findManyByRangeQuery', () => {
|
||||
// eslint-disable-next-line n8n-local-rules/no-skipped-tests
|
||||
test.skip('sort by `createdAt` if `startedAt` is null', async () => {
|
||||
test('sort by `createdAt` if `startedAt` is null', async () => {
|
||||
const now = DateTime.utc();
|
||||
const workflow = await createWorkflow();
|
||||
const execution1 = await createExecution({}, workflow);
|
||||
const execution2 = await createExecution({ startedAt: null }, workflow);
|
||||
const execution3 = await createExecution({}, workflow);
|
||||
const execution1 = await createExecution(
|
||||
{
|
||||
createdAt: now.plus({ minute: 1 }).toJSDate(),
|
||||
startedAt: now.plus({ minute: 1 }).toJSDate(),
|
||||
},
|
||||
workflow,
|
||||
);
|
||||
const execution2 = await createExecution(
|
||||
{
|
||||
createdAt: now.plus({ minute: 2 }).toJSDate(),
|
||||
startedAt: null,
|
||||
},
|
||||
workflow,
|
||||
);
|
||||
const execution3 = await createExecution(
|
||||
{
|
||||
createdAt: now.plus({ minute: 3 }).toJSDate(),
|
||||
startedAt: now.plus({ minute: 3 }).toJSDate(),
|
||||
},
|
||||
workflow,
|
||||
);
|
||||
|
||||
const executions = await executionRepository.findManyByRangeQuery({
|
||||
workflowId: workflow.id,
|
||||
|
||||
@@ -32,13 +32,23 @@ export async function createExecution(
|
||||
>,
|
||||
workflow: IWorkflowBase,
|
||||
) {
|
||||
const { data, finished, mode, startedAt, stoppedAt, waitTill, status, deletedAt, metadata } =
|
||||
attributes;
|
||||
const {
|
||||
data,
|
||||
finished,
|
||||
mode,
|
||||
startedAt,
|
||||
stoppedAt,
|
||||
waitTill,
|
||||
status,
|
||||
deletedAt,
|
||||
metadata,
|
||||
createdAt,
|
||||
} = attributes;
|
||||
|
||||
const execution = await Container.get(ExecutionRepository).save({
|
||||
finished: finished ?? true,
|
||||
mode: mode ?? 'manual',
|
||||
createdAt: new Date(),
|
||||
createdAt: createdAt ?? new Date(),
|
||||
startedAt: startedAt === undefined ? new Date() : startedAt,
|
||||
...(workflow !== undefined && { workflowId: workflow.id }),
|
||||
stoppedAt: stoppedAt ?? new Date(),
|
||||
|
||||
Reference in New Issue
Block a user