Skip to content

Commit

Permalink
[HOTFIX] Migration to remove translations v1 traces (#6200)
Browse files Browse the repository at this point in the history
* migration to remove translations v1 traces

* bump version

* fix check-translations

* fix eslint
  • Loading branch information
daneryl authored Oct 16, 2023
1 parent 0dc4a79 commit 3d4eb03
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
delta: 146,

name: 'remove_translationsv2_traces',

description: 'remove translations collection and translations updatelogs',

reindex: false,

async up(db) {
process.stdout.write(`${this.name}...\r\n`);
await db.collection('translations').drop();
await db.collection('updatelogs').deleteMany({ namespace: 'translations' });
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import testingDB from 'api/utils/testing_db';
import migration from '../index.js';
import { fixtures } from './fixtures.js';

describe('migration remove_translationsv2_traces', () => {
beforeEach(async () => {
jest.spyOn(process.stdout, 'write').mockImplementation(() => {});
await testingDB.setupFixturesAndContext(fixtures);
});

afterAll(async () => {
await testingDB.tearDown();
});

it('should have a delta number', () => {
expect(migration.delta).toBe(146);
});

it('should check if a reindex is needed', async () => {
expect(migration.reindex).toBe(false);
});

it('should delete translations collection', async () => {
await migration.up(testingDB.mongodb);
const collectionNames = (await testingDB.mongodb.listCollections().toArray()).map(c => c.name);
expect(collectionNames.includes('translations')).toBe(false);
});

it('should delete all translations entries in updatelogs', async () => {
await migration.up(testingDB.mongodb);
const updatelogs = await testingDB.mongodb.collection('updatelogs').find().toArray();
expect(updatelogs).toMatchObject([{ namespace: 'migrations' }, { namespace: 'entities' }]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const fixtures = {
translations: [{}],
updatelogs: [
{ namespace: 'migrations' },
{ namespace: 'translations' },
{ namespace: 'entities' },
{ namespace: 'translations' },
],
};
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.138.0",
"version": "1.138.1",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down
6 changes: 2 additions & 4 deletions scripts/checkTranslations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@ const getClient = async () => {
const getSystemUITranslations = async () => {
const client = await getClient();
const db = client.db(process.env.DATABASE_NAME || 'uwazi_development');
const collection = db.collection('translations');
const [firstTranslation] = await collection.find().toArray();
const systemContext = firstTranslation.contexts.find(c => c.id === 'System');
const collection = db.collection('translationsV2');
const translations = await collection.find({ 'context.id': 'System' }).toArray();
client.close();
const translations = systemContext.values;
const comparableTranslations = translations.map(t => ({
...t,
plainValue: comparableString(t.value),
Expand Down

0 comments on commit 3d4eb03

Please sign in to comment.