From 450f91c0d24307f44e0c088492e8cb07f388416f Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Thu, 26 Nov 2026 00:24:20 +0100 Subject: [PATCH] Added relation sharing table. --- ...20261124120000_scenes_relations_sharing.js | 46 +++++++++++++++++++ src/store-releases.js | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 migrations/20261124120000_scenes_relations_sharing.js diff --git a/migrations/20261124120000_scenes_relations_sharing.js b/migrations/20261124120000_scenes_relations_sharing.js new file mode 100644 index 00000000..748abcbb --- /dev/null +++ b/migrations/20261124120000_scenes_relations_sharing.js @@ -0,0 +1,46 @@ +// which scene receives actors, tags or duration from the other when a relation is shared: 'source' (the derivation or compilation), 'target' (the original or compilation part) or 'both', omitted fields are not shared by default +// sharing is a one-time copy through revisions, these only preselect the options in the relation dialog +const shareDefaults = { + rerelease: { actors: 'both', tags: 'both', duration: 'source' }, + variant: { actors: 'both', tags: 'both' }, + remaster: { actors: 'source', tags: 'source' }, + reedit: { actors: 'source', tags: 'source' }, + bts: { actors: 'source' }, + compilation: { actors: 'source' }, +}; + +exports.up = async function(knex) { + await knex.schema.alterTable('relations_types', (table) => { + table.jsonb('share_defaults') + .notNullable() + .defaultTo('{}'); + }); + + await Object.entries(shareDefaults).reduce(async (chain, [type, defaults]) => { + await chain; + + await knex('relations_types') + .where('type', type) + .update('share_defaults', JSON.stringify(defaults)); + }, Promise.resolve()); + + await knex.schema.alterTable('scenes_revisions', (table) => { + // revisions generated for related scenes when a relation is shared, reviewed and applied together with their parent + table.integer('parent_revision_id') + .references('id') + .inTable('scenes_revisions') + .onDelete('cascade'); + + table.index('parent_revision_id'); + }); +}; + +exports.down = async function(knex) { + await knex.schema.alterTable('scenes_revisions', (table) => { + table.dropColumn('parent_revision_id'); + }); + + await knex.schema.alterTable('relations_types', (table) => { + table.dropColumn('share_defaults'); + }); +}; diff --git a/src/store-releases.js b/src/store-releases.js index f56182ec..eacbd2d9 100755 --- a/src/store-releases.js +++ b/src/store-releases.js @@ -480,7 +480,7 @@ async function storeScenes(releases, useBatchId) { language_alpha2 = COALESCE(new.language_alpha2, releases.language_alpha2), comment = COALESCE(NULLIF(new.comment, ''), releases.comment), attributes = COALESCE(releases.attributes::jsonb || new.attributes::jsonb, new.attributes::jsonb, releases.attributes::jsonb), -- new keys overwrite stored ones - deep = new.url IS NOT NULL, + deep = releases.deep OR new.deep, deep_url = COALESCE(NULLIF(new.deep_url, ''), releases.deep_url), updated_at = NOW() FROM json_to_recordset(:scenes)