Skip to content

Commit

Permalink
add migrations to apply reindex
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao-vi committed Oct 17, 2024
1 parent 73873c1 commit b4de38a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Db } from 'mongodb';

export default {
delta: 169,

name: 'reindex_persist_filename_with_fullText_object',

description:
"We're now indexing document.filename within the fullText object on elasticsearch, this is usefull because on search/v2 endpoint we need to return which filename each text snippet belongs to.",

reindex: true,

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async up(db: Db) {
process.stdout.write(`${this.name}...\r\n`);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Db } from 'mongodb';

import testingDB from 'api/utils/testing_db';
import migration from '../index';
import { Fixture } from '../types';
import { fixtures } from './fixtures';

let db: Db | null;

const initTest = async (fixture: Fixture) => {
await testingDB.setupFixturesAndContext(fixture);
db = testingDB.mongodb!;
await migration.up(db);
};

beforeAll(async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
jest.spyOn(process.stdout, 'write').mockImplementation((str: string | Uint8Array) => true);
});

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

describe('migration test', () => {
beforeAll(async () => {
await initTest(fixtures);
});

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

it('should check if a reindex is needed', async () => {
expect(migration.reindex).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from 'mongodb';
import { Fixture } from '../types';

const fixtures: Fixture = {
entities: [
{
_id: new ObjectId(),
title: 'test_doc',
},
],
};

export { fixtures };
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ObjectId } from 'mongodb';

interface Entity {
_id: ObjectId;
title: string;
[k: string]: unknown | undefined;
}

interface Fixture {
entities: Entity[];
}

export type { Entity, Fixture };

0 comments on commit b4de38a

Please sign in to comment.