Added date range to flush commands.

This commit is contained in:
DebaucheryLibrarian 2024-06-06 00:20:54 +02:00
parent 00653a7cab
commit a0ed434360
3 changed files with 73 additions and 7 deletions

View File

@ -4,7 +4,7 @@ const config = require('config');
const yargs = require('yargs');
const moment = require('moment');
function interpretAfter(after, ignoreIfEmpty = false) {
function interpretDate(after, ignoreIfEmpty = false) {
if (!after && ignoreIfEmpty) {
return null;
}
@ -341,6 +341,14 @@ const { argv } = yargs
describe: 'Remove all movies.',
type: 'boolean',
})
.option('flush-after', {
describe: 'Only delete scenes release after including',
type: 'string',
})
.option('flush-before', {
describe: 'Only delete scenes released before including',
type: 'string',
})
.option('delete-actors', {
describe: 'Remove actors by ID.',
type: 'array',
@ -378,7 +386,9 @@ const { argv } = yargs
alias: ['showcase', 'batch-showcased'],
default: true,
})
.coerce('after', interpretAfter)
.coerce('actors-update', (after) => interpretAfter(after, true));
.coerce('after', interpretDate)
.coerce('flush-after', interpretDate)
.coerce('flush-before', interpretDate)
.coerce('actors-update', (after) => interpretDate(after, true));
module.exports = argv;

View File

@ -372,27 +372,54 @@ async function flushEntities(networkSlugs = [], channelSlugs = []) {
.clone()
.select('releases.id')
.distinct('releases.id')
.whereNotNull('releases.id')
.from('selected_entities')
.leftJoin('releases', 'releases.entity_id', 'selected_entities.id')
.whereNotNull('releases.id')
.modify((builder) => {
if (argv.flushAfter) {
builder.where('effective_date', '>=', argv.flushAfter);
}
if (argv.flushBefore) {
builder.where('effective_date', '<=', argv.flushBefore);
}
})
.pluck('releases.id');
const movieIds = await entityQuery
.clone()
.select('movies.id')
.distinct('movies.id')
.whereNotNull('movies.id')
.from('selected_entities')
.leftJoin('movies', 'movies.entity_id', 'selected_entities.id')
.whereNotNull('movies.id')
.modify((builder) => {
if (argv.flushAfter) {
builder.where('effective_date', '>=', argv.flushAfter);
}
if (argv.flushBefore) {
builder.where('effective_date', '<=', argv.flushBefore);
}
})
.pluck('movies.id');
const serieIds = await entityQuery
.clone()
.select('series.id')
.distinct('series.id')
.whereNotNull('series.id')
.from('selected_entities')
.leftJoin('series', 'series.entity_id', 'selected_entities.id')
.whereNotNull('series.id')
.modify((builder) => {
if (argv.flushAfter) {
builder.where('date', '>=', argv.flushAfter);
}
if (argv.flushBefore) {
builder.where('date', '<=', argv.flushBefore);
}
})
.pluck('series.id');
if (sceneIds.length === 0 && movieIds.length === 0 && serieIds.length === 0) {

View File

@ -348,7 +348,18 @@ async function deleteSeries(serieIds) {
}
async function flushScenes() {
const sceneIds = await knex('releases').select('id').pluck('id');
const sceneIds = await knex('releases')
.select('id')
.modify((builder) => {
if (argv.flushAfter) {
builder.where('effective_date', '>=', argv.flushAfter);
}
if (argv.flushBefore) {
builder.where('effective_date', '<=', argv.flushBefore);
}
})
.pluck('id');
const confirmed = await inquirer.prompt([{
type: 'confirm',
@ -421,10 +432,28 @@ async function flushBatches(batchIds) {
knex('releases')
.select('releases.id')
.whereIn('created_batch_id', batchIds)
.modify((builder) => {
if (argv.flushAfter) {
builder.where('effective_date', '>=', argv.flushAfter);
}
if (argv.flushBefore) {
builder.where('effective_date', '<=', argv.flushBefore);
}
})
.pluck('releases.id'),
knex('movies').whereIn('created_batch_id', batchIds)
.select('movies.id')
.whereIn('created_batch_id', batchIds)
.modify((builder) => {
if (argv.flushAfter) {
builder.where('effective_date', '>=', argv.flushAfter);
}
if (argv.flushBefore) {
builder.where('effective_date', '<=', argv.flushBefore);
}
})
.pluck('movies.id'),
]);