Implement cross version upgrade (#19559)
# Introduction Refactoring the upgrade engine to handle cross version upgrade, completely getting rid of the semver `version` at db and runtime level It remains a visual a listing indicator for or CD process but also during devenv in order to prepare next release Will write a release process runbook documentation on how to handle upgrade step patch, command insertion etc as it needs to be cascaded across all the involved supported version **The upgrade sequence model:** The sequence is a flat, ordered array of upgrade steps (`UpgradeStep[]`), built from the registry by chaining all versions in order, each version contributing its fast-instance → slow-instance → workspace commands sorted by timestamp. Version is metadata for logging, not used in the algorithm. **Segments:** The sequence naturally splits into alternating segments of contiguous instance steps and contiguous workspace steps. The runner processes segments in order: - **Instance segment:** Run sequentially from the instance cursor. Each step runs once globally. - **Workspace segment:** Each workspace independently walks from its own cursor through the end of the segment. Workspaces are independent within a segment — they can be at different positions. - **Synchronization (workspace → instance):** The runner blocks before entering an instance segment. All active/suspended workspaces must have completed the last workspace step of the preceding workspace segment. If any workspace failed, abort. This is the only explicit synchronization point. - Instance → workspace ordering is implicit — the runner processes segments sequentially, so the instance segment naturally completes before the workspace segment begins. full docs https://gist.github.com/prastoin/e62106d455fd72d6b6ebada8351e5492 ## Version constants & type-level deprecation Version management is split into three atomic constants: `TWENTY_PREVIOUS_VERSIONS`, `TWENTY_CURRENT_VERSION`, and `TWENTY_NEXT_VERSIONS`. Two derived constants compose them: `CROSS_UPGRADE_SUPPORTED_VERSIONS` (previous + current — what the engine runs) and `ALL_TWENTY_VERSIONS` (the full ordered tuple including next). The registry service validates at module init that no version is duplicated across constants and that at least one previous version exists. A `DeprecatedSinceVersion<RemoveAtVersion, T>` type utility resolves to `T` while `TWENTY_CURRENT_VERSION` is below `RemoveAtVersion`, and to `never` once it reaches it — turning deprecation into a compile-time guarantee via `IndexOf` and `IsGreaterOrEqual` generics in `twenty-shared`. ### `workspace.version` column deprecation The column is replaced by cursor-based state inference from `UpgradeMigration` records, but cannot be dropped in 1.22: workspaces activated during 1.21 predate the cursor system and need their initial cursor backfilled first (`backfillWorkspaceCreatedIn1_21_0Cursors`). This backfill itself depends on a new `isInitial` column on `UpgradeMigration`, bootstrapped via a targeted TypeORM migration before the upgrade sequence runs. Both functions and the entity field are typed with `DeprecatedSinceVersion<'1.23.0', ...>`. When `TWENTY_CURRENT_VERSION` reaches `1.23.0`, compile errors force their removal — and the pre-declared `DropWorkspaceVersionColumnFastInstanceCommand` takes over to drop the column. ## What's next - ci cross version upgrade ( wip ) - banner asking to contact twenty administrator if workspace is outdated - upgrade healthcheck cli ## New unit/integ test pattern Create a dedicated `createNestApp` that consumes a real database in order not to have to mack any database interaction to the `upgradeMigrations` allowing full coverage of the whole `upgradeRunnerService.run` core logic
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
import { TWENTY_CURRENT_VERSION } from 'src/engine/core-modules/upgrade/constants/twenty-current-version.constant';
|
||||
import { TWENTY_NEXT_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-next-versions.constant';
|
||||
import { TWENTY_PREVIOUS_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-previous-versions.constant';
|
||||
|
||||
export const TWENTY_ALL_VERSIONS = [
|
||||
...TWENTY_PREVIOUS_VERSIONS,
|
||||
TWENTY_CURRENT_VERSION,
|
||||
...TWENTY_NEXT_VERSIONS,
|
||||
] as const;
|
||||
|
||||
export type TwentyAllVersion = (typeof TWENTY_ALL_VERSIONS)[number];
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { TWENTY_CURRENT_VERSION } from 'src/engine/core-modules/upgrade/constants/twenty-current-version.constant';
|
||||
import { TWENTY_PREVIOUS_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-previous-versions.constant';
|
||||
|
||||
export const TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS = [
|
||||
...TWENTY_PREVIOUS_VERSIONS,
|
||||
TWENTY_CURRENT_VERSION,
|
||||
] as const;
|
||||
|
||||
export type TwentyCrossUpgradeSupportedVersion =
|
||||
(typeof TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS)[number];
|
||||
+1
@@ -0,0 +1 @@
|
||||
export const TWENTY_CURRENT_VERSION = '1.22.0' as const;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export const TWENTY_NEXT_VERSIONS = ['1.23.0'] as const;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export const TWENTY_PREVIOUS_VERSIONS = ['1.20.0', '1.21.0'] as const;
|
||||
+4
-4
@@ -2,24 +2,24 @@ import 'reflect-metadata';
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { type UpgradeCommandVersion } from 'src/engine/constants/upgrade-command-supported-versions.constant';
|
||||
import { type TwentyAllVersion } from 'src/engine/core-modules/upgrade/constants/twenty-all-versions.constant';
|
||||
|
||||
export type InstanceCommandType = 'fast' | 'slow';
|
||||
|
||||
export type RegisteredInstanceCommandMetadata = {
|
||||
version: UpgradeCommandVersion;
|
||||
version: TwentyAllVersion;
|
||||
timestamp: number;
|
||||
type: InstanceCommandType;
|
||||
};
|
||||
|
||||
const REGISTERED_INSTANCE_COMMAND_KEY = 'REGISTERED_INSTANCE_COMMAND';
|
||||
|
||||
// When dropping a version from UPGRADE_COMMAND_SUPPORTED_VERSIONS, also
|
||||
// When dropping a version from TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS, also
|
||||
// remove the @RegisteredInstanceCommand decorator from its associated
|
||||
// command files.
|
||||
export const RegisteredInstanceCommand =
|
||||
(
|
||||
version: UpgradeCommandVersion,
|
||||
version: TwentyAllVersion,
|
||||
timestamp: number,
|
||||
options?: { type: 'slow' },
|
||||
): ClassDecorator =>
|
||||
|
||||
+6
-3
@@ -1,16 +1,19 @@
|
||||
import 'reflect-metadata';
|
||||
|
||||
import { type UpgradeCommandVersion } from 'src/engine/constants/upgrade-command-supported-versions.constant';
|
||||
import { type TwentyCrossUpgradeSupportedVersion } from 'src/engine/core-modules/upgrade/constants/twenty-cross-upgrade-supported-version.constant';
|
||||
|
||||
export type RegisteredWorkspaceCommandMetadata = {
|
||||
version: UpgradeCommandVersion;
|
||||
version: TwentyCrossUpgradeSupportedVersion;
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
const REGISTERED_WORKSPACE_COMMAND_KEY = 'REGISTERED_WORKSPACE_COMMAND';
|
||||
|
||||
export const RegisteredWorkspaceCommand =
|
||||
(version: UpgradeCommandVersion, timestamp: number): ClassDecorator =>
|
||||
(
|
||||
version: TwentyCrossUpgradeSupportedVersion,
|
||||
timestamp: number,
|
||||
): ClassDecorator =>
|
||||
(target) => {
|
||||
Reflect.defineMetadata(
|
||||
REGISTERED_WORKSPACE_COMMAND_KEY,
|
||||
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
import {
|
||||
type UpgradeStep,
|
||||
type WorkspaceUpgradeStep,
|
||||
} from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import {
|
||||
type IntegrationTestContext,
|
||||
createUpgradeSequenceRunnerIntegrationTestModule,
|
||||
DEFAULT_OPTIONS,
|
||||
makeFastInstance,
|
||||
makeSlowInstance,
|
||||
makeStep,
|
||||
makeWorkspace,
|
||||
resetSeedSequenceCounter,
|
||||
seedMigration,
|
||||
setMockActiveWorkspaceIds,
|
||||
testGetLatestMigrationForCommand,
|
||||
WS_1,
|
||||
WS_2,
|
||||
} from './utils/upgrade-sequence-runner-integration-test.util';
|
||||
|
||||
const makeFailingFastInstance = (name: string, error: Error): UpgradeStep =>
|
||||
({
|
||||
...makeStep('fast-instance', name),
|
||||
command: {
|
||||
up: async () => {
|
||||
throw error;
|
||||
},
|
||||
down: async () => {},
|
||||
},
|
||||
}) as unknown as UpgradeStep;
|
||||
|
||||
const makeFailingWorkspace = (
|
||||
name: string,
|
||||
error: Error,
|
||||
): WorkspaceUpgradeStep =>
|
||||
({
|
||||
...makeStep('workspace', name),
|
||||
command: {
|
||||
runOnWorkspace: async () => {
|
||||
throw error;
|
||||
},
|
||||
},
|
||||
}) as unknown as WorkspaceUpgradeStep;
|
||||
|
||||
const makeWorkspaceFailingForIds = (
|
||||
name: string,
|
||||
failingWorkspaceIds: Set<string>,
|
||||
error: Error,
|
||||
): WorkspaceUpgradeStep =>
|
||||
({
|
||||
...makeStep('workspace', name),
|
||||
command: {
|
||||
runOnWorkspace: async ({ workspaceId }: { workspaceId: string }) => {
|
||||
if (failingWorkspaceIds.has(workspaceId)) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
},
|
||||
}) as unknown as WorkspaceUpgradeStep;
|
||||
|
||||
describe('UpgradeSequenceRunnerService — failing sequence (integration)', () => {
|
||||
let context: IntegrationTestContext;
|
||||
|
||||
beforeAll(async () => {
|
||||
context = await createUpgradeSequenceRunnerIntegrationTestModule();
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await context.dataSource.query('DELETE FROM core."upgradeMigration"');
|
||||
await context.module?.close();
|
||||
await context.dataSource?.destroy();
|
||||
}, 15000);
|
||||
|
||||
beforeEach(async () => {
|
||||
await context.dataSource.query('DELETE FROM core."upgradeMigration"');
|
||||
resetSeedSequenceCounter();
|
||||
setMockActiveWorkspaceIds([]);
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should throw when no migration history exists', async () => {
|
||||
const sequence = [makeFastInstance('Ic1')];
|
||||
|
||||
await expect(
|
||||
context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
}),
|
||||
).rejects.toThrow(
|
||||
'No upgrade migration found — the database may not have been initialized',
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw when cursor command is not found in the sequence', async () => {
|
||||
const sequence = [makeFastInstance('Ic1'), makeFastInstance('Ic2')];
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'RemovedCommand',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
await expect(
|
||||
context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
}),
|
||||
).rejects.toThrow('Step "RemovedCommand" not found in upgrade sequence');
|
||||
});
|
||||
|
||||
it('should throw when workspace cursors are outside the current slice', async () => {
|
||||
const sequence = [
|
||||
makeWorkspace('Wc1'),
|
||||
makeWorkspace('Wc2'),
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc3'),
|
||||
makeWorkspace('Wc4'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1, WS_2]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc3',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc4',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
await expect(
|
||||
context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
}),
|
||||
).rejects.toThrow('workspaces are not aligned');
|
||||
});
|
||||
|
||||
it('should throw when an active workspace has no migration history', async () => {
|
||||
const sequence = [makeFastInstance('Ic1'), makeWorkspace('Wc1')];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1, WS_2]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
await expect(
|
||||
context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
}),
|
||||
).rejects.toThrow('No upgrade migration found for workspace(s)');
|
||||
});
|
||||
|
||||
it('should record failure in DB when a fast instance command fails', async () => {
|
||||
const error = new Error('fast command exploded');
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeFailingFastInstance('Ic2', error),
|
||||
];
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
await expect(
|
||||
context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
}),
|
||||
).rejects.toThrow('fast command exploded');
|
||||
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ name: 'Ic2', status: 'failed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should record failure in DB when a slow instance command fails', async () => {
|
||||
const error = new Error('slow data migration exploded');
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
{
|
||||
...makeSlowInstance('Ic2'),
|
||||
command: {
|
||||
up: async () => {},
|
||||
down: async () => {},
|
||||
runDataMigration: async () => {
|
||||
throw error;
|
||||
},
|
||||
},
|
||||
} as unknown as UpgradeStep,
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
await expect(
|
||||
context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
}),
|
||||
).rejects.toThrow('slow data migration exploded');
|
||||
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ name: 'Ic2', status: 'failed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should abort and report failures when workspace commands fail, without running subsequent instance steps', async () => {
|
||||
const error = new Error('workspace command exploded');
|
||||
const sequence = [
|
||||
makeFailingWorkspace('Wc1', error),
|
||||
makeFastInstance('Ic1'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'failed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
const report = await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(report.totalFailures).toBe(1);
|
||||
expect(report.totalSuccesses).toBe(0);
|
||||
|
||||
const ic1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
});
|
||||
|
||||
expect(ic1).toBeNull();
|
||||
|
||||
const wc1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(wc1).toEqual(
|
||||
expect.objectContaining({ status: 'failed', attempt: 2 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should abort at workspace failure in a multi-segment sequence with two workspaces starting aligned', async () => {
|
||||
const error = new Error('Wc2 exploded for WS_2');
|
||||
|
||||
const sequence = [
|
||||
makeWorkspace('Wc0'),
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc1'),
|
||||
makeWorkspaceFailingForIds('Wc2', new Set([WS_2]), error),
|
||||
makeFastInstance('Ic2'),
|
||||
makeWorkspace('Wc3'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1, WS_2]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc0',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc0',
|
||||
status: 'completed',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
|
||||
const report = await context.runner.run({
|
||||
sequence,
|
||||
options: {
|
||||
...DEFAULT_OPTIONS,
|
||||
workspaceIds: [WS_1, WS_2],
|
||||
},
|
||||
});
|
||||
|
||||
expect(report.totalSuccesses).toBe(1);
|
||||
expect(report.totalFailures).toBe(1);
|
||||
|
||||
// WS_1 succeeded Wc2
|
||||
const ws1Wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(ws1Wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
|
||||
// WS_2 failed Wc2
|
||||
const ws2Wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
|
||||
expect(ws2Wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'failed' }),
|
||||
);
|
||||
|
||||
// Ic2 never ran — runner aborted at the workspace segment failure
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
|
||||
expect(ic2).toBeNull();
|
||||
|
||||
// Wc3 never ran either
|
||||
const ws1Wc3 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc3',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(ws1Wc3).toBeNull();
|
||||
});
|
||||
});
|
||||
+466
@@ -0,0 +1,466 @@
|
||||
import { InstanceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/instance-command-runner.service';
|
||||
|
||||
import {
|
||||
type IntegrationTestContext,
|
||||
createUpgradeSequenceRunnerIntegrationTestModule,
|
||||
DEFAULT_OPTIONS,
|
||||
makeFastInstance,
|
||||
makeSlowInstance,
|
||||
makeWorkspace,
|
||||
resetSeedSequenceCounter,
|
||||
seedMigration,
|
||||
setMockActiveWorkspaceIds,
|
||||
testGetLatestMigrationForCommand,
|
||||
WS_1,
|
||||
WS_2,
|
||||
} from './utils/upgrade-sequence-runner-integration-test.util';
|
||||
|
||||
describe('UpgradeSequenceRunnerService — execution (integration)', () => {
|
||||
let context: IntegrationTestContext;
|
||||
|
||||
beforeAll(async () => {
|
||||
context = await createUpgradeSequenceRunnerIntegrationTestModule();
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
await context.dataSource.query('DELETE FROM core."upgradeMigration"');
|
||||
await context.module?.close();
|
||||
await context.dataSource?.destroy();
|
||||
}, 15000);
|
||||
|
||||
beforeEach(async () => {
|
||||
await context.dataSource.query('DELETE FROM core."upgradeMigration"');
|
||||
resetSeedSequenceCounter();
|
||||
setMockActiveWorkspaceIds([]);
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should return zero counts for an empty sequence', async () => {
|
||||
const report = await context.runner.run({
|
||||
sequence: [],
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(report).toEqual({ totalSuccesses: 0, totalFailures: 0 });
|
||||
});
|
||||
|
||||
it('should resume from a completed instance command and run remaining steps', async () => {
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeFastInstance('Ic2'),
|
||||
makeSlowInstance('Ic3'),
|
||||
];
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
const ic1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
});
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
const ic3 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic3',
|
||||
});
|
||||
|
||||
expect(ic1).toEqual(
|
||||
expect.objectContaining({ status: 'completed', attempt: 1 }),
|
||||
);
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ status: 'completed', attempt: 1 }),
|
||||
);
|
||||
expect(ic3).toEqual(expect.objectContaining({ status: 'completed' }));
|
||||
});
|
||||
|
||||
it('should retry a failed instance command', async () => {
|
||||
const sequence = [makeFastInstance('Ic1'), makeFastInstance('Ic2')];
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
status: 'failed',
|
||||
});
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ name: 'Ic2', status: 'completed', attempt: 2 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should resume workspace commands from per-workspace cursors', async () => {
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc1'),
|
||||
makeWorkspace('Wc2'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
const wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should enforce workspace sync barrier before instance step', async () => {
|
||||
const sequence = [makeWorkspace('Wc1'), makeFastInstance('Ic1')];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
const ic1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
});
|
||||
|
||||
expect(ic1).toEqual(
|
||||
expect.objectContaining({ name: 'Ic1', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should skip data migration for slow instance commands when no workspaces exist', async () => {
|
||||
const sequence = [makeFastInstance('Ic1'), makeSlowInstance('Ic2')];
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
const instanceCommandRunnerService = context.module.get(
|
||||
InstanceCommandRunnerService,
|
||||
);
|
||||
const spy = jest.spyOn(
|
||||
instanceCommandRunnerService,
|
||||
'runSlowInstanceCommand',
|
||||
);
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ skipDataMigration: true }),
|
||||
);
|
||||
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ name: 'Ic2', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should run data migration for slow instance commands when workspaces exist', async () => {
|
||||
const sequence = [makeFastInstance('Ic0'), makeSlowInstance('Ic1')];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic0',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
const instanceCommandRunnerService = context.module.get(
|
||||
InstanceCommandRunnerService,
|
||||
);
|
||||
const spy = jest.spyOn(
|
||||
instanceCommandRunnerService,
|
||||
'runSlowInstanceCommand',
|
||||
);
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ skipDataMigration: false }),
|
||||
);
|
||||
|
||||
const ic1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
});
|
||||
|
||||
expect(ic1).toEqual(
|
||||
expect.objectContaining({ name: 'Ic1', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should run workspace commands for multiple workspaces successfully', async () => {
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc1'),
|
||||
makeWorkspace('Wc2'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1, WS_2]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
|
||||
const report = await context.runner.run({
|
||||
sequence,
|
||||
options: {
|
||||
...DEFAULT_OPTIONS,
|
||||
workspaceIds: [WS_1, WS_2],
|
||||
},
|
||||
});
|
||||
|
||||
expect(report).toEqual({ totalSuccesses: 2, totalFailures: 0 });
|
||||
|
||||
const ws1Wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
const ws2Wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
|
||||
expect(ws1Wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
expect(ws2Wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should execute the full sequence from the initial cursor on a fresh run', async () => {
|
||||
const sequence = [
|
||||
makeWorkspace('Wc0'),
|
||||
makeFastInstance('Ic1'),
|
||||
makeFastInstance('Ic2'),
|
||||
makeWorkspace('Wc1'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc0',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
|
||||
await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
const wc1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ name: 'Ic2', status: 'completed' }),
|
||||
);
|
||||
expect(wc1).toEqual(
|
||||
expect.objectContaining({ name: 'Wc1', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should retry a failed workspace command', async () => {
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc1'),
|
||||
makeWorkspace('Wc2'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'failed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
const report = await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(report.totalFailures).toBe(0);
|
||||
|
||||
const wc1 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
const wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(wc1).toEqual(
|
||||
expect.objectContaining({
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
attempt: 2,
|
||||
}),
|
||||
);
|
||||
expect(wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should traverse a multi-segment sequence with sync barriers', async () => {
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc1'),
|
||||
makeFastInstance('Ic2'),
|
||||
makeWorkspace('Wc2'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
const report = await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(report.totalFailures).toBe(0);
|
||||
|
||||
const ic2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Ic2',
|
||||
});
|
||||
const wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(ic2).toEqual(
|
||||
expect.objectContaining({ name: 'Ic2', status: 'completed' }),
|
||||
);
|
||||
expect(wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore migration records from inactive workspaces when resolving the global cursor', async () => {
|
||||
const sequence = [
|
||||
makeFastInstance('Ic1'),
|
||||
makeWorkspace('Wc1'),
|
||||
makeWorkspace('Wc2'),
|
||||
];
|
||||
|
||||
setMockActiveWorkspaceIds([WS_1]);
|
||||
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Ic1',
|
||||
status: 'completed',
|
||||
});
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc1',
|
||||
status: 'completed',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
// WS_2 is inactive — its record is more recent (seeded later)
|
||||
// but should not influence the global cursor
|
||||
await seedMigration(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
status: 'completed',
|
||||
workspaceId: WS_2,
|
||||
});
|
||||
|
||||
const report = await context.runner.run({
|
||||
sequence,
|
||||
options: DEFAULT_OPTIONS,
|
||||
});
|
||||
|
||||
expect(report.totalFailures).toBe(0);
|
||||
|
||||
const wc2 = await testGetLatestMigrationForCommand(context.dataSource, {
|
||||
name: 'Wc2',
|
||||
workspaceId: WS_1,
|
||||
});
|
||||
|
||||
expect(wc2).toEqual(
|
||||
expect.objectContaining({ name: 'Wc2', status: 'completed' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
+19
-4
@@ -95,6 +95,7 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
new MigrationA1770000000000(),
|
||||
new MigrationB1771000000000(),
|
||||
new MigrationC1772000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const v120 = service.getBundleForVersion('1.20.0');
|
||||
@@ -118,6 +119,7 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
new MigrationC1772000000000(),
|
||||
new MigrationA1770000000000(),
|
||||
new MigrationB1771000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const names = service
|
||||
@@ -135,6 +137,7 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
const service = await buildRegistryService([
|
||||
new UndecoratedMigration1768000000000(),
|
||||
new MigrationA1770000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const v121 = service.getBundleForVersion('1.21.0');
|
||||
@@ -157,6 +160,10 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
expect(v121.workspaceCommands).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it('should not throw when no commands are discovered (empty bundle)', async () => {
|
||||
await expect(buildRegistryService([])).resolves.toBeDefined();
|
||||
});
|
||||
|
||||
it('should return empty array for unsupported version', async () => {
|
||||
const service = await buildRegistryService([]);
|
||||
|
||||
@@ -255,9 +262,10 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
new MigrationD1769000000000(),
|
||||
new MigrationA1770000000000(),
|
||||
new MigrationB1771000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const allCommands = service.getAllFastInstanceCommands();
|
||||
const allCommands = service.getCrossUpgradeSupportedFastInstanceCommands();
|
||||
|
||||
expect(allCommands.map((entry) => entry.name)).toStrictEqual([
|
||||
'1.20.0_MigrationD1769000000000_1769000000000',
|
||||
@@ -267,10 +275,12 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return empty array from getAllFastInstanceCommands when no commands registered', async () => {
|
||||
it('should return empty array from getCrossUpgradeSupportedFastInstanceCommands when no commands registered', async () => {
|
||||
const service = await buildRegistryService([]);
|
||||
|
||||
expect(service.getAllFastInstanceCommands()).toStrictEqual([]);
|
||||
expect(
|
||||
service.getCrossUpgradeSupportedFastInstanceCommands(),
|
||||
).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it('should allow same class name with different timestamps across kinds', async () => {
|
||||
@@ -316,6 +326,7 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
const service = await buildRegistryService([
|
||||
new SlowMigrationB1780000000000(),
|
||||
new SlowMigrationA1779000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const { slowInstanceCommands } = service.getBundleForVersion('1.21.0');
|
||||
@@ -341,6 +352,7 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
const service = await buildRegistryService([
|
||||
new MigrationA1770000000000(),
|
||||
new SlowMigration1780000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const bucket = service.getBundleForVersion('1.21.0');
|
||||
@@ -391,6 +403,7 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
const service = await buildRegistryService([
|
||||
new MigrationA1770000000000(),
|
||||
new SlowMigrationSameTimestamp(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const bucket = service.getBundleForVersion('1.21.0');
|
||||
@@ -421,9 +434,11 @@ describe('UpgradeCommandRegistryService', () => {
|
||||
const service = await buildRegistryService([
|
||||
new SlowMigration1780000000000(),
|
||||
new SlowMigration1768000000000(),
|
||||
new WorkspaceCommandA(),
|
||||
]);
|
||||
|
||||
const allSlowCommands = service.getAllSlowInstanceCommands();
|
||||
const allSlowCommands =
|
||||
service.getCrossUpgradeSupportedSlowInstanceCommands();
|
||||
|
||||
expect(allSlowCommands.map((entry) => entry.name)).toStrictEqual([
|
||||
'1.20.0_SlowMigration1768000000000_1768000000000',
|
||||
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
import { Test, type TestingModule } from '@nestjs/testing';
|
||||
import { getDataSourceToken, getRepositoryToken } from '@nestjs/typeorm';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
import { DataSource, type Repository } from 'typeorm';
|
||||
|
||||
import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { InstanceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/instance-command-runner.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
import {
|
||||
UpgradeSequenceReaderService,
|
||||
type UpgradeStep,
|
||||
type WorkspaceUpgradeStep,
|
||||
} from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import { UpgradeSequenceRunnerService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-runner.service';
|
||||
import { WorkspaceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/workspace-command-runner.service';
|
||||
import { UpgradeMigrationEntity } from 'src/engine/core-modules/upgrade/upgrade-migration.entity';
|
||||
import {
|
||||
SEED_APPLE_WORKSPACE_ID,
|
||||
SEED_YCOMBINATOR_WORKSPACE_ID,
|
||||
} from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
|
||||
import { WorkspaceVersionService } from 'src/engine/workspace-manager/workspace-version/services/workspace-version.service';
|
||||
|
||||
jest.useRealTimers();
|
||||
|
||||
config({
|
||||
path: process.env.NODE_ENV === 'test' ? '.env.test' : '.env',
|
||||
override: true,
|
||||
});
|
||||
|
||||
export const WS_1 = SEED_APPLE_WORKSPACE_ID;
|
||||
export const WS_2 = SEED_YCOMBINATOR_WORKSPACE_ID;
|
||||
|
||||
const EXECUTED_BY_VERSION = '42.42.42';
|
||||
|
||||
const noopAsync = async () => {};
|
||||
|
||||
export const makeStep = (
|
||||
kind: UpgradeStep['kind'],
|
||||
name: string,
|
||||
): UpgradeStep => {
|
||||
const command =
|
||||
kind === 'workspace'
|
||||
? { runOnWorkspace: noopAsync }
|
||||
: kind === 'slow-instance'
|
||||
? { up: noopAsync, down: noopAsync, runDataMigration: noopAsync }
|
||||
: { up: noopAsync, down: noopAsync };
|
||||
|
||||
return {
|
||||
kind,
|
||||
name,
|
||||
command,
|
||||
version: '1.21.0',
|
||||
timestamp: 0,
|
||||
} as unknown as UpgradeStep;
|
||||
};
|
||||
|
||||
export const makeFastInstance = (name: string) =>
|
||||
makeStep('fast-instance', name);
|
||||
|
||||
export const makeSlowInstance = (name: string) =>
|
||||
makeStep('slow-instance', name);
|
||||
|
||||
export const makeWorkspace = (name: string) =>
|
||||
makeStep('workspace', name) as WorkspaceUpgradeStep;
|
||||
|
||||
let mockActiveWorkspaceIds: string[] = [];
|
||||
|
||||
export const setMockActiveWorkspaceIds = (ids: string[]) => {
|
||||
mockActiveWorkspaceIds = ids;
|
||||
};
|
||||
|
||||
export const DEFAULT_OPTIONS = {
|
||||
workspaceIds: undefined,
|
||||
startFromWorkspaceId: undefined,
|
||||
workspaceCountLimit: undefined,
|
||||
dryRun: false,
|
||||
verbose: false,
|
||||
};
|
||||
|
||||
type IntegrationTestModule = Awaited<
|
||||
ReturnType<typeof createUpgradeSequenceRunnerIntegrationTestModule>
|
||||
>;
|
||||
|
||||
export type IntegrationTestContext = {
|
||||
[K in keyof IntegrationTestModule]: IntegrationTestModule[K];
|
||||
};
|
||||
|
||||
export const createUpgradeSequenceRunnerIntegrationTestModule = async () => {
|
||||
const dataSource = new DataSource({
|
||||
type: 'postgres',
|
||||
url: process.env.PG_DATABASE_URL,
|
||||
schema: 'core',
|
||||
entities: [
|
||||
'src/engine/core-modules/**/*.entity.ts',
|
||||
'src/engine/metadata-modules/**/*.entity.ts',
|
||||
],
|
||||
synchronize: false,
|
||||
});
|
||||
|
||||
await dataSource.initialize();
|
||||
|
||||
const migrationRepo: Repository<UpgradeMigrationEntity> =
|
||||
dataSource.getRepository(UpgradeMigrationEntity);
|
||||
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
{
|
||||
provide: getRepositoryToken(UpgradeMigrationEntity),
|
||||
useValue: migrationRepo,
|
||||
},
|
||||
{
|
||||
provide: getDataSourceToken(),
|
||||
useValue: dataSource,
|
||||
},
|
||||
{
|
||||
provide: TwentyConfigService,
|
||||
useValue: {
|
||||
get: (key: string) =>
|
||||
key === 'APP_VERSION' ? EXECUTED_BY_VERSION : undefined,
|
||||
},
|
||||
},
|
||||
UpgradeMigrationService,
|
||||
{
|
||||
provide: WorkspaceVersionService,
|
||||
useValue: {
|
||||
getActiveOrSuspendedWorkspaceIds: jest
|
||||
.fn()
|
||||
.mockImplementation(async () => mockActiveWorkspaceIds),
|
||||
hasActiveOrSuspendedWorkspaces: jest
|
||||
.fn()
|
||||
.mockImplementation(async () => mockActiveWorkspaceIds.length > 0),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: UpgradeSequenceReaderService,
|
||||
useFactory: () => new UpgradeSequenceReaderService({} as any),
|
||||
},
|
||||
InstanceCommandRunnerService,
|
||||
WorkspaceCommandRunnerService,
|
||||
{
|
||||
provide: WorkspaceIteratorService,
|
||||
useValue: {
|
||||
iterate: jest.fn().mockImplementation(async (args: any) => {
|
||||
const { callback, workspaceIds } = args;
|
||||
const ids = workspaceIds ?? [WS_1];
|
||||
const report = { fail: [] as any[], success: [] as any[] };
|
||||
|
||||
for (const [index, workspaceId] of ids.entries()) {
|
||||
try {
|
||||
await callback({
|
||||
workspaceId,
|
||||
index,
|
||||
total: ids.length,
|
||||
dataSource,
|
||||
});
|
||||
report.success.push({ workspaceId });
|
||||
} catch (error) {
|
||||
report.fail.push({ error, workspaceId });
|
||||
}
|
||||
}
|
||||
|
||||
return report;
|
||||
}),
|
||||
},
|
||||
},
|
||||
UpgradeSequenceRunnerService,
|
||||
],
|
||||
}).compile();
|
||||
|
||||
const runner = module.get(UpgradeSequenceRunnerService);
|
||||
|
||||
jest.spyOn(runner['logger'], 'log').mockImplementation();
|
||||
jest.spyOn(runner['logger'], 'error').mockImplementation();
|
||||
jest.spyOn(runner['logger'], 'warn').mockImplementation();
|
||||
|
||||
const instanceCommandRunnerService = module.get(InstanceCommandRunnerService);
|
||||
|
||||
jest
|
||||
.spyOn(instanceCommandRunnerService['logger'], 'log')
|
||||
.mockImplementation();
|
||||
jest
|
||||
.spyOn(instanceCommandRunnerService['logger'], 'error')
|
||||
.mockImplementation();
|
||||
|
||||
const workspaceCommandRunnerService = module.get(
|
||||
WorkspaceCommandRunnerService,
|
||||
);
|
||||
|
||||
jest
|
||||
.spyOn(workspaceCommandRunnerService['logger'], 'log')
|
||||
.mockImplementation();
|
||||
jest
|
||||
.spyOn(workspaceCommandRunnerService['logger'], 'error')
|
||||
.mockImplementation();
|
||||
|
||||
return {
|
||||
module,
|
||||
dataSource,
|
||||
runner,
|
||||
};
|
||||
};
|
||||
|
||||
let seedSequenceCounter = 0;
|
||||
|
||||
export const resetSeedSequenceCounter = () => {
|
||||
seedSequenceCounter = 0;
|
||||
};
|
||||
|
||||
export const seedMigration = async (
|
||||
dataSource: DataSource,
|
||||
{
|
||||
name,
|
||||
status,
|
||||
workspaceId = null,
|
||||
attempt = 1,
|
||||
}: {
|
||||
name: string;
|
||||
status: 'completed' | 'failed';
|
||||
workspaceId?: string | null;
|
||||
attempt?: number;
|
||||
},
|
||||
) => {
|
||||
const createdAt = new Date(
|
||||
Date.now() + seedSequenceCounter * 1000,
|
||||
).toISOString();
|
||||
|
||||
seedSequenceCounter++;
|
||||
|
||||
await dataSource.query(
|
||||
`INSERT INTO core."upgradeMigration" (name, status, attempt, "executedByVersion", "workspaceId", "createdAt")
|
||||
VALUES ($1, $2, $3, $4, $5, $6)`,
|
||||
[name, status, attempt, EXECUTED_BY_VERSION, workspaceId, createdAt],
|
||||
);
|
||||
};
|
||||
|
||||
export const testCountMigrationsForCommand = async (
|
||||
dataSource: DataSource,
|
||||
{
|
||||
name,
|
||||
workspaceId = null,
|
||||
}: {
|
||||
name: string;
|
||||
workspaceId?: string | null;
|
||||
},
|
||||
): Promise<number> => {
|
||||
const rows = await dataSource.query(
|
||||
`SELECT COUNT(*)::int AS count FROM core."upgradeMigration"
|
||||
WHERE name = $1 AND ($2::uuid IS NULL AND "workspaceId" IS NULL OR "workspaceId" = $2)`,
|
||||
[name, workspaceId],
|
||||
);
|
||||
|
||||
return rows[0].count;
|
||||
};
|
||||
|
||||
export const testGetLatestMigrationForCommand = async (
|
||||
dataSource: DataSource,
|
||||
{
|
||||
name,
|
||||
workspaceId = null,
|
||||
}: {
|
||||
name: string;
|
||||
workspaceId?: string | null;
|
||||
},
|
||||
): Promise<{ name: string; status: string; attempt: number } | null> => {
|
||||
const rows = await dataSource.query(
|
||||
`SELECT name, status, attempt FROM core."upgradeMigration"
|
||||
WHERE name = $1 AND ($2::uuid IS NULL AND "workspaceId" IS NULL OR "workspaceId" = $2)
|
||||
ORDER BY attempt DESC LIMIT 1`,
|
||||
[name, workspaceId],
|
||||
);
|
||||
|
||||
return rows.length > 0 ? rows[0] : null;
|
||||
};
|
||||
+2
-2
@@ -14,8 +14,8 @@ type RunSingleMigrationResult =
|
||||
| { status: 'failed'; error: unknown };
|
||||
|
||||
@Injectable()
|
||||
export class InstanceUpgradeService {
|
||||
private readonly logger = new Logger(InstanceUpgradeService.name);
|
||||
export class InstanceCommandRunnerService {
|
||||
private readonly logger = new Logger(InstanceCommandRunnerService.name);
|
||||
|
||||
constructor(
|
||||
@InjectDataSource()
|
||||
+131
-44
@@ -3,14 +3,18 @@ import { DiscoveryService } from '@nestjs/core';
|
||||
|
||||
import { type ActiveOrSuspendedWorkspaceCommandRunner } from 'src/database/commands/command-runners/active-or-suspended-workspace.command-runner';
|
||||
import { type WorkspaceCommandRunner } from 'src/database/commands/command-runners/workspace.command-runner';
|
||||
import {
|
||||
TWENTY_ALL_VERSIONS,
|
||||
type TwentyAllVersion,
|
||||
} from 'src/engine/core-modules/upgrade/constants/twenty-all-versions.constant';
|
||||
import { TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-cross-upgrade-supported-version.constant';
|
||||
import { TWENTY_CURRENT_VERSION } from 'src/engine/core-modules/upgrade/constants/twenty-current-version.constant';
|
||||
import { TWENTY_NEXT_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-next-versions.constant';
|
||||
import { TWENTY_PREVIOUS_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-previous-versions.constant';
|
||||
import { getRegisteredInstanceCommandMetadata } from 'src/engine/core-modules/upgrade/decorators/registered-instance-command.decorator';
|
||||
import { getRegisteredWorkspaceCommandMetadata } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
|
||||
import { type FastInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/fast-instance-command.interface';
|
||||
import { type SlowInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/slow-instance-command.interface';
|
||||
import {
|
||||
UPGRADE_COMMAND_SUPPORTED_VERSIONS,
|
||||
type UpgradeCommandVersion,
|
||||
} from 'src/engine/constants/upgrade-command-supported-versions.constant';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
type WorkspaceCommand =
|
||||
@@ -20,22 +24,25 @@ type WorkspaceCommand =
|
||||
export type RegisteredFastInstanceCommand = {
|
||||
name: string;
|
||||
command: FastInstanceCommand;
|
||||
version: TwentyAllVersion;
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
export type RegisteredSlowInstanceCommand = {
|
||||
name: string;
|
||||
command: SlowInstanceCommand;
|
||||
version: TwentyAllVersion;
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
export type RegisteredWorkspaceCommand = {
|
||||
name: string;
|
||||
command: WorkspaceCommand;
|
||||
version: TwentyAllVersion;
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
export type VersionBundle = {
|
||||
type VersionBundle = {
|
||||
fastInstanceCommands: RegisteredFastInstanceCommand[];
|
||||
slowInstanceCommands: RegisteredSlowInstanceCommand[];
|
||||
workspaceCommands: RegisteredWorkspaceCommand[];
|
||||
@@ -52,14 +59,14 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
private readonly logger = new Logger(UpgradeCommandRegistryService.name);
|
||||
|
||||
private readonly bundlesByVersion = new Map<
|
||||
UpgradeCommandVersion,
|
||||
TwentyAllVersion,
|
||||
VersionBundle
|
||||
>();
|
||||
|
||||
constructor(private readonly discoveryService: DiscoveryService) {}
|
||||
|
||||
onModuleInit(): void {
|
||||
for (const version of UPGRADE_COMMAND_SUPPORTED_VERSIONS) {
|
||||
for (const version of TWENTY_ALL_VERSIONS) {
|
||||
this.bundlesByVersion.set(version, {
|
||||
fastInstanceCommands: [],
|
||||
slowInstanceCommands: [],
|
||||
@@ -84,27 +91,30 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
instanceCommandMetadata.version,
|
||||
);
|
||||
|
||||
if (isDefined(bundle)) {
|
||||
const entry = {
|
||||
name: this.computeCommandName(
|
||||
instanceCommandMetadata.version,
|
||||
(instance as FastInstanceCommand).constructor.name,
|
||||
instanceCommandMetadata.timestamp,
|
||||
),
|
||||
timestamp: instanceCommandMetadata.timestamp,
|
||||
};
|
||||
if (!isDefined(bundle)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (instanceCommandMetadata.type === 'slow') {
|
||||
bundle.slowInstanceCommands.push({
|
||||
...entry,
|
||||
command: instance as SlowInstanceCommand,
|
||||
});
|
||||
} else {
|
||||
bundle.fastInstanceCommands.push({
|
||||
...entry,
|
||||
command: instance as FastInstanceCommand,
|
||||
});
|
||||
}
|
||||
const entry = {
|
||||
name: this.computeCommandName(
|
||||
instanceCommandMetadata.version,
|
||||
(instance as FastInstanceCommand).constructor.name,
|
||||
instanceCommandMetadata.timestamp,
|
||||
),
|
||||
version: instanceCommandMetadata.version,
|
||||
timestamp: instanceCommandMetadata.timestamp,
|
||||
};
|
||||
|
||||
if (instanceCommandMetadata.type === 'slow') {
|
||||
bundle.slowInstanceCommands.push({
|
||||
...entry,
|
||||
command: instance as SlowInstanceCommand,
|
||||
});
|
||||
} else {
|
||||
bundle.fastInstanceCommands.push({
|
||||
...entry,
|
||||
command: instance as FastInstanceCommand,
|
||||
});
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -118,17 +128,20 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
workspaceCommandMetadata.version,
|
||||
);
|
||||
|
||||
if (isDefined(bundle)) {
|
||||
bundle.workspaceCommands.push({
|
||||
name: this.computeCommandName(
|
||||
workspaceCommandMetadata.version,
|
||||
(instance as WorkspaceCommand).constructor.name,
|
||||
workspaceCommandMetadata.timestamp,
|
||||
),
|
||||
command: instance as WorkspaceCommand,
|
||||
timestamp: workspaceCommandMetadata.timestamp,
|
||||
});
|
||||
if (!isDefined(bundle)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bundle.workspaceCommands.push({
|
||||
name: this.computeCommandName(
|
||||
workspaceCommandMetadata.version,
|
||||
(instance as WorkspaceCommand).constructor.name,
|
||||
workspaceCommandMetadata.timestamp,
|
||||
),
|
||||
command: instance as WorkspaceCommand,
|
||||
version: workspaceCommandMetadata.version,
|
||||
timestamp: workspaceCommandMetadata.timestamp,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +157,10 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
);
|
||||
}
|
||||
|
||||
this.validateNoVersionDuplicatesAcrossConstants();
|
||||
this.validatePreviousVersionsNotEmpty();
|
||||
this.validateNoDuplicates();
|
||||
this.validateAtLeastOneVersionBundleHasWorkspaceCommands();
|
||||
|
||||
for (const [version, bundle] of this.bundlesByVersion) {
|
||||
const totalCount =
|
||||
@@ -160,24 +176,32 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
getBundleForVersion(version: UpgradeCommandVersion): VersionBundle {
|
||||
getBundleForVersion(version: TwentyAllVersion): VersionBundle {
|
||||
return this.bundlesByVersion.get(version) ?? buildEmptyVersionBundle();
|
||||
}
|
||||
|
||||
getAllFastInstanceCommands(): RegisteredFastInstanceCommand[] {
|
||||
return UPGRADE_COMMAND_SUPPORTED_VERSIONS.flatMap(
|
||||
getLastWorkspaceCommandForVersion(
|
||||
version: TwentyAllVersion,
|
||||
): RegisteredWorkspaceCommand | undefined {
|
||||
const bundle = this.getBundleForVersion(version);
|
||||
|
||||
return bundle.workspaceCommands[bundle.workspaceCommands.length - 1];
|
||||
}
|
||||
|
||||
getCrossUpgradeSupportedFastInstanceCommands(): RegisteredFastInstanceCommand[] {
|
||||
return TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS.flatMap(
|
||||
(version) => this.getBundleForVersion(version).fastInstanceCommands,
|
||||
);
|
||||
}
|
||||
|
||||
getAllSlowInstanceCommands(): RegisteredSlowInstanceCommand[] {
|
||||
return UPGRADE_COMMAND_SUPPORTED_VERSIONS.flatMap(
|
||||
getCrossUpgradeSupportedSlowInstanceCommands(): RegisteredSlowInstanceCommand[] {
|
||||
return TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS.flatMap(
|
||||
(version) => this.getBundleForVersion(version).slowInstanceCommands,
|
||||
);
|
||||
}
|
||||
|
||||
private computeCommandName(
|
||||
version: UpgradeCommandVersion,
|
||||
version: TwentyAllVersion,
|
||||
className: string,
|
||||
timestamp: number,
|
||||
): string {
|
||||
@@ -222,8 +246,43 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
}
|
||||
}
|
||||
|
||||
private validateAtLeastOneVersionBundleHasWorkspaceCommands(): void {
|
||||
let totalCommandCount = 0;
|
||||
let hasWorkspaceCommands = false;
|
||||
|
||||
for (const version of TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS) {
|
||||
const bundle = this.getBundleForVersion(version);
|
||||
|
||||
totalCommandCount +=
|
||||
bundle.fastInstanceCommands.length +
|
||||
bundle.slowInstanceCommands.length +
|
||||
bundle.workspaceCommands.length;
|
||||
|
||||
if (bundle.workspaceCommands.length > 0) {
|
||||
hasWorkspaceCommands = true;
|
||||
}
|
||||
}
|
||||
|
||||
// UpgradeModule is loaded in the worker transitively via WorkspaceModule,
|
||||
// but no command modules are imported — zero providers are discovered.
|
||||
// TODO: split WorkspaceModule so the worker doesn't pull in UpgradeModule
|
||||
if (totalCommandCount === 0) {
|
||||
this.logger.warn(
|
||||
'No upgrade commands discovered — skipping workspace command validation',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasWorkspaceCommands) {
|
||||
throw new Error(
|
||||
'Upgrade sequence must contain at least one workspace command',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private validateNoTimestampDuplicatesWithinKind(
|
||||
version: UpgradeCommandVersion,
|
||||
version: TwentyAllVersion,
|
||||
kind: 'fast-instance' | 'slow-instance' | 'workspace',
|
||||
entries:
|
||||
| RegisteredFastInstanceCommand[]
|
||||
@@ -242,4 +301,32 @@ export class UpgradeCommandRegistryService implements OnModuleInit {
|
||||
seenTimestamps.add(entry.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
private validateNoVersionDuplicatesAcrossConstants(): void {
|
||||
const allVersions = [
|
||||
...TWENTY_PREVIOUS_VERSIONS,
|
||||
TWENTY_CURRENT_VERSION,
|
||||
...TWENTY_NEXT_VERSIONS,
|
||||
];
|
||||
|
||||
const uniqueVersions = new Set(allVersions);
|
||||
|
||||
if (uniqueVersions.size !== allVersions.length) {
|
||||
const duplicates = allVersions.filter(
|
||||
(version, index) => allVersions.indexOf(version) !== index,
|
||||
);
|
||||
|
||||
throw new Error(
|
||||
`Duplicate version(s) across TWENTY_PREVIOUS_VERSIONS, TWENTY_CURRENT_VERSION, and TWENTY_NEXT_VERSIONS: ${duplicates.join(', ')}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private validatePreviousVersionsNotEmpty(): void {
|
||||
if ((TWENTY_PREVIOUS_VERSIONS as readonly string[]).length === 0) {
|
||||
throw new Error(
|
||||
'TWENTY_PREVIOUS_VERSIONS must contain at least one version before TWENTY_CURRENT_VERSION',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+162
-2
@@ -2,9 +2,12 @@ import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { IsNull, type QueryRunner, Repository } from 'typeorm';
|
||||
import { In, IsNull, type QueryRunner, Repository } from 'typeorm';
|
||||
|
||||
import { UpgradeMigrationEntity } from 'src/engine/core-modules/upgrade/upgrade-migration.entity';
|
||||
import {
|
||||
UpgradeMigrationEntity,
|
||||
type UpgradeMigrationStatus,
|
||||
} from 'src/engine/core-modules/upgrade/upgrade-migration.entity';
|
||||
import { formatUpgradeErrorForStorage } from 'src/engine/core-modules/upgrade/utils/format-upgrade-error-for-storage.util';
|
||||
|
||||
@Injectable()
|
||||
@@ -89,4 +92,161 @@ export class UpgradeMigrationService {
|
||||
errorMessage: formatUpgradeErrorForStorage(error),
|
||||
});
|
||||
}
|
||||
|
||||
async markAsInitial({
|
||||
name,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
queryRunner,
|
||||
}: {
|
||||
name: string;
|
||||
workspaceId: string;
|
||||
executedByVersion: string;
|
||||
queryRunner?: QueryRunner;
|
||||
}): Promise<void> {
|
||||
const repository = queryRunner
|
||||
? queryRunner.manager.getRepository(UpgradeMigrationEntity)
|
||||
: this.upgradeMigrationRepository;
|
||||
|
||||
await repository.save({
|
||||
name,
|
||||
status: 'completed',
|
||||
isInitial: true,
|
||||
attempt: 1,
|
||||
executedByVersion,
|
||||
workspaceId,
|
||||
});
|
||||
}
|
||||
|
||||
// Returns the most recently attempted command (by createdAt)
|
||||
// across instance and active-workspace scopes, with its status.
|
||||
// Workspace-scoped records from inactive/deleted workspaces are
|
||||
// excluded so they cannot incorrectly influence the global cursor.
|
||||
async getLastAttemptedCommandNameOrThrow(
|
||||
allActiveOrSuspendedWorkspaceIds: string[],
|
||||
): Promise<{
|
||||
name: string;
|
||||
status: UpgradeMigrationStatus;
|
||||
}> {
|
||||
const queryBuilder = this.upgradeMigrationRepository
|
||||
.createQueryBuilder('migration')
|
||||
.select(['migration.name', 'migration.status'])
|
||||
.andWhere(
|
||||
`migration.attempt = (
|
||||
SELECT MAX(sub.attempt)
|
||||
FROM core."upgradeMigration" sub
|
||||
WHERE sub.name = migration.name
|
||||
AND (
|
||||
(sub."workspaceId" IS NULL AND migration."workspaceId" IS NULL)
|
||||
OR sub."workspaceId" = migration."workspaceId"
|
||||
)
|
||||
)`,
|
||||
);
|
||||
|
||||
if (allActiveOrSuspendedWorkspaceIds.length > 0) {
|
||||
queryBuilder.andWhere(
|
||||
'(migration."workspaceId" IS NULL OR migration."workspaceId" IN (:...allActiveOrSuspendedWorkspaceIds))',
|
||||
{ allActiveOrSuspendedWorkspaceIds },
|
||||
);
|
||||
} else {
|
||||
queryBuilder.andWhere('migration."workspaceId" IS NULL');
|
||||
}
|
||||
|
||||
const migration = await queryBuilder
|
||||
.orderBy('migration.createdAt', 'DESC')
|
||||
.getOne();
|
||||
|
||||
if (!migration) {
|
||||
throw new Error(
|
||||
'No upgrade migration found — the database may not have been initialized',
|
||||
);
|
||||
}
|
||||
|
||||
return { name: migration.name, status: migration.status };
|
||||
}
|
||||
|
||||
async getWorkspaceLastAttemptedCommandNameOrThrow(
|
||||
workspaceIds: string[],
|
||||
): Promise<Map<string, { name: string; status: UpgradeMigrationStatus }>> {
|
||||
if (workspaceIds.length === 0) {
|
||||
return new Map();
|
||||
}
|
||||
|
||||
const results = await this.upgradeMigrationRepository
|
||||
.createQueryBuilder('migration')
|
||||
.select('migration.workspaceId', 'workspaceId')
|
||||
.addSelect('migration.name', 'name')
|
||||
.addSelect('migration.status', 'status')
|
||||
.where({
|
||||
workspaceId: In(workspaceIds),
|
||||
})
|
||||
.andWhere(
|
||||
`migration.attempt = (
|
||||
SELECT MAX(sub.attempt)
|
||||
FROM core."upgradeMigration" sub
|
||||
WHERE sub.name = migration.name
|
||||
AND sub."workspaceId" = migration."workspaceId"
|
||||
)`,
|
||||
)
|
||||
.orderBy('migration.workspaceId')
|
||||
.addOrderBy('migration.createdAt', 'DESC')
|
||||
.distinctOn(['migration.workspaceId'])
|
||||
.getRawMany<{
|
||||
workspaceId: string;
|
||||
name: string;
|
||||
status: UpgradeMigrationStatus;
|
||||
}>();
|
||||
|
||||
const cursors = new Map<
|
||||
string,
|
||||
{ name: string; status: UpgradeMigrationStatus }
|
||||
>();
|
||||
|
||||
for (const row of results) {
|
||||
cursors.set(row.workspaceId, { name: row.name, status: row.status });
|
||||
}
|
||||
|
||||
const missingWorkspaceIds = workspaceIds.filter(
|
||||
(workspaceId) => !cursors.has(workspaceId),
|
||||
);
|
||||
|
||||
if (missingWorkspaceIds.length > 0) {
|
||||
throw new Error(
|
||||
`No upgrade migration found for workspace(s): ${missingWorkspaceIds.join(', ')}`,
|
||||
);
|
||||
}
|
||||
|
||||
return cursors;
|
||||
}
|
||||
|
||||
async areAllWorkspacesAtCommand({
|
||||
commandName,
|
||||
workspaceIds,
|
||||
}: {
|
||||
commandName: string;
|
||||
workspaceIds: string[];
|
||||
}): Promise<boolean> {
|
||||
if (workspaceIds.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const completedCount = await this.upgradeMigrationRepository
|
||||
.createQueryBuilder('migration')
|
||||
.where({
|
||||
name: commandName,
|
||||
status: 'completed',
|
||||
workspaceId: In(workspaceIds),
|
||||
})
|
||||
.andWhere(
|
||||
`migration.attempt = (
|
||||
SELECT MAX(sub.attempt)
|
||||
FROM core."upgradeMigration" sub
|
||||
WHERE sub.name = migration.name
|
||||
AND sub."workspaceId" = migration."workspaceId"
|
||||
)`,
|
||||
)
|
||||
.getCount();
|
||||
|
||||
return completedCount === workspaceIds.length;
|
||||
}
|
||||
}
|
||||
|
||||
+171
@@ -0,0 +1,171 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS } from 'src/engine/core-modules/upgrade/constants/twenty-cross-upgrade-supported-version.constant';
|
||||
import {
|
||||
type RegisteredFastInstanceCommand,
|
||||
type RegisteredSlowInstanceCommand,
|
||||
type RegisteredWorkspaceCommand,
|
||||
UpgradeCommandRegistryService,
|
||||
} from 'src/engine/core-modules/upgrade/services/upgrade-command-registry.service';
|
||||
|
||||
export type FastInstanceUpgradeStep = {
|
||||
kind: 'fast-instance';
|
||||
} & RegisteredFastInstanceCommand;
|
||||
|
||||
export type SlowInstanceUpgradeStep = {
|
||||
kind: 'slow-instance';
|
||||
} & RegisteredSlowInstanceCommand;
|
||||
|
||||
export type InstanceUpgradeStep =
|
||||
| FastInstanceUpgradeStep
|
||||
| SlowInstanceUpgradeStep;
|
||||
|
||||
export type WorkspaceUpgradeStep = {
|
||||
kind: 'workspace';
|
||||
} & RegisteredWorkspaceCommand;
|
||||
|
||||
export type UpgradeStep = InstanceUpgradeStep | WorkspaceUpgradeStep;
|
||||
|
||||
@Injectable()
|
||||
export class UpgradeSequenceReaderService {
|
||||
constructor(
|
||||
private readonly upgradeCommandRegistryService: UpgradeCommandRegistryService,
|
||||
) {}
|
||||
|
||||
getUpgradeSequence(): UpgradeStep[] {
|
||||
const sequence: UpgradeStep[] = [];
|
||||
|
||||
for (const version of TWENTY_CROSS_UPGRADE_SUPPORTED_VERSIONS) {
|
||||
const bundle =
|
||||
this.upgradeCommandRegistryService.getBundleForVersion(version);
|
||||
|
||||
for (const command of bundle.fastInstanceCommands) {
|
||||
sequence.push({ kind: 'fast-instance', ...command });
|
||||
}
|
||||
|
||||
for (const command of bundle.slowInstanceCommands) {
|
||||
sequence.push({ kind: 'slow-instance', ...command });
|
||||
}
|
||||
|
||||
for (const command of bundle.workspaceCommands) {
|
||||
sequence.push({ kind: 'workspace', ...command });
|
||||
}
|
||||
}
|
||||
|
||||
return sequence;
|
||||
}
|
||||
|
||||
locateStepInSequenceOrThrow({
|
||||
sequence,
|
||||
stepName,
|
||||
}: {
|
||||
sequence: UpgradeStep[];
|
||||
stepName: string;
|
||||
}): number {
|
||||
const cursor = sequence.findIndex((step) => step.name === stepName);
|
||||
|
||||
if (cursor === -1) {
|
||||
throw new Error(`Step "${stepName}" not found in upgrade sequence`);
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
getWorkspaceCommandsSliceBounds({
|
||||
sequence,
|
||||
workspaceCommand,
|
||||
}: {
|
||||
sequence: UpgradeStep[];
|
||||
workspaceCommand: WorkspaceUpgradeStep;
|
||||
}): { startCursor: number; endCursor: number } {
|
||||
const workspaceCommandCursor = this.locateStepInSequenceOrThrow({
|
||||
sequence,
|
||||
stepName: workspaceCommand.name,
|
||||
});
|
||||
|
||||
let startCursor = workspaceCommandCursor;
|
||||
|
||||
while (startCursor > 0 && sequence[startCursor - 1].kind === 'workspace') {
|
||||
startCursor--;
|
||||
}
|
||||
|
||||
let endCursor = workspaceCommandCursor;
|
||||
|
||||
while (
|
||||
endCursor < sequence.length - 1 &&
|
||||
sequence[endCursor + 1].kind === 'workspace'
|
||||
) {
|
||||
endCursor++;
|
||||
}
|
||||
|
||||
return { startCursor, endCursor };
|
||||
}
|
||||
|
||||
collectContiguousWorkspaceSteps({
|
||||
sequence,
|
||||
fromWorkspaceCommand,
|
||||
}: {
|
||||
sequence: UpgradeStep[];
|
||||
fromWorkspaceCommand: WorkspaceUpgradeStep;
|
||||
}): WorkspaceUpgradeStep[] {
|
||||
const fromCursor = this.locateStepInSequenceOrThrow({
|
||||
sequence,
|
||||
stepName: fromWorkspaceCommand.name,
|
||||
});
|
||||
|
||||
const slice: WorkspaceUpgradeStep[] = [];
|
||||
|
||||
for (let cursor = fromCursor; cursor < sequence.length; cursor++) {
|
||||
const step = sequence[cursor];
|
||||
|
||||
if (step.kind !== 'workspace') {
|
||||
break;
|
||||
}
|
||||
|
||||
slice.push(step);
|
||||
}
|
||||
|
||||
return slice;
|
||||
}
|
||||
|
||||
// Returns workspace commands that still need to run, based on the
|
||||
// workspace's cursor position. If the cursor points to a command from
|
||||
// a previous slice (not found in the current one), the entire slice
|
||||
// is pending — this happens when a workspace enters a new slice for
|
||||
// the first time after a sync barrier.
|
||||
getPendingWorkspaceCommands({
|
||||
workspaceCommands,
|
||||
workspaceCursor,
|
||||
}: {
|
||||
workspaceCommands: WorkspaceUpgradeStep[];
|
||||
workspaceCursor: { name: string; status: 'completed' | 'failed' };
|
||||
}): WorkspaceUpgradeStep[] {
|
||||
const cursorIndex = workspaceCommands.findIndex(
|
||||
(command) => command.name === workspaceCursor.name,
|
||||
);
|
||||
|
||||
if (cursorIndex === -1) {
|
||||
return workspaceCommands;
|
||||
}
|
||||
|
||||
return workspaceCursor.status === 'completed'
|
||||
? workspaceCommands.slice(cursorIndex + 1)
|
||||
: workspaceCommands.slice(cursorIndex);
|
||||
}
|
||||
|
||||
getLastWorkspaceCommand(): RegisteredWorkspaceCommand {
|
||||
const sequence = this.getUpgradeSequence();
|
||||
|
||||
for (let index = sequence.length - 1; index >= 0; index--) {
|
||||
const step = sequence[index];
|
||||
|
||||
if (step.kind === 'workspace') {
|
||||
return step;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
'No workspace commands found in upgrade sequence — this should have been caught at startup',
|
||||
);
|
||||
}
|
||||
}
|
||||
+294
@@ -0,0 +1,294 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import {
|
||||
type WorkspaceIteratorReport,
|
||||
WorkspaceIteratorService,
|
||||
} from 'src/database/commands/command-runners/workspace-iterator.service';
|
||||
import { type ParsedUpgradeCommandOptions } from 'src/database/commands/upgrade-version-command/upgrade.command';
|
||||
import { InstanceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/instance-command-runner.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
import {
|
||||
type InstanceUpgradeStep,
|
||||
type UpgradeStep,
|
||||
type WorkspaceUpgradeStep,
|
||||
UpgradeSequenceReaderService,
|
||||
} from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import { WorkspaceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/workspace-command-runner.service';
|
||||
import { WorkspaceVersionService } from 'src/engine/workspace-manager/workspace-version/services/workspace-version.service';
|
||||
import { assertUnreachable, isDefined } from 'twenty-shared/utils';
|
||||
|
||||
export type UpgradeSequenceRunnerReport = {
|
||||
totalSuccesses: number;
|
||||
totalFailures: number;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class UpgradeSequenceRunnerService {
|
||||
private readonly logger = new Logger(UpgradeSequenceRunnerService.name);
|
||||
|
||||
constructor(
|
||||
private readonly upgradeMigrationService: UpgradeMigrationService,
|
||||
private readonly instanceCommandRunnerService: InstanceCommandRunnerService,
|
||||
private readonly workspaceCommandRunnerService: WorkspaceCommandRunnerService,
|
||||
private readonly upgradeSequenceReaderService: UpgradeSequenceReaderService,
|
||||
private readonly workspaceIteratorService: WorkspaceIteratorService,
|
||||
private readonly workspaceVersionService: WorkspaceVersionService,
|
||||
) {}
|
||||
|
||||
async run({
|
||||
sequence,
|
||||
options,
|
||||
}: {
|
||||
sequence: UpgradeStep[];
|
||||
options: ParsedUpgradeCommandOptions;
|
||||
}): Promise<UpgradeSequenceRunnerReport> {
|
||||
if (sequence.length === 0) {
|
||||
return { totalSuccesses: 0, totalFailures: 0 };
|
||||
}
|
||||
|
||||
const allActiveOrSuspendedWorkspaceIds =
|
||||
await this.workspaceVersionService.getActiveOrSuspendedWorkspaceIds();
|
||||
|
||||
const startCursor = await this.resolveStartCursor({
|
||||
sequence,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
});
|
||||
|
||||
let totalSuccesses = 0;
|
||||
let totalFailures = 0;
|
||||
let cursor = startCursor;
|
||||
|
||||
while (cursor < sequence.length) {
|
||||
const step = sequence[cursor];
|
||||
|
||||
if (step.kind === 'fast-instance' || step.kind === 'slow-instance') {
|
||||
const previousStep = cursor > 0 ? sequence[cursor - 1] : undefined;
|
||||
if (previousStep?.kind === 'workspace') {
|
||||
await this.enforceWorkspaceSyncBarrier({
|
||||
previousWorkspaceStep: previousStep,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
});
|
||||
}
|
||||
|
||||
await this.runInstanceStep({
|
||||
instanceStep: step,
|
||||
skipDataMigration: allActiveOrSuspendedWorkspaceIds.length === 0,
|
||||
});
|
||||
cursor++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const contiguousWorkspaceSteps =
|
||||
this.upgradeSequenceReaderService.collectContiguousWorkspaceSteps({
|
||||
sequence,
|
||||
fromWorkspaceCommand: step,
|
||||
});
|
||||
|
||||
const report = await this.resumeWorkspaceCommandsFromCursors({
|
||||
contiguousWorkspaceSteps,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
options,
|
||||
});
|
||||
|
||||
totalSuccesses += report.success.length;
|
||||
totalFailures += report.fail.length;
|
||||
|
||||
if (report.fail.length > 0) {
|
||||
this.logger.error(
|
||||
`Workspace steps ended with ${report.fail.length} failure(s). ` +
|
||||
'Aborting — cannot proceed to next instance step.',
|
||||
);
|
||||
|
||||
return { totalSuccesses, totalFailures };
|
||||
}
|
||||
|
||||
cursor += contiguousWorkspaceSteps.length;
|
||||
}
|
||||
|
||||
return { totalSuccesses, totalFailures };
|
||||
}
|
||||
private async resolveStartCursor({
|
||||
sequence,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
}: {
|
||||
sequence: UpgradeStep[];
|
||||
allActiveOrSuspendedWorkspaceIds: string[];
|
||||
}): Promise<number> {
|
||||
const lastAttempted =
|
||||
await this.upgradeMigrationService.getLastAttemptedCommandNameOrThrow(
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
);
|
||||
|
||||
const lastAttemptedCursor =
|
||||
this.upgradeSequenceReaderService.locateStepInSequenceOrThrow({
|
||||
sequence,
|
||||
stepName: lastAttempted.name,
|
||||
});
|
||||
|
||||
const lastAttemptedStep = sequence[lastAttemptedCursor];
|
||||
|
||||
switch (lastAttemptedStep.kind) {
|
||||
case 'fast-instance':
|
||||
case 'slow-instance': {
|
||||
return lastAttempted.status === 'completed'
|
||||
? lastAttemptedCursor + 1
|
||||
: lastAttemptedCursor;
|
||||
}
|
||||
case 'workspace': {
|
||||
const workspaceSliceBounds =
|
||||
this.upgradeSequenceReaderService.getWorkspaceCommandsSliceBounds({
|
||||
sequence,
|
||||
workspaceCommand: lastAttemptedStep,
|
||||
});
|
||||
|
||||
await this.validateWorkspaceCursorsAreInSameWorkspaceStepsSlice({
|
||||
sequence,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
workspaceSliceBounds,
|
||||
});
|
||||
|
||||
return workspaceSliceBounds.startCursor;
|
||||
}
|
||||
default:
|
||||
assertUnreachable(lastAttemptedStep);
|
||||
}
|
||||
}
|
||||
|
||||
private async validateWorkspaceCursorsAreInSameWorkspaceStepsSlice({
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
sequence,
|
||||
workspaceSliceBounds: { startCursor, endCursor },
|
||||
}: {
|
||||
sequence: UpgradeStep[];
|
||||
allActiveOrSuspendedWorkspaceIds: string[];
|
||||
workspaceSliceBounds: { startCursor: number; endCursor: number };
|
||||
}): Promise<void> {
|
||||
const workspaceCursors =
|
||||
await this.upgradeMigrationService.getWorkspaceLastAttemptedCommandNameOrThrow(
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
);
|
||||
|
||||
for (const [workspaceId, workspaceCursor] of workspaceCursors) {
|
||||
const cursor =
|
||||
this.upgradeSequenceReaderService.locateStepInSequenceOrThrow({
|
||||
sequence,
|
||||
stepName: workspaceCursor.name,
|
||||
});
|
||||
|
||||
if (cursor < startCursor || cursor > endCursor) {
|
||||
throw new Error(
|
||||
`Workspace ${workspaceId} cursor "${workspaceCursor.name}" is outside the ` +
|
||||
`current workspace slice [${startCursor}..${endCursor}] — ` +
|
||||
'workspaces are not aligned',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async runInstanceStep({
|
||||
instanceStep,
|
||||
skipDataMigration,
|
||||
}: {
|
||||
instanceStep: InstanceUpgradeStep;
|
||||
skipDataMigration: boolean;
|
||||
}): Promise<void> {
|
||||
switch (instanceStep.kind) {
|
||||
case 'fast-instance': {
|
||||
const result =
|
||||
await this.instanceCommandRunnerService.runFastInstanceCommand({
|
||||
command: instanceStep.command,
|
||||
name: instanceStep.name,
|
||||
});
|
||||
|
||||
if (result.status === 'failed') {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
case 'slow-instance': {
|
||||
const result =
|
||||
await this.instanceCommandRunnerService.runSlowInstanceCommand({
|
||||
command: instanceStep.command,
|
||||
name: instanceStep.name,
|
||||
skipDataMigration,
|
||||
});
|
||||
|
||||
if (result.status === 'failed') {
|
||||
throw result.error;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
default:
|
||||
assertUnreachable(instanceStep);
|
||||
}
|
||||
}
|
||||
|
||||
private async resumeWorkspaceCommandsFromCursors({
|
||||
contiguousWorkspaceSteps,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
options,
|
||||
}: {
|
||||
contiguousWorkspaceSteps: WorkspaceUpgradeStep[];
|
||||
allActiveOrSuspendedWorkspaceIds: string[];
|
||||
options: ParsedUpgradeCommandOptions;
|
||||
}): Promise<WorkspaceIteratorReport> {
|
||||
const workspaceCursors =
|
||||
await this.upgradeMigrationService.getWorkspaceLastAttemptedCommandNameOrThrow(
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
);
|
||||
|
||||
return this.workspaceIteratorService.iterate({
|
||||
workspaceIds:
|
||||
isDefined(options.workspaceIds) && options.workspaceIds.length > 0
|
||||
? options.workspaceIds
|
||||
: allActiveOrSuspendedWorkspaceIds,
|
||||
startFromWorkspaceId: options.startFromWorkspaceId,
|
||||
workspaceCountLimit: options.workspaceCountLimit,
|
||||
dryRun: options.dryRun,
|
||||
callback: async (context) => {
|
||||
const workspaceCursor = workspaceCursors.get(context.workspaceId);
|
||||
|
||||
if (!workspaceCursor) {
|
||||
throw new Error(
|
||||
`No upgrade migration found for workspace ${context.workspaceId}. This should never occur.`,
|
||||
);
|
||||
}
|
||||
|
||||
const pendingCommands =
|
||||
this.upgradeSequenceReaderService.getPendingWorkspaceCommands({
|
||||
workspaceCommands: contiguousWorkspaceSteps,
|
||||
workspaceCursor,
|
||||
});
|
||||
|
||||
await this.workspaceCommandRunnerService.runWorkspaceCommands({
|
||||
iteratorContext: context,
|
||||
options,
|
||||
workspaceCommands: pendingCommands,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private async enforceWorkspaceSyncBarrier({
|
||||
previousWorkspaceStep,
|
||||
allActiveOrSuspendedWorkspaceIds,
|
||||
}: {
|
||||
previousWorkspaceStep: WorkspaceUpgradeStep;
|
||||
allActiveOrSuspendedWorkspaceIds: string[];
|
||||
}): Promise<void> {
|
||||
const allWorkspacesReady =
|
||||
await this.upgradeMigrationService.areAllWorkspacesAtCommand({
|
||||
commandName: previousWorkspaceStep.name,
|
||||
workspaceIds: allActiveOrSuspendedWorkspaceIds,
|
||||
});
|
||||
|
||||
if (!allWorkspacesReady) {
|
||||
throw new Error(
|
||||
'Cannot run instance step: not all workspaces have completed ' +
|
||||
`"${previousWorkspaceStep.name}"`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { type WorkspaceIteratorContext } from 'src/database/commands/command-runners/workspace-iterator.service';
|
||||
import { type ParsedUpgradeCommandOptions } from 'src/database/commands/upgrade-version-command/upgrade.command';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { type RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/services/upgrade-command-registry.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
|
||||
type WorkspaceCommandEntry = Pick<
|
||||
RegisteredWorkspaceCommand,
|
||||
'name' | 'command'
|
||||
>;
|
||||
|
||||
export type RunWorkspaceCommandsArgs = {
|
||||
iteratorContext: WorkspaceIteratorContext;
|
||||
options: ParsedUpgradeCommandOptions;
|
||||
workspaceCommands: WorkspaceCommandEntry[];
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceCommandRunnerService {
|
||||
private readonly logger = new Logger(WorkspaceCommandRunnerService.name);
|
||||
|
||||
constructor(
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
private readonly upgradeMigrationService: UpgradeMigrationService,
|
||||
) {}
|
||||
|
||||
async runWorkspaceCommands({
|
||||
iteratorContext,
|
||||
options,
|
||||
workspaceCommands,
|
||||
}: RunWorkspaceCommandsArgs): Promise<void> {
|
||||
const { workspaceId, index, total } = iteratorContext;
|
||||
|
||||
this.logger.log(
|
||||
`${options.dryRun ? '(dry run) ' : ''}Upgrading workspace ${workspaceId} ${index + 1}/${total}`,
|
||||
);
|
||||
|
||||
const executedByVersion =
|
||||
this.twentyConfigService.get('APP_VERSION') ?? 'unknown';
|
||||
|
||||
for (const workspaceCommandEntry of workspaceCommands) {
|
||||
await this.runSingleWorkspaceCommandOrThrow({
|
||||
workspaceCommandEntry,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
options,
|
||||
iteratorContext,
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.log(`Upgrade for workspace ${workspaceId} completed.`);
|
||||
}
|
||||
|
||||
private async runSingleWorkspaceCommandOrThrow({
|
||||
workspaceCommandEntry,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
options,
|
||||
iteratorContext,
|
||||
}: {
|
||||
workspaceCommandEntry: WorkspaceCommandEntry;
|
||||
workspaceId: string;
|
||||
executedByVersion: string;
|
||||
options: ParsedUpgradeCommandOptions;
|
||||
iteratorContext: WorkspaceIteratorContext;
|
||||
}): Promise<void> {
|
||||
const { name, command: workspaceCommand } = workspaceCommandEntry;
|
||||
|
||||
try {
|
||||
await workspaceCommand.runOnWorkspace({
|
||||
options,
|
||||
workspaceId,
|
||||
dataSource: iteratorContext.dataSource,
|
||||
index: iteratorContext.index,
|
||||
total: iteratorContext.total,
|
||||
});
|
||||
|
||||
if (!options.dryRun) {
|
||||
await this.upgradeMigrationService.markAsCompleted({
|
||||
name,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (!options.dryRun) {
|
||||
await this.upgradeMigrationService.markAsFailed({
|
||||
name,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
-181
@@ -1,181 +0,0 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { SemVer } from 'semver';
|
||||
import { assertUnreachable, isDefined } from 'twenty-shared/utils';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { type WorkspaceIteratorContext } from 'src/database/commands/command-runners/workspace-iterator.service';
|
||||
import {
|
||||
type UpgradeCommandOptions,
|
||||
type VersionCommands,
|
||||
} from 'src/database/commands/upgrade-version-command/upgrade.command';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/services/upgrade-command-registry.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import {
|
||||
type CompareVersionMajorAndMinorReturnType,
|
||||
compareVersionMajorAndMinor,
|
||||
} from 'src/utils/version/compare-version-minor-and-major';
|
||||
|
||||
export type UpgradeWorkspaceArgs = {
|
||||
iteratorContext: WorkspaceIteratorContext;
|
||||
options: UpgradeCommandOptions;
|
||||
fromWorkspaceVersion: SemVer;
|
||||
currentAppVersion: SemVer;
|
||||
workspaceCommands: VersionCommands;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceUpgradeService {
|
||||
private readonly logger = new Logger(WorkspaceUpgradeService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(WorkspaceEntity)
|
||||
private readonly workspaceRepository: Repository<WorkspaceEntity>,
|
||||
private readonly twentyConfigService: TwentyConfigService,
|
||||
private readonly upgradeMigrationService: UpgradeMigrationService,
|
||||
) {}
|
||||
|
||||
async upgradeWorkspace({
|
||||
iteratorContext,
|
||||
options,
|
||||
fromWorkspaceVersion,
|
||||
currentAppVersion,
|
||||
workspaceCommands,
|
||||
}: UpgradeWorkspaceArgs): Promise<void> {
|
||||
const { workspaceId, index, total } = iteratorContext;
|
||||
|
||||
this.logger.log(
|
||||
`${options.dryRun ? '(dry run) ' : ''}Upgrading workspace ${workspaceId} from=${fromWorkspaceVersion} to=${currentAppVersion} ${index + 1}/${total}`,
|
||||
);
|
||||
|
||||
const versionCompareResult =
|
||||
await this.compareWorkspaceVersionToFromVersion(
|
||||
workspaceId,
|
||||
fromWorkspaceVersion,
|
||||
);
|
||||
|
||||
switch (versionCompareResult) {
|
||||
case 'lower': {
|
||||
throw new Error(
|
||||
`WORKSPACE_VERSION_MISMATCH Upgrade for workspace ${workspaceId} failed as its version is beneath fromWorkspaceVersion=${fromWorkspaceVersion.version}`,
|
||||
);
|
||||
}
|
||||
case 'equal': {
|
||||
const executedByVersion =
|
||||
this.twentyConfigService.get('APP_VERSION') ?? 'unknown';
|
||||
|
||||
for (const workspaceCommandEntry of workspaceCommands) {
|
||||
await this.runSingleWorkspaceCommandOrThrow({
|
||||
workspaceCommandEntry,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
options,
|
||||
iteratorContext,
|
||||
});
|
||||
}
|
||||
|
||||
if (!options.dryRun) {
|
||||
await this.workspaceRepository.update(
|
||||
{ id: workspaceId },
|
||||
{ version: currentAppVersion.version },
|
||||
);
|
||||
}
|
||||
|
||||
this.logger.log(`Upgrade for workspace ${workspaceId} completed.`);
|
||||
|
||||
return;
|
||||
}
|
||||
case 'higher': {
|
||||
this.logger.log(
|
||||
`Upgrade for workspace ${workspaceId} ignored as is already at a higher version.`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
assertUnreachable(versionCompareResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async compareWorkspaceVersionToFromVersion(
|
||||
workspaceId: string,
|
||||
fromWorkspaceVersion: SemVer,
|
||||
): Promise<CompareVersionMajorAndMinorReturnType> {
|
||||
const workspace = await this.workspaceRepository.findOneByOrFail({
|
||||
id: workspaceId,
|
||||
});
|
||||
const currentWorkspaceVersion = workspace.version;
|
||||
|
||||
if (!isDefined(currentWorkspaceVersion)) {
|
||||
throw new Error(`WORKSPACE_VERSION_NOT_DEFINED workspace=${workspaceId}`);
|
||||
}
|
||||
|
||||
return compareVersionMajorAndMinor(
|
||||
currentWorkspaceVersion,
|
||||
fromWorkspaceVersion.version,
|
||||
);
|
||||
}
|
||||
|
||||
private async runSingleWorkspaceCommandOrThrow({
|
||||
workspaceCommandEntry,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
options,
|
||||
iteratorContext,
|
||||
}: {
|
||||
workspaceCommandEntry: RegisteredWorkspaceCommand;
|
||||
workspaceId: string;
|
||||
executedByVersion: string;
|
||||
options: UpgradeCommandOptions;
|
||||
iteratorContext: WorkspaceIteratorContext;
|
||||
}): Promise<void> {
|
||||
const { name, command: workspaceCommand } = workspaceCommandEntry;
|
||||
|
||||
const isAlreadyCompleted =
|
||||
await this.upgradeMigrationService.isLastAttemptCompleted({
|
||||
name,
|
||||
workspaceId,
|
||||
});
|
||||
|
||||
if (isAlreadyCompleted) {
|
||||
this.logger.log(
|
||||
`Workspace command ${name} already completed for workspace ${workspaceId}, skipping`,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await workspaceCommand.runOnWorkspace({
|
||||
options,
|
||||
workspaceId,
|
||||
dataSource: iteratorContext.dataSource,
|
||||
index: iteratorContext.index,
|
||||
total: iteratorContext.total,
|
||||
});
|
||||
|
||||
if (!options.dryRun) {
|
||||
await this.upgradeMigrationService.markAsCompleted({
|
||||
name,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
if (!options.dryRun) {
|
||||
await this.upgradeMigrationService.markAsFailed({
|
||||
name,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
error,
|
||||
});
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
TWENTY_ALL_VERSIONS,
|
||||
TwentyAllVersion,
|
||||
} from 'src/engine/core-modules/upgrade/constants/twenty-all-versions.constant';
|
||||
import { TWENTY_CURRENT_VERSION } from 'src/engine/core-modules/upgrade/constants/twenty-current-version.constant';
|
||||
import { IndexOf, IsGreaterOrEqual } from 'twenty-shared/types';
|
||||
|
||||
export type RemovedSinceVersion<RemoveAtVersion extends TwentyAllVersion, T> =
|
||||
IsGreaterOrEqual<
|
||||
IndexOf<typeof TWENTY_CURRENT_VERSION, typeof TWENTY_ALL_VERSIONS>,
|
||||
IndexOf<RemoveAtVersion, typeof TWENTY_ALL_VERSIONS>
|
||||
> extends true
|
||||
? never
|
||||
: T;
|
||||
@@ -41,6 +41,9 @@ export class UpgradeMigrationEntity {
|
||||
@Column({ type: 'text', nullable: true })
|
||||
errorMessage: string | null;
|
||||
|
||||
@Column({ type: 'boolean', nullable: false, default: false })
|
||||
isInitial: boolean;
|
||||
|
||||
@ManyToOne(() => WorkspaceEntity, { onDelete: 'CASCADE', nullable: true })
|
||||
@JoinColumn({ name: 'workspaceId' })
|
||||
workspace: Relation<WorkspaceEntity> | null;
|
||||
|
||||
@@ -2,29 +2,39 @@ import { Module } from '@nestjs/common';
|
||||
import { DiscoveryModule } from '@nestjs/core';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { InstanceUpgradeService } from 'src/engine/core-modules/upgrade/services/instance-upgrade.service';
|
||||
import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/workspace-iterator.module';
|
||||
import { InstanceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/instance-command-runner.service';
|
||||
import { UpgradeCommandRegistryService } from 'src/engine/core-modules/upgrade/services/upgrade-command-registry.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
import { WorkspaceUpgradeService } from 'src/engine/core-modules/upgrade/services/workspace-upgrade.service';
|
||||
import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import { UpgradeSequenceRunnerService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-runner.service';
|
||||
import { WorkspaceCommandRunnerService } from 'src/engine/core-modules/upgrade/services/workspace-command-runner.service';
|
||||
import { UpgradeMigrationEntity } from 'src/engine/core-modules/upgrade/upgrade-migration.entity';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceVersionModule } from 'src/engine/workspace-manager/workspace-version/workspace-version.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
DiscoveryModule,
|
||||
WorkspaceIteratorModule,
|
||||
WorkspaceVersionModule,
|
||||
TypeOrmModule.forFeature([UpgradeMigrationEntity, WorkspaceEntity]),
|
||||
],
|
||||
providers: [
|
||||
UpgradeMigrationService,
|
||||
InstanceUpgradeService,
|
||||
WorkspaceUpgradeService,
|
||||
InstanceCommandRunnerService,
|
||||
WorkspaceCommandRunnerService,
|
||||
UpgradeCommandRegistryService,
|
||||
UpgradeSequenceReaderService,
|
||||
UpgradeSequenceRunnerService,
|
||||
],
|
||||
exports: [
|
||||
UpgradeMigrationService,
|
||||
InstanceUpgradeService,
|
||||
WorkspaceUpgradeService,
|
||||
InstanceCommandRunnerService,
|
||||
WorkspaceCommandRunnerService,
|
||||
UpgradeCommandRegistryService,
|
||||
UpgradeSequenceReaderService,
|
||||
UpgradeSequenceRunnerService,
|
||||
],
|
||||
})
|
||||
export class UpgradeModule {}
|
||||
|
||||
+5
-1
@@ -28,8 +28,10 @@ import { WorkspaceService } from 'src/engine/core-modules/workspace/services/wor
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { createEmptyAllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/constant/create-empty-all-flat-entity-maps.constant';
|
||||
import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';
|
||||
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import { AiModelRegistryService } from 'src/engine/metadata-modules/ai/ai-models/services/ai-model-registry.service';
|
||||
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
|
||||
import { PermissionsService } from 'src/engine/metadata-modules/permissions/permissions.service';
|
||||
import { CoreEntityCacheService } from 'src/engine/core-entity-cache/services/core-entity-cache.service';
|
||||
import { WorkspaceCacheStorageService } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
|
||||
@@ -122,6 +124,8 @@ describe('WorkspaceService', () => {
|
||||
FileCorePictureService,
|
||||
AiModelRegistryService,
|
||||
PrefillLogicFunctionService,
|
||||
UpgradeMigrationService,
|
||||
UpgradeSequenceReaderService,
|
||||
].map((service) => ({
|
||||
provide: service,
|
||||
useValue: {},
|
||||
|
||||
+50
-10
@@ -10,7 +10,9 @@ import { assertIsDefinedOrThrow, isDefined } from 'twenty-shared/utils';
|
||||
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
|
||||
import { DataSource, QueryRunner, Repository } from 'typeorm';
|
||||
|
||||
import { CoreEntityCacheService } from 'src/engine/core-entity-cache/services/core-entity-cache.service';
|
||||
import { ApiKeyEntity } from 'src/engine/core-modules/api-key/api-key.entity';
|
||||
import { type AuthContextUser } from 'src/engine/core-modules/auth/types/auth-context.type';
|
||||
import { BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service';
|
||||
import { BillingService } from 'src/engine/core-modules/billing/services/billing.service';
|
||||
import { DnsManagerService } from 'src/engine/core-modules/dns-manager/services/dns-manager.service';
|
||||
@@ -27,9 +29,10 @@ import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decora
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
|
||||
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
|
||||
import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
|
||||
import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||
import { UserWorkspaceService } from 'src/engine/core-modules/user-workspace/user-workspace.service';
|
||||
import { type AuthContextUser } from 'src/engine/core-modules/auth/types/auth-context.type';
|
||||
import { UserEntity } from 'src/engine/core-modules/user/user.entity';
|
||||
import { type ActivateWorkspaceInput } from 'src/engine/core-modules/workspace/dtos/activate-workspace-input';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
@@ -38,7 +41,6 @@ import {
|
||||
WorkspaceExceptionCode,
|
||||
WorkspaceNotFoundDefaultError,
|
||||
} from 'src/engine/core-modules/workspace/workspace.exception';
|
||||
import { CoreEntityCacheService } from 'src/engine/core-entity-cache/services/core-entity-cache.service';
|
||||
import { AiModelRegistryService } from 'src/engine/metadata-modules/ai/ai-models/services/ai-model-registry.service';
|
||||
import { isModelAllowedByWorkspace } from 'src/engine/metadata-modules/ai/ai-models/utils/is-model-allowed.util';
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
@@ -54,17 +56,16 @@ import { PermissionsService } from 'src/engine/metadata-modules/permissions/perm
|
||||
import { WorkspaceCacheStorageService } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
|
||||
import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { PrefillLogicFunctionService } from 'src/engine/workspace-manager/standard-objects-prefill-data/services/prefill-logic-function.service';
|
||||
import { prefillCompanies } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-companies.util';
|
||||
import { prefillDashboards } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-dashboards.util';
|
||||
import { prefillOpportunities } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-opportunities.util';
|
||||
import { prefillPeople } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-people.util';
|
||||
import { prefillWorkflowCommandMenuItems } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-command-menu-items.util';
|
||||
import { getCreateCompanyWhenAddingNewPersonCodeStepLogicFunctionDefinitions } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-code-step-logic-functions.util';
|
||||
import { prefillWorkflowCommandMenuItems } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflow-command-menu-items.util';
|
||||
import { prefillWorkflows } from 'src/engine/workspace-manager/standard-objects-prefill-data/utils/prefill-workflows.util';
|
||||
import { PrefillLogicFunctionService } from 'src/engine/workspace-manager/standard-objects-prefill-data/services/prefill-logic-function.service';
|
||||
import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service';
|
||||
import { DEFAULT_FEATURE_FLAGS } from 'src/engine/workspace-manager/workspace-migration/constant/default-feature-flags';
|
||||
import { extractVersionMajorMinorPatch } from 'src/utils/version/extract-version-major-minor-patch';
|
||||
|
||||
@Injectable()
|
||||
// oxlint-disable-next-line twenty/inject-workspace-repository
|
||||
@@ -126,6 +127,8 @@ export class WorkspaceService extends TypeOrmQueryService<WorkspaceEntity> {
|
||||
@InjectDataSource()
|
||||
private readonly coreDataSource: DataSource,
|
||||
private readonly coreEntityCacheService: CoreEntityCacheService,
|
||||
private readonly upgradeMigrationService: UpgradeMigrationService,
|
||||
private readonly upgradeSequenceReaderService: UpgradeSequenceReaderService,
|
||||
) {
|
||||
super(workspaceRepository);
|
||||
}
|
||||
@@ -354,12 +357,9 @@ export class WorkspaceService extends TypeOrmQueryService<WorkspaceEntity> {
|
||||
schemaName: getWorkspaceSchemaName(workspace.id),
|
||||
});
|
||||
|
||||
const appVersion = this.twentyConfigService.get('APP_VERSION');
|
||||
|
||||
await this.workspaceRepository.update(workspace.id, {
|
||||
await this.activateAndInitializeUpgradeState({
|
||||
workspaceId: workspace.id,
|
||||
displayName: data.displayName,
|
||||
activationStatus: WorkspaceActivationStatus.ACTIVE,
|
||||
version: extractVersionMajorMinorPatch(appVersion),
|
||||
});
|
||||
|
||||
await this.coreEntityCacheService.invalidate(
|
||||
@@ -372,6 +372,46 @@ export class WorkspaceService extends TypeOrmQueryService<WorkspaceEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
private async activateAndInitializeUpgradeState({
|
||||
displayName,
|
||||
workspaceId,
|
||||
}: {
|
||||
workspaceId: string;
|
||||
displayName: string;
|
||||
}): Promise<void> {
|
||||
const lastWorkspaceCommand =
|
||||
this.upgradeSequenceReaderService.getLastWorkspaceCommand();
|
||||
|
||||
const executedByVersion =
|
||||
this.twentyConfigService.get('APP_VERSION') ?? 'unknown';
|
||||
|
||||
const queryRunner = this.coreDataSource.createQueryRunner();
|
||||
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
await queryRunner.manager.update(WorkspaceEntity, workspaceId, {
|
||||
displayName,
|
||||
activationStatus: WorkspaceActivationStatus.ACTIVE,
|
||||
});
|
||||
|
||||
await this.upgradeMigrationService.markAsInitial({
|
||||
name: lastWorkspaceCommand.name,
|
||||
workspaceId,
|
||||
executedByVersion,
|
||||
queryRunner,
|
||||
});
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async deleteWorkspace(id: string, softDelete = false) {
|
||||
const workspace = await this.workspaceRepository.findOne({
|
||||
where: { id },
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { type WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { type FlatWorkspace } from 'src/engine/core-modules/workspace/types/flat-workspace.type';
|
||||
import { type WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
|
||||
export const fromWorkspaceEntityToFlat = (
|
||||
entity: WorkspaceEntity,
|
||||
@@ -28,7 +28,6 @@ export const fromWorkspaceEntityToFlat = (
|
||||
isCustomDomainEnabled: entity.isCustomDomainEnabled,
|
||||
editableProfileFields: entity.editableProfileFields,
|
||||
defaultRoleId: entity.defaultRoleId,
|
||||
version: entity.version,
|
||||
fastModel: entity.fastModel,
|
||||
smartModel: entity.smartModel,
|
||||
aiAdditionalInstructions: entity.aiAdditionalInstructions,
|
||||
@@ -40,4 +39,5 @@ export const fromWorkspaceEntityToFlat = (
|
||||
updatedAt: entity.updatedAt.toISOString(),
|
||||
deletedAt: entity.deletedAt?.toISOString(),
|
||||
suspendedAt: entity.suspendedAt?.toISOString() ?? null,
|
||||
version: entity.version ?? null,
|
||||
});
|
||||
|
||||
@@ -32,12 +32,9 @@ import { KeyValuePairEntity } from 'src/engine/core-modules/key-value-pair/key-v
|
||||
import { PostgresCredentialsEntity } from 'src/engine/core-modules/postgres-credentials/postgres-credentials.entity';
|
||||
import { PublicDomainEntity } from 'src/engine/core-modules/public-domain/public-domain.entity';
|
||||
import { WorkspaceSSOIdentityProviderEntity } from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { RemovedSinceVersion } from 'src/engine/core-modules/upgrade/types/removed-since-version.type';
|
||||
import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
|
||||
import { AgentEntity } from 'src/engine/metadata-modules/ai/ai-agent/entities/agent.entity';
|
||||
import {
|
||||
AUTO_SELECT_FAST_MODEL_ID,
|
||||
AUTO_SELECT_SMART_MODEL_ID,
|
||||
} from 'twenty-shared/constants';
|
||||
import { type ModelId } from 'src/engine/metadata-modules/ai/ai-models/types/model-id.type';
|
||||
import { RoleDTO } from 'src/engine/metadata-modules/role/dtos/role.dto';
|
||||
import { ViewFieldDTO } from 'src/engine/metadata-modules/view-field/dtos/view-field.dto';
|
||||
@@ -53,6 +50,10 @@ import { ViewSortEntity } from 'src/engine/metadata-modules/view-sort/entities/v
|
||||
import { ViewDTO } from 'src/engine/metadata-modules/view/dtos/view.dto';
|
||||
import { ViewEntity } from 'src/engine/metadata-modules/view/entities/view.entity';
|
||||
import { WebhookEntity } from 'src/engine/metadata-modules/webhook/entities/webhook.entity';
|
||||
import {
|
||||
AUTO_SELECT_FAST_MODEL_ID,
|
||||
AUTO_SELECT_SMART_MODEL_ID,
|
||||
} from 'twenty-shared/constants';
|
||||
|
||||
registerEnumType(WorkspaceActivationStatus, {
|
||||
name: 'WorkspaceActivationStatus',
|
||||
@@ -296,7 +297,7 @@ export class WorkspaceEntity {
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
@Column({ type: 'varchar', nullable: true })
|
||||
version: string | null;
|
||||
version: RemovedSinceVersion<'1.23.0', string | null>;
|
||||
|
||||
@Field(() => String, { nullable: false })
|
||||
@Column({
|
||||
|
||||
@@ -25,6 +25,7 @@ import { UserWorkspaceModule } from 'src/engine/core-modules/user-workspace/user
|
||||
import { UserEntity } from 'src/engine/core-modules/user/user.entity';
|
||||
import { CheckCustomDomainValidRecordsCronCommand } from 'src/engine/core-modules/workspace/crons/commands/check-custom-domain-valid-records.cron.command';
|
||||
import { CheckCustomDomainValidRecordsCronJob } from 'src/engine/core-modules/workspace/crons/jobs/check-custom-domain-valid-records.cron.job';
|
||||
import { UpgradeModule } from 'src/engine/core-modules/upgrade/upgrade.module';
|
||||
import { CoreEntityCacheModule } from 'src/engine/core-entity-cache/core-entity-cache.module';
|
||||
import { WorkspaceEntityCacheProviderService } from 'src/engine/core-modules/workspace/services/workspace-entity-cache-provider.service';
|
||||
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
|
||||
@@ -83,6 +84,7 @@ import { StandardObjectsPrefillModule } from 'src/engine/workspace-manager/stand
|
||||
EnterpriseModule,
|
||||
StandardObjectsPrefillModule,
|
||||
CoreEntityCacheModule,
|
||||
UpgradeModule,
|
||||
],
|
||||
services: [WorkspaceService],
|
||||
resolvers: workspaceAutoResolverOpts,
|
||||
|
||||
Reference in New Issue
Block a user