mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-01 09:17:08 +02:00
Add migration
This commit is contained in:
parent
8e5e5965b1
commit
4ce78619ee
|
|
@ -0,0 +1,44 @@
|
|||
import type { MigrationContext, ReversibleMigration } from '../migration-types';
|
||||
|
||||
const workflowPublishHistoryTableName = 'workflow_publish_history';
|
||||
|
||||
export class CreateWorkflowPublishHistoryTable1763387043735 implements ReversibleMigration {
|
||||
async up({ schemaBuilder: { createTable, column }, runQuery }: MigrationContext) {
|
||||
await createTable(workflowPublishHistoryTableName)
|
||||
.withColumns(
|
||||
column('workflowId').varchar(36).notNull,
|
||||
column('versionId').varchar(36).notNull,
|
||||
column('status').varchar(36).notNull,
|
||||
)
|
||||
.withUpdatedAt.withForeignKey('workflowId', {
|
||||
tableName: 'workflow_entity',
|
||||
columnName: 'id',
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
.withForeignKey('versionId', {
|
||||
tableName: 'workflow_history',
|
||||
columnName: 'versionId',
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
.withUniqueConstraintOn(['workflowId', 'versionId'])
|
||||
.withIndexOn(['workflowId', 'versionId']);
|
||||
|
||||
const activeWorkflows = await runQuery<Array<{ id: string; versionId: string }>>(
|
||||
'SELECT we.id, we.versionId FROM workflow_entity we WHERE we.active;',
|
||||
);
|
||||
console.log(activeWorkflows);
|
||||
|
||||
if (activeWorkflows.length > 0) {
|
||||
const values = activeWorkflows
|
||||
.map(({ id, versionId }) => `('${id}', '${versionId}', 'activated')`)
|
||||
.join(',');
|
||||
await runQuery(
|
||||
`INSERT INTO ${workflowPublishHistoryTableName} (workflowId, versionId, status) VALUES ${values};`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async down({ schemaBuilder: { dropTable } }: MigrationContext) {
|
||||
await dropTable(workflowPublishHistoryTableName);
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,11 @@ export class CreateTable extends TableOperation {
|
|||
return this;
|
||||
}
|
||||
|
||||
get withUpdatedAt() {
|
||||
this.columns.push(new Column('updatedAt').timestampTimezone().notNull.default('NOW()'));
|
||||
return this;
|
||||
}
|
||||
|
||||
withIndexOn(columnName: string | string[], isUnique = false) {
|
||||
const columnNames = Array.isArray(columnName) ? columnName : [columnName];
|
||||
this.indices.add({ columnNames, isUnique });
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ import { AddToolsColumnToChatHubTables1761830340990 } from '../common/1761830340
|
|||
import { AddWorkflowDescriptionColumn1762177736257 } from '../common/1762177736257-AddWorkflowDescriptionColumn';
|
||||
import { BackfillMissingWorkflowHistoryRecords1762763704614 } from '../common/1762763704614-BackfillMissingWorkflowHistoryRecords';
|
||||
import { AddWorkflowHistoryAutoSaveFields1762847206508 } from '../common/1762847206508-AddWorkflowHistoryAutoSaveFields';
|
||||
import { CreateWorkflowPublishHistoryTable1763387043735 } from '../common/1763387043735-CreateWorkflowPublishHistoryTable';
|
||||
import type { Migration } from '../migration-types';
|
||||
|
||||
export const postgresMigrations: Migration[] = [
|
||||
|
|
@ -231,4 +232,5 @@ export const postgresMigrations: Migration[] = [
|
|||
ChangeDefaultForIdInUserTable1762771264000,
|
||||
AddWorkflowHistoryAutoSaveFields1762847206508,
|
||||
AddToolsColumnToChatHubTables1761830340990,
|
||||
CreateWorkflowPublishHistoryTable1763387043735,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ import { AddToolsColumnToChatHubTables1761830340990 } from '../common/1761830340
|
|||
import { AddWorkflowDescriptionColumn1762177736257 } from '../common/1762177736257-AddWorkflowDescriptionColumn';
|
||||
import { BackfillMissingWorkflowHistoryRecords1762763704614 } from '../common/1762763704614-BackfillMissingWorkflowHistoryRecords';
|
||||
import { AddWorkflowHistoryAutoSaveFields1762847206508 } from '../common/1762847206508-AddWorkflowHistoryAutoSaveFields';
|
||||
import { CreateWorkflowPublishHistoryTable1763387043735 } from '../common/1763387043735-CreateWorkflowPublishHistoryTable';
|
||||
import type { Migration } from '../migration-types';
|
||||
|
||||
const sqliteMigrations: Migration[] = [
|
||||
|
|
@ -223,6 +224,7 @@ const sqliteMigrations: Migration[] = [
|
|||
BackfillMissingWorkflowHistoryRecords1762763704614,
|
||||
AddWorkflowHistoryAutoSaveFields1762847206508,
|
||||
AddToolsColumnToChatHubTables1761830340990,
|
||||
CreateWorkflowPublishHistoryTable1763387043735,
|
||||
];
|
||||
|
||||
export { sqliteMigrations };
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user