mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(core): Fixes issue with workflow lastUpdated field (#5015)
Fixed issue causing workflow updated field to be affected by statistics data
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
import { logMigrationEnd, logMigrationStart } from '@db/utils/migrationHelpers';
|
||||
import config from '@/config';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { StatisticsNames } from '@/databases/entities/WorkflowStatistics';
|
||||
|
||||
export class RemoveWorkflowDataLoadedFlag1671726148419 implements MigrationInterface {
|
||||
name = 'RemoveWorkflowDataLoadedFlag1671726148419';
|
||||
|
||||
async up(queryRunner: QueryRunner) {
|
||||
logMigrationStart(this.name);
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
|
||||
// If any existing workflow has dataLoaded set to true, insert the relevant information to the statistics table
|
||||
const workflowIds: Array<{ id: number; dataLoaded: boolean }> = await queryRunner.query(`
|
||||
SELECT id, dataLoaded
|
||||
FROM "${tablePrefix}workflow_entity"
|
||||
`);
|
||||
|
||||
workflowIds.map(({ id, dataLoaded }) => {
|
||||
if (dataLoaded) {
|
||||
const [insertQuery, insertParams] = queryRunner.connection.driver.escapeQueryWithParameters(
|
||||
`
|
||||
INSERT INTO "${tablePrefix}workflow_statistics" (workflowId, name, count, latestEvent) VALUES
|
||||
(:id, :name, 1, STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))
|
||||
`,
|
||||
{ id, name: StatisticsNames.dataLoaded },
|
||||
{},
|
||||
);
|
||||
|
||||
return queryRunner.query(insertQuery, insertParams);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`${tablePrefix}workflow_entity\` DROP COLUMN "dataLoaded"`,
|
||||
);
|
||||
|
||||
logMigrationEnd(this.name);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner) {
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE \`${tablePrefix}workflow_entity\` ADD COLUMN "dataLoaded" BOOLEAN DEFAULT false`,
|
||||
);
|
||||
|
||||
// Search through statistics for any workflows that have the dataLoaded stat
|
||||
const workflowsIds: Array<{ workflowId: string }> = await queryRunner.query(`
|
||||
SELECT workflowId
|
||||
FROM "${tablePrefix}workflow_statistics"
|
||||
WHERE name = '${StatisticsNames.dataLoaded}'
|
||||
`);
|
||||
workflowsIds.map(({ workflowId }) => {
|
||||
return queryRunner.query(`
|
||||
UPDATE "${tablePrefix}workflow_entity"
|
||||
SET dataLoaded = true
|
||||
WHERE id = '${workflowId}'`);
|
||||
});
|
||||
|
||||
await queryRunner.query(
|
||||
`DELETE FROM "${tablePrefix}workflow_statistics" WHERE name = '${StatisticsNames.dataLoaded}'`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import { CreateCredentialUsageTable1665484192211 } from './1665484192211-CreateC
|
||||
import { RemoveCredentialUsageTable1665754637024 } from './1665754637024-RemoveCredentialUsageTable';
|
||||
import { AddWorkflowVersionIdColumn1669739707124 } from './1669739707124-AddWorkflowVersionIdColumn';
|
||||
import { AddTriggerCountColumn1669823906993 } from './1669823906993-AddTriggerCountColumn';
|
||||
import { RemoveWorkflowDataLoadedFlag1671726148419 } from './1671726148419-RemoveWorkflowDataLoadedFlag';
|
||||
import { MessageEventBusDestinations1671535397530 } from './1671535397530-MessageEventBusDestinations';
|
||||
|
||||
const sqliteMigrations = [
|
||||
@@ -51,6 +52,7 @@ const sqliteMigrations = [
|
||||
AddWorkflowVersionIdColumn1669739707124,
|
||||
AddTriggerCountColumn1669823906993,
|
||||
WorkflowStatistics1664196174000,
|
||||
RemoveWorkflowDataLoadedFlag1671726148419,
|
||||
MessageEventBusDestinations1671535397530,
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user