2022-07-25 17:22:59 +00:00
|
|
|
import { prisma } from '../src/db';
|
|
|
|
import { ComicCharacter, ComicPage, Prisma } from '@prisma/client';
|
|
|
|
import rain from './seed-data/comics/rain.json';
|
|
|
|
|
|
|
|
async function seedComicRain() {
|
|
|
|
const comicData = {
|
|
|
|
slug: 'rain',
|
|
|
|
url: 'https://rain.thecomicseries.com/',
|
|
|
|
title: rain.title,
|
|
|
|
};
|
|
|
|
const comic = await prisma.comic.upsert({
|
|
|
|
where: {
|
|
|
|
slug: 'rain',
|
|
|
|
},
|
|
|
|
update: comicData,
|
|
|
|
create: comicData,
|
|
|
|
});
|
|
|
|
|
|
|
|
{
|
|
|
|
// Chapters not directly related to the story
|
|
|
|
const SKIP_CHAPTERS = [
|
2022-07-25 17:31:20 +00:00
|
|
|
0, // Cover page
|
2022-07-25 17:22:59 +00:00
|
|
|
30, // SRS Hiatus
|
|
|
|
37, // Summer 2018 Hiatus
|
|
|
|
42, // Quarantine Hiatus 2020
|
|
|
|
48, // Rain delays
|
|
|
|
49, // Specials
|
|
|
|
];
|
|
|
|
const ops: Prisma.Prisma__ComicPageClient<ComicPage>[] = [];
|
|
|
|
for (const page of rain.pages) {
|
|
|
|
if (SKIP_CHAPTERS.includes(page.chapterId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const pageData = {
|
|
|
|
id: page.id,
|
|
|
|
title: page.name,
|
|
|
|
imageUrl: page.imageUrl,
|
|
|
|
url: page.url,
|
|
|
|
comicId: comic.id,
|
|
|
|
width: page.width,
|
|
|
|
height: page.height,
|
|
|
|
};
|
|
|
|
const op = prisma.comicPage.upsert({
|
|
|
|
where: {
|
|
|
|
comicId_id: {
|
|
|
|
comicId: comic.id,
|
|
|
|
id: page.id,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
create: pageData,
|
|
|
|
update: pageData,
|
|
|
|
});
|
|
|
|
ops.push(op);
|
|
|
|
}
|
|
|
|
await prisma.$transaction(ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const ops: Prisma.Prisma__ComicCharacterClient<ComicCharacter>[] = [];
|
|
|
|
for (const char of rain.characters) {
|
2022-07-25 17:31:20 +00:00
|
|
|
const character =
|
|
|
|
typeof char === 'string'
|
|
|
|
? { longName: char, shortName: char }
|
|
|
|
: char;
|
|
|
|
|
2022-07-25 17:22:59 +00:00
|
|
|
const characterData = {
|
|
|
|
comicId: comic.id,
|
2022-07-25 17:31:20 +00:00
|
|
|
...character,
|
|
|
|
};
|
2022-07-25 17:22:59 +00:00
|
|
|
const op = prisma.comicCharacter.upsert({
|
|
|
|
where: {
|
|
|
|
longName: character.longName,
|
|
|
|
},
|
|
|
|
create: characterData,
|
|
|
|
update: characterData,
|
|
|
|
});
|
|
|
|
ops.push(op);
|
|
|
|
}
|
|
|
|
await prisma.$transaction(ops);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(async function () {
|
|
|
|
await seedComicRain();
|
2022-07-25 17:31:20 +00:00
|
|
|
})().catch((e) => {
|
|
|
|
console.error('failed to seed', e);
|
2022-07-25 17:22:59 +00:00
|
|
|
process.exitCode = 1;
|
|
|
|
});
|