Added relation sharing table.

This commit is contained in:
DebaucheryLibrarian
2026-11-26 00:24:20 +01:00
parent bf6adf4ef1
commit 450f91c0d2
2 changed files with 47 additions and 1 deletions
@@ -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');
});
};
+1 -1
View File
@@ -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)