Skip to content

Commit 4467de1

Browse files
authored
Move apikey/webhook migration command from 1.3 to 1.1 (#13146)
1 parent 50e402a commit 4467de1

File tree

6 files changed

+37
-42
lines changed

6 files changed

+37
-42
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { WORKFLOW_RUN_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/wo
1515
import { WorkflowRunStatus } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
1616

1717
@Command({
18-
name: 'upgrade:1-2:add-enqueued-status-to-workflow-run',
18+
name: 'upgrade:1-1:add-enqueued-status-to-workflow-run',
1919
description: 'Add enqueued status to workflow run',
2020
})
2121
export class AddEnqueuedStatusToWorkflowRunCommand extends ActiveOrSuspendedWorkspacesMigrationCommandRunner {
@@ -65,6 +65,8 @@ export class AddEnqueuedStatusToWorkflowRunCommand extends ActiveOrSuspendedWork
6565
this.logger.log(
6666
`Workflow run status field metadata options already contain enqueued status for workspace ${workspaceId}`,
6767
);
68+
69+
return;
6870
} else if (options.dryRun) {
6971
this.logger.log(
7072
`Would add enqueued status to workflow run status field metadata for workspace ${workspaceId}`,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ApiKeyWorkspaceEntity } from 'src/modules/api-key/standard-objects/api-
1717
import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity';
1818

1919
@Command({
20-
name: 'upgrade:1-3:migrate-api-keys-webhooks-to-core',
20+
name: 'upgrade:1-1:migrate-api-keys-webhooks-to-core',
2121
description:
2222
'Migrate API keys and webhooks from workspace schemas to core schema',
2323
})

packages/twenty-server/src/database/commands/upgrade-version-command/1-1/1-1-upgrade-version-command.module.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { Module } from '@nestjs/common';
22
import { TypeOrmModule } from '@nestjs/typeorm';
33

4+
import { AddEnqueuedStatusToWorkflowRunCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-add-enqueued-status-to-workflow-run.command';
45
import { FixSchemaArrayTypeCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-fix-schema-array-type.command';
56
import { FixUpdateStandardFieldsIsLabelSyncedWithName } from 'src/database/commands/upgrade-version-command/1-1/1-1-fix-update-standard-field-is-label-synced-with-name.command';
7+
import { MigrateApiKeysWebhooksToCoreCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-migrate-api-keys-webhooks-to-core.command';
8+
import { MigrateWorkflowRunStatesCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-migrate-workflow-run-state.command';
69
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
10+
import { ApiKey } from 'src/engine/core-modules/api-key/api-key.entity';
11+
import { ApiKeyModule } from 'src/engine/core-modules/api-key/api-key.module';
712
import { AppToken } from 'src/engine/core-modules/app-token/app-token.entity';
813
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
914
import { User } from 'src/engine/core-modules/user/user.entity';
15+
import { Webhook } from 'src/engine/core-modules/webhook/webhook.entity';
16+
import { WebhookModule } from 'src/engine/core-modules/webhook/webhook.module';
1017
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
1118
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
1219
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
1320
import { WorkspaceMetadataVersionModule } from 'src/engine/metadata-modules/workspace-metadata-version/workspace-metadata-version.module';
1421
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
1522
import { WorkspaceHealthModule } from 'src/engine/workspace-manager/workspace-health/workspace-health.module';
1623
import { WorkspaceMigrationRunnerModule } from 'src/engine/workspace-manager/workspace-migration-runner/workspace-migration-runner.module';
17-
import { MigrateWorkflowRunStatesCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-migrate-workflow-run-state.command';
1824

1925
@Module({
2026
imports: [
@@ -26,6 +32,8 @@ import { MigrateWorkflowRunStatesCommand } from 'src/database/commands/upgrade-v
2632
UserWorkspace,
2733
FieldMetadataEntity,
2834
ObjectMetadataEntity,
35+
ApiKey,
36+
Webhook,
2937
],
3038
'core',
3139
),
@@ -34,16 +42,22 @@ import { MigrateWorkflowRunStatesCommand } from 'src/database/commands/upgrade-v
3442
WorkspaceMetadataVersionModule,
3543
WorkspaceHealthModule,
3644
TypeORMModule,
45+
ApiKeyModule,
46+
WebhookModule,
3747
],
3848
providers: [
3949
FixUpdateStandardFieldsIsLabelSyncedWithName,
4050
FixSchemaArrayTypeCommand,
4151
MigrateWorkflowRunStatesCommand,
52+
MigrateApiKeysWebhooksToCoreCommand,
53+
AddEnqueuedStatusToWorkflowRunCommand,
4254
],
4355
exports: [
4456
FixUpdateStandardFieldsIsLabelSyncedWithName,
4557
FixSchemaArrayTypeCommand,
4658
MigrateWorkflowRunStatesCommand,
59+
MigrateApiKeysWebhooksToCoreCommand,
60+
AddEnqueuedStatusToWorkflowRunCommand,
4761
],
4862
})
4963
export class V1_1_UpgradeVersionCommandModule {}
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import { Module } from '@nestjs/common';
2-
import { TypeOrmModule } from '@nestjs/typeorm';
3-
4-
import { AddEnqueuedStatusToWorkflowRunCommand } from 'src/database/commands/upgrade-version-command/1-2/1-2-add-enqueued-status-to-workflow-run.command';
5-
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
6-
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
7-
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
82

93
@Module({
10-
imports: [
11-
TypeOrmModule.forFeature([Workspace, FieldMetadataEntity], 'core'),
12-
WorkspaceDataSourceModule,
13-
],
14-
providers: [AddEnqueuedStatusToWorkflowRunCommand],
15-
exports: [AddEnqueuedStatusToWorkflowRunCommand],
4+
imports: [],
5+
providers: [],
6+
exports: [],
167
})
178
export class V1_2_UpgradeVersionCommandModule {}
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
import { Module } from '@nestjs/common';
2-
import { TypeOrmModule } from '@nestjs/typeorm';
3-
4-
import { MigrateApiKeysWebhooksToCoreCommand } from 'src/database/commands/upgrade-version-command/1-3/1-3-migrate-api-keys-webhooks-to-core.command';
5-
import { ApiKey } from 'src/engine/core-modules/api-key/api-key.entity';
6-
import { ApiKeyModule } from 'src/engine/core-modules/api-key/api-key.module';
7-
import { Webhook } from 'src/engine/core-modules/webhook/webhook.entity';
8-
import { WebhookModule } from 'src/engine/core-modules/webhook/webhook.module';
9-
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
10-
import { WorkspaceDataSourceModule } from 'src/engine/workspace-datasource/workspace-datasource.module';
112

123
@Module({
13-
imports: [
14-
TypeOrmModule.forFeature([Workspace, ApiKey, Webhook], 'core'),
15-
WorkspaceDataSourceModule,
16-
ApiKeyModule,
17-
WebhookModule,
18-
],
19-
providers: [MigrateApiKeysWebhooksToCoreCommand],
20-
exports: [MigrateApiKeysWebhooksToCoreCommand],
4+
imports: [],
5+
providers: [],
6+
exports: [],
217
})
228
export class V1_3_UpgradeVersionCommandModule {}

packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import { FixStandardSelectFieldsPositionCommand } from 'src/database/commands/up
2121
import { LowercaseUserAndInvitationEmailsCommand } from 'src/database/commands/upgrade-version-command/0-54/0-54-lowercase-user-and-invitation-emails.command';
2222
import { MigrateDefaultAvatarUrlToUserWorkspaceCommand } from 'src/database/commands/upgrade-version-command/0-54/0-54-migrate-default-avatar-url-to-user-workspace.command';
2323
import { DeduplicateIndexedFieldsCommand } from 'src/database/commands/upgrade-version-command/0-55/0-55-deduplicate-indexed-fields.command';
24+
import { AddEnqueuedStatusToWorkflowRunCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-add-enqueued-status-to-workflow-run.command';
2425
import { FixSchemaArrayTypeCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-fix-schema-array-type.command';
2526
import { FixUpdateStandardFieldsIsLabelSyncedWithName } from 'src/database/commands/upgrade-version-command/1-1/1-1-fix-update-standard-field-is-label-synced-with-name.command';
26-
import { AddEnqueuedStatusToWorkflowRunCommand } from 'src/database/commands/upgrade-version-command/1-2/1-2-add-enqueued-status-to-workflow-run.command';
27-
import { MigrateApiKeysWebhooksToCoreCommand } from 'src/database/commands/upgrade-version-command/1-3/1-3-migrate-api-keys-webhooks-to-core.command';
27+
import { MigrateApiKeysWebhooksToCoreCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-migrate-api-keys-webhooks-to-core.command';
28+
import { MigrateWorkflowRunStatesCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-migrate-workflow-run-state.command';
2829
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
2930
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
3031
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
3132
import { SyncWorkspaceMetadataCommand } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command';
3233
import { compareVersionMajorAndMinor } from 'src/utils/version/compare-version-minor-and-major';
33-
import { MigrateWorkflowRunStatesCommand } from 'src/database/commands/upgrade-version-command/1-1/1-1-migrate-workflow-run-state.command';
3434

3535
const execPromise = promisify(exec);
3636

@@ -144,13 +144,13 @@ export class UpgradeCommand extends UpgradeCommandRunner {
144144
// 1.1 Commands
145145
protected readonly fixSchemaArrayTypeCommand: FixSchemaArrayTypeCommand,
146146
protected readonly fixUpdateStandardFieldsIsLabelSyncedWithNameCommand: FixUpdateStandardFieldsIsLabelSyncedWithName,
147-
148-
// 1.2 Commands
147+
protected readonly migrateApiKeysWebhooksToCoreCommand: MigrateApiKeysWebhooksToCoreCommand,
149148
protected readonly migrateWorkflowRunStatesCommand: MigrateWorkflowRunStatesCommand,
150149
protected readonly addEnqueuedStatusToWorkflowRunCommand: AddEnqueuedStatusToWorkflowRunCommand,
151150

151+
// 1.2 Commands
152+
152153
// 1.3 Commands
153-
protected readonly migrateApiKeysWebhooksToCoreCommand: MigrateApiKeysWebhooksToCoreCommand,
154154
) {
155155
super(
156156
workspaceRepository,
@@ -195,17 +195,19 @@ export class UpgradeCommand extends UpgradeCommandRunner {
195195
beforeSyncMetadata: [
196196
this.fixUpdateStandardFieldsIsLabelSyncedWithNameCommand,
197197
this.fixSchemaArrayTypeCommand,
198+
this.migrateApiKeysWebhooksToCoreCommand,
199+
this.addEnqueuedStatusToWorkflowRunCommand,
198200
],
199-
afterSyncMetadata: [],
201+
afterSyncMetadata: [this.migrateWorkflowRunStatesCommand],
200202
};
201203

202204
const commands_120: VersionCommands = {
203-
beforeSyncMetadata: [this.addEnqueuedStatusToWorkflowRunCommand],
204-
afterSyncMetadata: [this.migrateWorkflowRunStatesCommand],
205+
beforeSyncMetadata: [],
206+
afterSyncMetadata: [],
205207
};
206208

207209
const commands_130: VersionCommands = {
208-
beforeSyncMetadata: [this.migrateApiKeysWebhooksToCoreCommand],
210+
beforeSyncMetadata: [],
209211
afterSyncMetadata: [],
210212
};
211213

0 commit comments

Comments
 (0)