Added stashes to Manticore search update.

This commit is contained in:
DebaucheryLibrarian
2024-03-15 00:57:28 +01:00
parent b96d996947
commit f83ea2436d
2417 changed files with 565 additions and 111 deletions

View File

@@ -2,9 +2,9 @@ exports.up = async function up(knex) {
await knex.raw(`
CREATE MATERIALIZED VIEW actors_meta AS (
SELECT
actors.*,
COUNT(DISTINCT stashes_actors) as stashed,
COUNT(DISTINCT releases_actors) as scenes,
actors.id as actor_id,
COUNT(DISTINCT stashes_actors)::integer as stashed,
COUNT(DISTINCT releases_actors)::integer as scenes,
row_to_json(avatars) as avatar
FROM actors
LEFT JOIN stashes_actors ON stashes_actors.actor_id = actors.id
@@ -17,12 +17,31 @@ exports.up = async function up(knex) {
CREATE MATERIALIZED VIEW scenes_meta AS (
SELECT
releases.*,
COUNT(DISTINCT stashes_scenes) as stashed
releases.id as scene_id,
COUNT(DISTINCT stashes_scenes)::integer as stashed
FROM releases
LEFT JOIN stashes_scenes ON stashes_scenes.scene_id = releases.id
GROUP BY releases.id
);
CREATE MATERIALIZED VIEW movies_meta AS (
SELECT
movie_id,
stashed,
stashed_scenes,
stashed + stashed_scenes as stashed_total
FROM (
SELECT
movies.id as movie_id,
COUNT(DISTINCT stashes_movies)::integer as stashed,
COUNT(DISTINCT stashes_scenes)::integer as stashed_scenes
FROM movies
LEFT JOIN stashes_movies ON stashes_movies.movie_id = movies.id
LEFT JOIN movies_scenes ON movies_scenes.movie_id = movies.id
LEFT JOIN stashes_scenes ON stashes_scenes.scene_id = movies_scenes.scene_id
GROUP BY movies.id
)
);
`);
};
@@ -30,5 +49,6 @@ exports.down = async function down(knex) {
await knex.raw(`
DROP MATERIALIZED VIEW IF EXISTS actors_meta;
DROP MATERIALIZED VIEW IF EXISTS scenes_meta;
DROP MATERIALIZED VIEW IF EXISTS movies_meta;
`);
};

View File

@@ -7,30 +7,119 @@ mantiClient.basePath = `http://${config.database.manticore.host}:${config.databa
const utilsApi = new manticore.UtilsApi(mantiClient);
exports.up = async () => {
await utilsApi.sql(`create table scenes (
id int,
title text,
title_filtered text,
shoot_id text,
channel_id int,
channel_name text,
channel_slug text,
network_id int,
network_name text,
network_slug text,
actor_ids multi,
actors text,
tag_ids multi,
tags text,
meta text,
date timestamp,
created_at timestamp,
effective_date timestamp,
stashed int
const scenesFields = `
id int,
title text,
title_filtered text,
shoot_id text,
channel_id int,
channel_name text,
channel_slug text,
network_id int,
network_name text,
network_slug text,
actor_ids multi,
actors text,
tag_ids multi,
tags text,
meta text,
date timestamp,
created_at timestamp,
effective_date timestamp,
stashed int
`;
const moviesFields = `
id int,
title text,
title_filtered text,
channel_id int,
channel_name text,
channel_slug text,
network_id int,
network_name text,
network_slug text,
actor_ids multi,
actors text,
tag_ids multi,
tags text,
meta text,
date timestamp,
has_cover bool,
created_at timestamp,
effective_date timestamp,
stashed int,
stashed_scenes int,
stashed_total int
`;
const actorsFields = `
id int,
name text,
slug string,
gender string,
date_of_birth timestamp,
country string,
has_avatar bool,
weight int,
height int,
cup string,
natural_boobs int,
penis_length int,
penis_girth int,
stashed int,
scenes int
`;
exports.up = async (knex) => {
await utilsApi.sql(`create table scenes (${scenesFields})`);
/*
await utilsApi.sql(`create table scenes_stashed (
${scenesFields},
user_id int,
stash_id int
)`);
*/
await utilsApi.sql(`create table scenes_stashed (
scene_id int,
stash_id int,
user_id int
)`);
await utilsApi.sql(`create table movies (${moviesFields})`);
await utilsApi.sql(`create table movies_stashed (
${moviesFields},
user_id int,
stash_id int
)`);
await utilsApi.sql(`create table actors (${actorsFields})`);
await utilsApi.sql(`create table actors_stashed (
${actorsFields},
user_id int,
stash_id int
)`);
await knex.schema.alterTable('stashes_scenes', (table) => table.increments('id'));
await knex.schema.alterTable('stashes_movies', (table) => table.increments('id'));
await knex.schema.alterTable('stashes_actors', (table) => table.increments('id'));
await knex.schema.alterTable('stashes_series', (table) => table.increments('id'));
};
exports.down = async () => {
await utilsApi.sql('drop table scenes');
exports.down = async (knex) => {
await utilsApi.sql('drop table if exists scenes');
await utilsApi.sql('drop table if exists scenes_stashed');
await utilsApi.sql('drop table if exists movies');
await utilsApi.sql('drop table if exists movies_stashed');
await utilsApi.sql('drop table if exists actors');
await utilsApi.sql('drop table if exists actors_stashed');
await knex.schema.alterTable('stashes_scenes', (table) => table.dropColumn('id'));
await knex.schema.alterTable('stashes_movies', (table) => table.dropColumn('id'));
await knex.schema.alterTable('stashes_actors', (table) => table.dropColumn('id'));
await knex.schema.alterTable('stashes_series', (table) => table.dropColumn('id'));
};

View File

@@ -0,0 +1,21 @@
exports.up = async (knex) => {
await knex.schema.alterTable('users', (table) => {
table.dropUnique('username');
});
await knex.raw(`
CREATE UNIQUE INDEX username_unique_index ON users (LOWER(username));
CREATE UNIQUE INDEX email_unique_index ON users (LOWER(email));
`);
};
exports.down = async (knex) => {
await knex.raw(`
DROP INDEX IF EXISTS username_unique_index;
DROP INDEX IF EXISTS email_unique_index;
`);
await knex.schema.alterTable('users', (table) => {
table.unique('username');
});
};

View File

@@ -0,0 +1,22 @@
exports.up = async function up(knex) {
await knex.raw(`
CREATE MATERIALIZED VIEW stashes_meta AS (
SELECT
stashes.id as stash_id,
COUNT(DISTINCT stashes_scenes)::integer as stashed_scenes,
COUNT(DISTINCT stashes_movies)::integer as stashed_movies,
COUNT(DISTINCT stashes_actors)::integer as stashed_actors
FROM stashes
LEFT JOIN stashes_scenes ON stashes_scenes.stash_id = stashes.id
LEFT JOIN stashes_movies ON stashes_movies.stash_id = stashes.id
LEFT JOIN stashes_actors ON stashes_actors.stash_id = stashes.id
GROUP BY stashes.id
);
`);
};
exports.down = async function down(knex) {
await knex.raw(`
DROP MATERIALIZED VIEW IF EXISTS stashes_meta;
`);
};