traxxx/src/tools/julesjordan-fix.js

52 lines
1.4 KiB
JavaScript

'use strict';
// const config = require('config');
const initKnex = require('knex');
// const unprint = require('unprint');
// const args = require('yargs').argv;
// const stashes = require('./julesjordan_stashes.json');
const slugify = require('../utils/slugify');
async function init() {
const knex = initKnex({
client: 'pg',
connection: {
host: 'syskill.unknown.name',
user: 'traxxx',
password: 'YGDdBeXZXE25gKuzh5g7u4RV61G00XP6',
database: 'traxxx',
},
asyncStackTraces: true,
});
const results = await knex('releases')
.select('releases.*', knex.raw('json_agg(actors.name) as actor_names'))
.leftJoin('entities', 'entities.id', 'releases.entity_id')
.leftJoin('releases_actors', 'releases_actors.release_id', 'releases.id')
.leftJoin('actors', 'actors.id', 'releases_actors.actor_id')
.whereIn('entities.slug', ['julesjordan'])
.groupBy('releases.id');
await knex.transaction(async (trx) => {
return results.reduce(async (chain, scene) => {
await chain;
// const newEntryId = scene.entry_id.replace(/-\d{4}-\d{2}-\d{2}$/, ''); // remove date
const newEntryId = slugify([scene.title, ...(scene.actor_names?.toSorted() || [])]);
console.log(newEntryId);
await trx('releases')
.where('id', scene.id)
.update({
entry_id: newEntryId,
comment: `old entry id: ${scene.entry_id}`,
});
}, Promise.resolve());
});
knex.destroy();
}
init();