Skip to content

Commit

Permalink
[backend] Migration to remove representative in DB (#7484)
Browse files Browse the repository at this point in the history
(cherry picked from commit af5f572)
  • Loading branch information
SouadHadjiat authored and Kedae committed Jun 28, 2024
1 parent 7aa1381 commit 9ae038c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion opencti-platform/opencti-graphql/src/database/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3605,7 +3605,7 @@ export const elUpdateElement = async (instance) => {
// If entity with a name, must update connections
let connectionPromise = Promise.resolve();
if (esData.name && isStixObject(instance.entity_type)) {
connectionPromise = elUpdateConnectionsOfElement(instance.internal_id, { name: esData.representative.main });
connectionPromise = elUpdateConnectionsOfElement(instance.internal_id, { name: extractEntityRepresentativeName(esData) });
}
return Promise.all([replacePromise, connectionPromise]);
};
Expand Down
3 changes: 1 addition & 2 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
UnsupportedError,
ValidationError
} from '../config/errors';
import { extractEntityRepresentativeName, extractRepresentative } from './entity-representative';
import { extractEntityRepresentativeName } from './entity-representative';
import {
buildPagination,
computeAverage,
Expand Down Expand Up @@ -854,7 +854,6 @@ const partialInstanceWithInputs = (instance, inputs) => {
_index: instance._index,
internal_id: instance.internal_id,
entity_type: instance.entity_type,
representative: extractRepresentative(instance),
...inputData,
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { logApp } from '../config/conf';
import { elUpdateByQueryForMigration } from '../database/engine';
import { READ_DATA_INDICES } from '../database/utils';

const message = '[MIGRATION] Remove representative field';

export const up = async (next) => {
logApp.info(`${message} > started`);
const updateQuery = {
script: {
params: { fieldToRemove: 'representative' },
source: 'ctx._source.remove(params.fieldToRemove)',
},
query: {
bool: {
must: [{ exists: { field: 'representative' } }],
},
},
};
await elUpdateByQueryForMigration(
message,
READ_DATA_INDICES,
updateQuery
);
logApp.info(`${message} > done`);
next();
};

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

0 comments on commit 9ae038c

Please sign in to comment.