Skip to content

Commit

Permalink
[backend] fix max shareable markings migrations (#7392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit committed Jun 19, 2024
1 parent f97dbe0 commit 480922b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { executionContext, SYSTEM_USER } from '../utils/access';
import { getSettings, settingsEditField } from '../domain/settings';
import { logApp } from '../config/conf';
// import { executionContext, SYSTEM_USER } from '../utils/access';
// import { getSettings, settingsEditField } from '../domain/settings';
// import { logApp } from '../config/conf';

export const up = async (next) => {
logApp.info('[MIGRATION] Add platform data sharing max markings');
const context = executionContext('migration');
// ----- Explanations ----------
// This migration has been removed
// because platform_data_sharing_max_markings does not exist anymore since version 6.1.11
// -----------------------------

// -------- Old code -----------
// logApp.info('[MIGRATION] Add platform data sharing max markings');
// const context = executionContext('migration');
// ------ Add platform_data_sharing_max_markings
const settings = await getSettings(context);
const patch = [{ key: 'platform_data_sharing_max_markings', value: [] }];
await settingsEditField(context, SYSTEM_USER, settings.id, patch);
logApp.info('[MIGRATION] Add platform data sharing max markings done.');
// const settings = await getSettings(context);
// const patch = [{ key: 'platform_data_sharing_max_markings', value: [] }];
// await settingsEditField(context, SYSTEM_USER, settings.id, patch);
// logApp.info('[MIGRATION] Add platform data sharing max markings done.');
next();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export const up = async (next) => {

await Promise.all(groupMaxMarkingRelationCreationsPromises);

// remove platform_data_sharing_max_markings from settings
// set platform_data_sharing_max_markings to null in settings
const updateQuery = {
script: {
params: { null: null },
source: 'ctx._source.platform_data_sharing_max_markings = params.null',
params: { fieldToRemove: 'platform_data_sharing_max_markings' },
source: 'ctx._source.remove(params.fieldToRemove)',
},
query: {
bool: {
Expand All @@ -64,11 +64,10 @@ export const up = async (next) => {
};
await elUpdateByQueryForMigration(
message,
[READ_INDEX_INTERNAL_OBJECTS],
READ_INDEX_INTERNAL_OBJECTS,
updateQuery
);

// do your migration
logApp.info(`${message} > done`);
next();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { logApp } from '../config/conf';
import { elUpdateByQueryForMigration } from '../database/engine';
import { READ_INDEX_INTERNAL_OBJECTS } from '../database/utils';

const message = '[MIGRATION] Remove platform_max_shareable_markings field from Settings';

export const up = async (next) => {
logApp.info(`${message} > started`);
const updateQuery = {
script: {
params: { fieldToRemove: 'platform_data_sharing_max_markings' },
source: 'ctx._source.remove(params.fieldToRemove)',
},
query: {
bool: {
must: [
{ term: { 'entity_type.keyword': { value: 'Settings' } } },
],
},
},
};
await elUpdateByQueryForMigration(
message,
READ_INDEX_INTERNAL_OBJECTS,
updateQuery
);
logApp.info(`${message} > done`);
next();
};

export const down = async (next) => {
next();
};

0 comments on commit 480922b

Please sign in to comment.