Skip to content

Dictionary migration - Part 2 - Execution migration#183

Open
leoraba wants to merge 13 commits intofeat/dictionary_migration_dbfrom
feat/migration_implementation
Open

Dictionary migration - Part 2 - Execution migration#183
leoraba wants to merge 13 commits intofeat/dictionary_migration_dbfrom
feat/migration_implementation

Conversation

@leoraba
Copy link
Copy Markdown
Contributor

@leoraba leoraba commented Jan 9, 2026

Summary

Dictionary migration implementation, PR 2 of #175

This PR depends on:

@leoraba leoraba marked this pull request as draft January 9, 2026 16:22
@leoraba leoraba changed the base branch from feat/dictionary_migration to feat/dictionary_migration_db January 29, 2026 14:16
@leoraba leoraba marked this pull request as ready for review February 3, 2026 14:15
@leoraba leoraba marked this pull request as draft April 1, 2026 13:19
Comment on lines +474 to +477
migrationId:
type: string
description: ID of the Migration if applicable
allowEmptyValue: true
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New optional field in the response registering a new dictionary.

Comment on lines +414 to +421
data: Partial<SubmittedData>;
audit: {
dataDiff: DataDiff;
errors?: DictionaryValidationRecordErrorDetails[];
isMigration: boolean;
oldIsValid: boolean;
submissionId: number;
};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding 2 new properties errors and isMigration in the args, grouping values used for auditing

// This ensures the main thread is not affected by worker errors and can continue processing other tasks.
}
},
dictionaryMigration: async (input) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the entry point function to be used to start a working thread to handle the dictionary migration.

Comment on lines +153 to +160
* **This function is designed to be executed in a worker thread.**
* Performs the Submitted data validation for a given migration,
* it iterates over all organizations and validates the submitted data for each of them.
* @param migrationId The ID of the migration to perform
* @param userName The name of the user that initiated the migration (for audit purposes)
* @returns void
*/
const performMigrationValidation = async ({
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a tsdoc to indicate the reason why this function is intended to by called on a worker thread

@leoraba leoraba marked this pull request as ready for review April 14, 2026 15:35
@leoraba leoraba changed the title Feat/migration implementation Dictionary migration - Part 1 - Execution migration Apr 14, 2026
@leoraba leoraba changed the title Dictionary migration - Part 1 - Execution migration Dictionary migration - Part 2 - Execution migration Apr 14, 2026
@leoraba leoraba linked an issue Apr 16, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@JamesTLopez JamesTLopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a small thought but optional, otherwise lgtm

Copy link
Copy Markdown
Contributor

@joneubank joneubank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, have a couple small items to look at. Thanks!

if (submisionUpdateData) {
logger.info(LOG_MODULE, `Updating submittedData system ID '${data.systemId}' in entity '${entityName}'`);
inputUpdate.data = data.data;
logger.info(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be debug level, we expect a lot of records to be updated in a migration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having a hard time reviewing the many changes to performCommitSubmissionAsync, the submission process is long with many steps and since its all inline with many checks for empty values or errors there is a lot of error handling mixed in with actual actions. Its likely that the processes could be separated into functions for each step, or more comments added to outline the process that is performed. This is likely a refactoring process separate from this PR.

Comment on lines +18 to +23
migrationService.finalizeMigration({
migrationId,
status: 'FAILED',
userName,
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This finalize will likely fail for the same reason that caused it to throw an error the first time, but there is no error handling in place for this call. Will this crash the server? What is the expected outcome here?

Comment on lines +17 to +30
/**
* Update the status of the migration to COMPLETED or FAILED
* @param param0
* @returns The ID of the finalized migration
*/
const finalizeMigration = async ({
migrationId,
status,
userName,
}: {
migrationId: number;
status: Extract<MigrationStatus, 'COMPLETED' | 'FAILED'>;
userName: string;
}): Promise<number> => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why return the migrationId?, thats one of the input parameters. Also, the only place that calls this does not use the returned value.

This could easily return Promise<void>.

Should this return a Result instead of throwing?

Comment on lines +147 to +152
const migrationId = await initiateMigration({
categoryId: updatedCategory.id,
fromDictionaryId: foundCategory.activeDictionaryId,
toDictionaryId: savedDictionary.id,
userName: username || '',
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initiateMigration throws on failure. Should this be in a try/catch? Maybe it should return a Result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Part 1 - Data migration] Trigger Data category migration.

3 participants