Skip to content

Commit

Permalink
Merge pull request #3965 from huridocs/migration53_hotfix
Browse files Browse the repository at this point in the history
migration 53 hotpatch
  • Loading branch information
RafaPolit authored Oct 13, 2021
2 parents 2167c9b + 3d9112a commit 529682e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,9 @@ export default {

name: 'delete-orphaned-connections',

description: 'Removes all orphaned connections',
description: 'Hot Patched to do nothing',

async up(db) {
// For every connection, check if the entity connected exists
// If the entity does not exist, delete the connection
// Check whether there is only one connections in the hub contained in the connection
// If there is only one connection, delete that connection
const cursor = await db.collection('connections').find({});

while (await cursor.hasNext()) {
const connection = await cursor.next();
const { hub: hubId, entity: sharedId } = connection;

// Checking if entity exists
const entity = await db.collection('entities').findOne({ sharedId });
if (!entity) {
await db.collection('connections').deleteOne({ _id: connection._id });
}

const connectionsInHub = await db.collection('connections').find({ hub: hubId });
const count = await connectionsInHub.count();
if (count === 1) {
const { _id } = await connectionsInHub.next();
await db.collection('connections').deleteOne({ _id });
}
}
async up() {
process.stdout.write('Hot Patched to do nothing');
},
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import testingDB from 'api/utils/testing_db';
import migration from '../index.js';
import fixtures from './fixtures.js';

describe('migration delete-orphaned-connections', () => {
beforeEach(async () => {
spyOn(process.stdout, 'write');
await testingDB.clearAllAndLoad(fixtures);
});

afterAll(async () => {
Expand All @@ -17,22 +15,6 @@ describe('migration delete-orphaned-connections', () => {
});

it('should delete all connections which do not have an existing entity', async () => {
await migration.up(testingDB.mongodb);
const connections = await testingDB.mongodb
.collection('connections')
.find()
.toArray();
expect(connections.length).toBe(3);
});

it('should delete all connections who are alone in a hub', async () => {
await migration.up(testingDB.mongodb);
const connections = await testingDB.mongodb
.collection('connections')
.find()
.toArray();
expect(connections).toEqual(
expect.arrayContaining([expect.not.objectContaining({ hub: 'hub3' })])
);
expect(migration.description).toBe('Hot Patched to do nothing');
});
});
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
export default {
entities: [
{
sharedId: 'sharedid1',
title: 'test_doc',
},
{
sharedId: 'sharedid2',
title: 'test_doc_2',
},
{
sharedId: 'sharedid1',
title: 'test_doc',
},
{
sharedId: 'sharedid3',
title: 'test_doc_2',
},
{
sharedId: 'sharedid1',
title: 'test_doc',
},
{
sharedId: 'sharedid3',
title: 'test_doc_2',
},
],
connections: [
{
entity: 'sharedid3',
hub: 'hub1',
},
{
entity: 'sharedid1',
hub: 'hub1',
},
{
entity: 'sharedid2',
hub: 'hub1',
},
{
entity: 'sharedid3',
hub: 'hub2',
},
{
entity: 'sharedid1',
hub: 'hub3',
},
{
entity: 'shareid4',
hub: 'hub3',
},
],
entities: [],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.40.0",
"version": "1.40.1",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down

0 comments on commit 529682e

Please sign in to comment.