Skip to content

Commit 5203420

Browse files
Remove automated cleanup of config tables during migration (#476)
1 parent 755f0fa commit 5203420

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

messages/assess.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,5 @@
232232
"processingNotRequired": "Assessment is not required for orgs on standard data model with the Omnistudio Metadata setting turned on.",
233233
"skippingTruncation": "Skipping truncation as the org is on standard data model.",
234234
"loglevelFlagDeprecated": "loglevel is deprecated. Use --verbose instead",
235-
"cleanupMetadataTablesRequired": "Omnistudio configuration tables contain records. Manually clean up the tables.\n<a href='https://help.salesforce.com/s/articleView?id=xcloud.os_enable_omnistudio_metadata_api_support.htm&type=5' target='_blank'>Cleanup Metadata Tables</a>"
235+
"cleanupMetadataTablesRequired": "Omnistudio configuration tables contain records. Back up your Omnistudio component table data, and manually clean up the Omnistudio configuration tables. <a href='https://help.salesforce.com/s/articleView?id=xcloud.os_enable_omnistudio_metadata_api_support.htm&type=5' target='_blank'>Learn more about cleaning up tables in Salesforce Help</a>"
236236
}

messages/migrate.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@
297297
"deploymentTriggeredSuccessfully": "Please monitor your Deployment: %s using deployment status page in Org",
298298
"omniscriptPackageDeploymentFailedReturnedFalse": "Omniscript package deployment failed - deployment returned false. This may be due to missing package, permissions, or deployment timeout.",
299299
"omniscriptPackageDeploymentFailedWithMessage": "Omniscript package deployment failed: %s",
300+
"cleanupMetadataTablesRequired": "Omnistudio configuration tables contain records. The migration can't proceed. Records on these configuration tables block the Omnistudio Metadata setting from being enabled. Back up your Omnistudio component table data, manually clean up the Omnistudio configuration tables, and validate before running the migration.",
301+
"cleanupMetadataTablesHelpUrl": "https://help.salesforce.com/s/articleView?id=xcloud.os_enable_omnistudio_metadata_api_support.htm&type=5",
302+
"cleanupMetadataTablesHelpLinkText": "Learn more about cleaning up tables in Salesforce Help",
300303
"metadataTablesAlreadyClean": "OmniStudio metadata tables are empty",
301304
"startingMetadataCleanup": "Initiated cleanup process for Omnistudio metadata tables.",
302305
"failedToCleanTables": "Table cleanup failed: %s, Please contact Salesforce Support.",

src/migration/premigrate.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class PreMigrate extends BaseMigrationTool {
5353
}
5454

5555
// Handle config tables cleanup for standard data model migration
56-
const isMetadataCleanupSuccess = await this.handleOmniStudioMetadataCleanup();
57-
if (!isMetadataCleanupSuccess) {
56+
const isMetadataTablesValid = await this.validateOmniStudioMetadataTables();
57+
if (!isMetadataTablesValid) {
5858
process.exit(1);
5959
}
6060
}
@@ -186,11 +186,11 @@ export class PreMigrate extends BaseMigrationTool {
186186
}
187187

188188
/**
189-
* Handles OmniStudio metadata tables cleanup with user consent
189+
* Validates that OmniStudio metadata tables are clean before migration can proceed.
190190
*
191-
* @returns Promise<boolean> - true if cleanup was successful, false otherwise
191+
* @returns Promise<boolean> - true if tables are clean and migration can proceed, false otherwise
192192
*/
193-
public async handleOmniStudioMetadataCleanup(): Promise<boolean> {
193+
public async validateOmniStudioMetadataTables(): Promise<boolean> {
194194
if (isStandardDataModelWithMetadataAPIEnabled()) {
195195
return true;
196196
}
@@ -200,14 +200,11 @@ export class PreMigrate extends BaseMigrationTool {
200200
Logger.logVerbose(this.messages.getMessage('metadataTablesAlreadyClean'));
201201
return true;
202202
}
203-
204-
const consent = await this.getMetadataCleanupConsent();
205-
206-
if (!consent) {
207-
Logger.error(this.messages.getMessage('metadataCleanupConsentNotGiven'));
208-
return false;
209-
}
210-
return await omniStudioMetadataCleanupService.cleanupOmniStudioMetadataTables();
203+
const helpUrl = this.messages.getMessage('cleanupMetadataTablesHelpUrl');
204+
const helpLinkText = this.messages.getMessage('cleanupMetadataTablesHelpLinkText');
205+
const clickableLink = `\x1b]8;;${helpUrl}\x1b\\${helpLinkText}\x1b]8;;\x1b\\`;
206+
Logger.error(`${this.messages.getMessage('cleanupMetadataTablesRequired')} ${clickableLink}`);
207+
return false;
211208
}
212209

213210
private async checkLwcDeployPrerequisites(
@@ -319,6 +316,8 @@ export class PreMigrate extends BaseMigrationTool {
319316
*
320317
* @returns Promise<boolean> - true if user consents, false otherwise
321318
*/
319+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
320+
// @ts-ignore TS6133: kept intentionally for future metadata cleanup flow.
322321
private async getMetadataCleanupConsent(): Promise<boolean> {
323322
const askWithTimeOut = PromptUtil.askWithTimeOut(this.messages);
324323
let validResponse = false;

test/migration/premigrate.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import sinon = require('sinon');
99
import { PreMigrate } from '../../src/migration/premigrate';
1010
import { Logger } from '../../src/utils/logger';
1111
import { PromptUtil } from '../../src/utils/promptUtil';
12+
import { OmniStudioMetadataCleanupService } from '../../src/utils/config/OmniStudioMetadataCleanupService';
13+
import * as dataModelService from '../../src/utils/dataModelService';
1214

1315
describe('PreMigrate - handleAllVersionsPrerequisites for Standard Data Model', () => {
1416
let preMigrate: PreMigrate;
@@ -121,4 +123,31 @@ describe('PreMigrate - handleAllVersionsPrerequisites for Standard Data Model',
121123
expect(processExitStub.called).to.be.false;
122124
});
123125
});
126+
127+
describe('OmniStudio metadata prerequisites', () => {
128+
it('should log cleanup required and exit when config tables are not empty', async () => {
129+
// Arrange
130+
const expectedMessage = 'Omnistudio configuration tables contain records.';
131+
getMessageStub.withArgs('cleanupMetadataTablesRequired').returns(expectedMessage);
132+
getMessageStub
133+
.withArgs('cleanupMetadataTablesHelpUrl')
134+
.returns(
135+
'https://help.salesforce.com/s/articleView?id=xcloud.os_enable_omnistudio_metadata_api_support.htm&type=5'
136+
);
137+
getMessageStub
138+
.withArgs('cleanupMetadataTablesHelpLinkText')
139+
.returns('Learn more about cleaning up tables in Salesforce Help');
140+
sandbox.stub(dataModelService, 'isStandardDataModelWithMetadataAPIEnabled').returns(false);
141+
sandbox.stub(preMigrate, 'getOmniStudioMetadataEnableConsent').resolves(true);
142+
sandbox.stub(OmniStudioMetadataCleanupService.prototype, 'hasCleanOmniStudioMetadataTables').resolves(false);
143+
144+
// Act
145+
await preMigrate.handleOmnistudioMetadataPrerequisites();
146+
147+
// Assert - Logger.error is called with the message + ANSI clickable link appended
148+
expect(logErrorStub.calledOnce).to.be.true;
149+
expect((logErrorStub.firstCall.args[0] as string).startsWith(expectedMessage)).to.be.true;
150+
expect(processExitStub.calledWith(1)).to.be.true;
151+
});
152+
});
124153
});

0 commit comments

Comments
 (0)