Added selectable tag function for actors. Implemented experimental filtering by tag.
This commit is contained in:
@@ -147,12 +147,15 @@ exports.up = knex => Promise.resolve()
|
||||
table.text('type')
|
||||
.primary();
|
||||
}))
|
||||
.then(() => knex('entities_types').insert([
|
||||
{ type: 'network' },
|
||||
{ type: 'channel' },
|
||||
{ type: 'studio' },
|
||||
{ type: 'info' },
|
||||
]))
|
||||
.then(() => { // eslint-disable-line arrow-body-style
|
||||
// allow vim fold
|
||||
return knex('entities_types').insert([
|
||||
{ type: 'network' },
|
||||
{ type: 'channel' },
|
||||
{ type: 'studio' },
|
||||
{ type: 'info' },
|
||||
]);
|
||||
})
|
||||
.then(() => knex.schema.createTable('entities', (table) => {
|
||||
table.increments('id', 12);
|
||||
|
||||
@@ -756,6 +759,7 @@ exports.up = knex => Promise.resolve()
|
||||
.references('id')
|
||||
.inTable('releases');
|
||||
}))
|
||||
// SEARCH
|
||||
.then(() => { // eslint-disable-line arrow-body-style
|
||||
// allow vim fold
|
||||
return knex.raw(`
|
||||
@@ -771,15 +775,25 @@ exports.up = knex => Promise.resolve()
|
||||
ALTER TABLE releases_search
|
||||
ADD COLUMN document tsvector;
|
||||
|
||||
ALTER TEXT SEARCH CONFIGURATION traxxx
|
||||
ALTER MAPPING FOR word, numword, hword, numhword, hword_part, hword_numpart, asciiword, asciihword, hword_asciipart WITH traxxx_dict, simple, english_stem;
|
||||
`);
|
||||
})
|
||||
// INDEXES
|
||||
.then(() => { // eslint-disable-line arrow-body-style
|
||||
// allow vim fold
|
||||
return knex.raw(`
|
||||
CREATE UNIQUE INDEX unique_actor_slugs_network ON actors (slug, entity_id);
|
||||
CREATE UNIQUE INDEX unique_actor_slugs ON actors (slug, (entity_id IS NULL));
|
||||
|
||||
ALTER TEXT SEARCH CONFIGURATION traxxx
|
||||
ALTER MAPPING FOR word, numword, hword, numhword, hword_part, hword_numpart, asciiword, asciihword, hword_asciipart WITH traxxx_dict, simple, english_stem;
|
||||
|
||||
CREATE UNIQUE INDEX releases_search_unique ON releases_search (release_id);
|
||||
CREATE INDEX releases_search_index ON releases_search USING GIN (document);
|
||||
|
||||
`);
|
||||
})
|
||||
// FUNCTIONS
|
||||
.then(() => { // eslint-disable-line arrow-body-style
|
||||
// allow vim fold
|
||||
return knex.raw(`
|
||||
CREATE FUNCTION search_releases(query text) RETURNS SETOF releases AS $$
|
||||
SELECT * FROM releases WHERE releases.id IN (
|
||||
SELECT release_id FROM releases_search AS search
|
||||
@@ -802,10 +816,33 @@ exports.up = knex => Promise.resolve()
|
||||
AND name ILIKE ('%' || search || '%')
|
||||
$$ LANGUAGE SQL STABLE;
|
||||
|
||||
CREATE FUNCTION actors_tags(actor actors, selectable_tags text[]) RETURNS SETOF tags AS $$
|
||||
SELECT tags.*
|
||||
FROM releases_actors
|
||||
LEFT JOIN
|
||||
releases_tags ON releases_tags.release_id = releases_actors.release_id
|
||||
LEFT JOIN
|
||||
tags ON tags.id = releases_tags.tag_id
|
||||
WHERE
|
||||
releases_actors.actor_id = actor.id
|
||||
AND
|
||||
CASE WHEN array_length(selectable_tags, 1) IS NOT NULL
|
||||
THEN tags.slug = ANY(selectable_tags)
|
||||
ELSE true
|
||||
END
|
||||
GROUP BY tags.id
|
||||
ORDER BY tags.name;
|
||||
$$ LANGUAGE SQL STABLE;
|
||||
|
||||
CREATE FUNCTION releases_is_new(release releases) RETURNS boolean AS $$
|
||||
SELECT EXISTS(SELECT true WHERE (SELECT id FROM batches ORDER BY created_at DESC LIMIT 1) = release.created_batch_id);
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
`);
|
||||
})
|
||||
// VIEWS AND COMMENTS
|
||||
.then(() => { // eslint-disable-line arrow-body-style
|
||||
// allow vim fold
|
||||
return knex.raw(`
|
||||
CREATE VIEW movie_actors AS
|
||||
SELECT releases_movies.movie_id, releases_actors.actor_id FROM releases_movies
|
||||
LEFT JOIN releases ON releases.id = releases_movies.scene_id
|
||||
@@ -881,6 +918,9 @@ exports.down = (knex) => { // eslint-disable-line arrow-body-style
|
||||
DROP FUNCTION IF EXISTS search_actors;
|
||||
DROP FUNCTION IF EXISTS get_random_sfw_media_id;
|
||||
|
||||
DROP FUNCTION IF EXISTS releases_is_new;
|
||||
DROP FUNCTION IF EXISTS actors_tags;
|
||||
|
||||
DROP TEXT SEARCH CONFIGURATION IF EXISTS traxxx;
|
||||
DROP TEXT SEARCH DICTIONARY IF EXISTS traxxx_dict;
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user