chore: adjust the column type and fix some tetss

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-11-05 13:37:15 +01:00
parent 53b90600df
commit 4eb0475795
6 changed files with 19 additions and 9 deletions
@@ -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');
});
};
@@ -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',
},
@@ -69,6 +69,7 @@ describe('deleteOrphanedEntities', () => {
await knex<DbFinalEntitiesRow>('final_entities').insert({
entity_id: `id-${ref}`,
hash: 'original',
entity_ref: ref,
stitch_ticket: '',
});
}
@@ -204,6 +204,7 @@ describe('DefaultLocationStore', () => {
hash: 'hash',
last_updated_at: new Date(),
stitch_ticket: '',
entity_ref: 'k:ns/n',
});
await knex<DbSearchRow>('search').insert({
@@ -114,6 +114,7 @@ describe('DefaultEntitiesCatalog', () => {
await knex<DbFinalEntitiesRow>('final_entities').insert({
entity_id: id,
entity_ref: entityRef,
final_entity: entityJson,
hash: 'h',
stitch_ticket: '',
@@ -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(