Skip to content

Commit

Permalink
Update migration command
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed Oct 29, 2024
1 parent a7a53a9 commit 318c6ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { InjectRepository } from '@nestjs/typeorm';

import { Command } from 'nest-commander';
import { Repository } from 'typeorm';
import { ObjectLiteral, Repository } from 'typeorm';
import chalk from 'chalk';

import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { BaseCommandOptions } from 'src/database/commands/base.command';
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';

@Command({
name: 'upgrade-0.32:copy-webhook-operation-into-operations',
Expand Down Expand Up @@ -43,11 +44,21 @@ export class CopyWebhookOperationIntoOperationsCommand extends ActiveWorkspacesC

for (const webhook of webhooks) {
if ('operation' in webhook) {
let newOperation = webhook.operation;

const [firstWebhookPart, lastWebhookPart] = newOperation.split('.');

if (['created', 'updated', 'deleted'].includes(firstWebhookPart)) {
newOperation = `${lastWebhookPart}.${firstWebhookPart}`;
}

await webhookRepository.update(webhook.id, {
operations: [webhook.operation],
operation: newOperation,
operations: [newOperation],
});

this.logger.log(
chalk.yellow(`Copied webhook operation to operations`),
chalk.yellow(`Handled webhook operation updates for ${webhook.id}`),
);
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/twenty-zapier/src/utils/triggers/triggers.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const subscribe = async (
);
return result.data.createWebhook;
} catch (e) {
// Remove that catch code when operations column exists in all active workspace schemas
// Remove that catch code when VERSION 0.32 is deployed
// probably removable after 01/11/2024
// (ie: when operations column exists in all active workspace schemas)
const data = {
targetUrl: bundle.targetUrl,
operation: `${bundle.inputData.nameSingular}.${operation}`,
Expand Down

0 comments on commit 318c6ed

Please sign in to comment.