From 4eb0475795c43a263bf89ab43bdc27f579a8440f Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 5 Nov 2024 13:37:15 +0100 Subject: [PATCH] chore: adjust the column type and fix some tetss Signed-off-by: blam --- ...20241024104700_add_entity_ref_to_final_entities.js | 10 ++++------ .../operations/stitcher/markForStitching.test.ts | 4 ++++ .../operations/util/deleteOrphanedEntities.test.ts | 1 + .../src/providers/DefaultLocationStore.test.ts | 1 + .../src/service/DefaultEntitiesCatalog.test.ts | 1 + plugins/catalog-backend/src/tests/migrations.test.ts | 11 ++++++++--- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/plugins/catalog-backend/migrations/20241024104700_add_entity_ref_to_final_entities.js b/plugins/catalog-backend/migrations/20241024104700_add_entity_ref_to_final_entities.js index 40d07a6860..962ea05e22 100644 --- a/plugins/catalog-backend/migrations/20241024104700_add_entity_ref_to_final_entities.js +++ b/plugins/catalog-backend/migrations/20241024104700_add_entity_ref_to_final_entities.js @@ -23,11 +23,9 @@ exports.up = async function up(knex) { await knex.schema.alterTable('final_entities', table => { table - .text('entity_ref') + .string('entity_ref') .nullable() - .comment( - 'The entity reference of the entity that was created from the catalog processing', - ); + .comment('The entity reference of the entity'); table.index('entity_ref', 'entity_ref_idx'); }); @@ -44,7 +42,7 @@ exports.up = async function up(knex) { // SQLite does not support ALTER COLUMN. if (!knex.client.config.client.includes('sqlite3')) { await knex.schema.alterTable('final_entities', table => { - table.text('entity_ref').notNullable().alter({ alterNullable: true }); + table.string('entity_ref').notNullable().alter({ alterNullable: true }); }); } }; @@ -55,7 +53,7 @@ exports.up = async function up(knex) { */ exports.down = async function down(knex) { await knex.schema.alterTable('final_entities', table => { - table.dropIndex('entity_ref_idx'); + table.dropIndex([], 'entity_ref_idx'); table.dropColumn('entity_ref'); }); }; diff --git a/plugins/catalog-backend/src/database/operations/stitcher/markForStitching.test.ts b/plugins/catalog-backend/src/database/operations/stitcher/markForStitching.test.ts index 011fe54e83..1afa0b9c30 100644 --- a/plugins/catalog-backend/src/database/operations/stitcher/markForStitching.test.ts +++ b/plugins/catalog-backend/src/database/operations/stitcher/markForStitching.test.ts @@ -252,24 +252,28 @@ describe('markForStitching', () => { { entity_id: '1', final_entity: '{}', + entity_ref: 'k:ns/one', hash: 'old', stitch_ticket: 'old', }, { entity_id: '2', final_entity: '{}', + entity_ref: 'k:ns/two', hash: 'old', stitch_ticket: 'old', }, { entity_id: '3', final_entity: '{}', + entity_ref: 'k:ns/three', hash: 'old', stitch_ticket: 'old', }, { entity_id: '4', final_entity: '{}', + entity_ref: 'k:ns/four', hash: 'old', stitch_ticket: 'old', }, diff --git a/plugins/catalog-backend/src/database/operations/util/deleteOrphanedEntities.test.ts b/plugins/catalog-backend/src/database/operations/util/deleteOrphanedEntities.test.ts index 1dc8a42d5f..0f4f5f0c3d 100644 --- a/plugins/catalog-backend/src/database/operations/util/deleteOrphanedEntities.test.ts +++ b/plugins/catalog-backend/src/database/operations/util/deleteOrphanedEntities.test.ts @@ -69,6 +69,7 @@ describe('deleteOrphanedEntities', () => { await knex('final_entities').insert({ entity_id: `id-${ref}`, hash: 'original', + entity_ref: ref, stitch_ticket: '', }); } diff --git a/plugins/catalog-backend/src/providers/DefaultLocationStore.test.ts b/plugins/catalog-backend/src/providers/DefaultLocationStore.test.ts index 4f302308ae..5e3f3e0b17 100644 --- a/plugins/catalog-backend/src/providers/DefaultLocationStore.test.ts +++ b/plugins/catalog-backend/src/providers/DefaultLocationStore.test.ts @@ -204,6 +204,7 @@ describe('DefaultLocationStore', () => { hash: 'hash', last_updated_at: new Date(), stitch_ticket: '', + entity_ref: 'k:ns/n', }); await knex('search').insert({ diff --git a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts index 5b369bfa41..1e795e9eb0 100644 --- a/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts +++ b/plugins/catalog-backend/src/service/DefaultEntitiesCatalog.test.ts @@ -114,6 +114,7 @@ describe('DefaultEntitiesCatalog', () => { await knex('final_entities').insert({ entity_id: id, + entity_ref: entityRef, final_entity: entityJson, hash: 'h', stitch_ticket: '', diff --git a/plugins/catalog-backend/src/tests/migrations.test.ts b/plugins/catalog-backend/src/tests/migrations.test.ts index 69e347bad0..5e92eda614 100644 --- a/plugins/catalog-backend/src/tests/migrations.test.ts +++ b/plugins/catalog-backend/src/tests/migrations.test.ts @@ -93,6 +93,7 @@ describe('migrations', () => { hash: 'h', stitch_ticket: '', final_entity: '{}', + entity_ref: 'k:ns/n1', }) .into('final_entities'); @@ -418,7 +419,7 @@ describe('migrations', () => { }) .into('refresh_state'); - // Insert a simple URL before the migration + // Insert a simple entity before the migration await knex .insert({ entity_id: '8222246a-b572-49cf-a702-1a0fcfaae901', @@ -428,11 +429,15 @@ describe('migrations', () => { }) .into('final_entities'); + // verify that the entity_ref column is not present + const preColumnInfo = await knex('final_entities').columnInfo(); + expect(preColumnInfo.entity_ref).toBeUndefined(); + await migrateUpOnce(knex); // verify that the entity_ref column has been added - const columnInfo = await knex('final_entities').columnInfo(); - expect(columnInfo.entity_ref).not.toBeUndefined(); + const afterColumnInfo = await knex('final_entities').columnInfo(); + expect(afterColumnInfo.entity_ref).not.toBeUndefined(); // verify that the contents of the entity_ref column are correct await expect(knex('final_entities')).resolves.toEqual(