import { knexOwner as knex } from '../src/knex.js';
import { utilsApi } from '../src/manticore.js';
import { syncStashes } from '../src/sync.js';

async function init() {
	await utilsApi.sql('drop table if exists scenes_stashed');

	await utilsApi.sql(`create table if not exists scenes_stashed (
		scene_id int,
		stash_id int,
		user_id int,
		created_at timestamp
	)`);

	await utilsApi.sql('drop table if exists movies_stashed');

	await utilsApi.sql(`create table if not exists movies_stashed (
		movie_id int,
		stash_id int,
		user_id int,
		created_at timestamp
	)`);

	await utilsApi.sql('drop table if exists actors_stashed');

	await utilsApi.sql(`create table if not exists actors_stashed (
		actor_id int,
		stash_id int,
		user_id int,
		created_at timestamp
	)`);

	console.log('Recreated stash tables, syncing stashes...');

	await syncStashes('scene');
	await syncStashes('actor');
	await syncStashes('movie');

	knex.destroy();
}

init();
