Added prefer option for entity resolution. Merged migrations.

This commit is contained in:
DebaucheryLibrarian 2023-07-01 22:24:21 +02:00
parent 744bdb3170
commit a2331bc913
4 changed files with 11 additions and 22 deletions

View File

@ -273,6 +273,7 @@ exports.up = (knex) => Promise.resolve()
table.integer('age', 3); table.integer('age', 3);
table.text('gender', 18); table.text('gender', 18);
table.text('orientation');
table.text('description'); table.text('description');
table.text('birth_city'); table.text('birth_city');
@ -346,6 +347,7 @@ exports.up = (knex) => Promise.resolve()
table.text('real_name'); table.text('real_name');
table.text('gender', 18); table.text('gender', 18);
table.text('orientation');
table.date('date_of_birth'); table.date('date_of_birth');
table.date('date_of_death'); table.date('date_of_death');

View File

@ -1,19 +0,0 @@
exports.up = async (knex) => {
await knex.schema.alterTable('actors', (table) => {
table.text('orientation');
});
await knex.schema.alterTable('actors_profiles', (table) => {
table.text('orientation');
});
};
exports.down = async (knex) => {
await knex.schema.alterTable('actors', (table) => {
table.dropColumn('orientation');
});
await knex.schema.alterTable('actors_profiles', (table) => {
table.dropColumn('orientation');
});
};

View File

@ -244,6 +244,12 @@ const { argv } = yargs
type: 'string', type: 'string',
default: process.env.NODE_ENV === 'development' ? 'silly' : 'info', default: process.env.NODE_ENV === 'development' ? 'silly' : 'info',
}) })
.option('prefer-entity', {
alias: 'prefer',
describe: 'Prefer network or channel when resolving entities with the same identifier.',
choices: ['channel', 'network'],
type: 'string',
})
.option('resolve-place', { .option('resolve-place', {
describe: 'Call OSM Nominatim API for actor place of birth and residence. Raw value discarded if disabled.', describe: 'Call OSM Nominatim API for actor place of birth and residence. Raw value discarded if disabled.',
type: 'boolean', type: 'boolean',

View File

@ -199,7 +199,7 @@ async function fetchIncludedEntities() {
return curatedNetworks; return curatedNetworks;
} }
async function fetchEntitiesBySlug(entitySlugs, sort = 'asc') { async function fetchEntitiesBySlug(entitySlugs, prefer = 'channel') {
const entities = await knex.raw(` const entities = await knex.raw(`
WITH RECURSIVE entity_tree as ( WITH RECURSIVE entity_tree as (
SELECT to_jsonb(entities) as entity, SELECT to_jsonb(entities) as entity,
@ -235,7 +235,7 @@ async function fetchEntitiesBySlug(entitySlugs, sort = 'asc') {
`, { `, {
entitySlugs: entitySlugs.filter((slug) => !slug.includes('.')), entitySlugs: entitySlugs.filter((slug) => !slug.includes('.')),
entityHosts: entitySlugs.filter((slug) => slug.includes('.')).map((hostname) => `%${hostname}%`), entityHosts: entitySlugs.filter((slug) => slug.includes('.')).map((hostname) => `%${hostname}%`),
sort: knex.raw(sort), sort: knex.raw(prefer === 'channel' ? 'asc' : 'desc'),
}); });
// channel entity will overwrite network entity // channel entity will overwrite network entity
@ -262,7 +262,7 @@ async function fetchReleaseEntities(baseReleases) {
.filter(Boolean), .filter(Boolean),
)); ));
return fetchEntitiesBySlug(entitySlugs, 'desc'); return fetchEntitiesBySlug(entitySlugs, argv.prefer || 'network');
} }
async function fetchEntity(entityId, type) { async function fetchEntity(entityId, type) {