115 lines
3.5 KiB
TypeScript
115 lines
3.5 KiB
TypeScript
import { randomInt } from 'crypto';
|
|
import { PrismaClient } from '../generated/prisma';
|
|
import { withAccelerate } from '@prisma/extension-accelerate';
|
|
import { VodSegment } from '../src/types';
|
|
|
|
const prisma = new PrismaClient().$extends(withAccelerate());
|
|
|
|
const statuses = ['pending', 'approved', 'rejected'] as const;
|
|
|
|
const vodSegments: VodSegment[] = [
|
|
{ key: 'usc/yoosu613liof5i64dt6dv4os.mp4', name: 'yoosu613liof5i64dt6dv4os.mp4' },
|
|
{ key: 'usc/ytsbbb1qkl77c8lnjxv60mib.mp4', name: 'ytsbbb1qkl77c8lnjxv60mib.mp4' },
|
|
{ key: 'usc/zscvyiikaqg5j9zg2ib2537l.mp4', name: 'zscvyiikaqg5j9zg2ib2537l.mp4' },
|
|
{ key: 'usc/krxi88rpk2znkm6b4jajb05l.mp4', name: 'krxi88rpk2znkm6b4jajb05l.mp4' },
|
|
{ key: 'usc/h5c2l1o47u2jaqv4vgze26le.mp4', name: 'h5c2l1o47u2jaqv4vgze26le.mp4' },
|
|
{ key: 'usc/aj5sktmd75b1jskx5rkmgxkd.mp4', name: 'aj5sktmd75b1jskx5rkmgxkd.mp4' },
|
|
];
|
|
|
|
|
|
function getRandomStatus() {
|
|
return statuses[Math.floor(Math.random() * statuses.length)];
|
|
}
|
|
|
|
|
|
function getRandomSegments(vodSegments: VodSegment[]): VodSegment[] {
|
|
const count = Math.floor(Math.random() * 3) + 1; // 1 to 3
|
|
const shuffled = [...vodSegments].sort(() => Math.random() - 0.5);
|
|
return shuffled.slice(0, count);
|
|
}
|
|
|
|
async function main() {
|
|
console.log('🌱 Seeding database...');
|
|
|
|
const length = 9;
|
|
|
|
// Create Roles
|
|
await Promise.all([
|
|
prisma.role.create({ data: { name: 'user' } }),
|
|
prisma.role.create({ data: { name: 'admin' } }),
|
|
prisma.role.create({ data: { name: 'supporterTier1' } }),
|
|
prisma.role.create({ data: { name: 'supporterTier2' } }),
|
|
prisma.role.create({ data: { name: 'supporterTier3' } }),
|
|
prisma.role.create({ data: { name: 'supporterTier4' } }),
|
|
prisma.role.create({ data: { name: 'supporterTier5' } }),
|
|
prisma.role.create({ data: { name: 'supporterTier6' } }),
|
|
]);
|
|
|
|
// Create Users
|
|
const users = await Promise.all(
|
|
Array.from({ length }).map((_, i) =>
|
|
prisma.user.create({
|
|
data: {
|
|
patreonFullName: `User ${i + 1}`,
|
|
patreonId: `${randomInt(9558925894)}`,
|
|
imageUrl: 'https://placehold.co/48',
|
|
},
|
|
})
|
|
)
|
|
);
|
|
|
|
// Create Vtubers
|
|
const vtubers = await Promise.all(
|
|
['Alpha', 'Bravo', 'Charlie'].map((name, i) =>
|
|
prisma.vtuber.create({
|
|
data: {
|
|
displayName: name,
|
|
slug: name.toLowerCase(),
|
|
uploader: {
|
|
connect: {
|
|
id: users[i % users.length].id, // re-use existing seeded users
|
|
},
|
|
},
|
|
},
|
|
})
|
|
)
|
|
);
|
|
|
|
// Create Streams and VODs (with embedded upload data)
|
|
await Promise.all(
|
|
users.map((user, i) =>
|
|
prisma.vod.create({
|
|
data: {
|
|
uploader: { connect: { id: user.id } },
|
|
segmentKeys: getRandomSegments(vodSegments),
|
|
streamDate: new Date(),
|
|
notes: `This is a vod I recorded using future.porn DVR 3000. This is my ${i + 1} vod I recorded and I believe it is archival quality.`,
|
|
status: getRandomStatus(),
|
|
hlsPlaylist: '',
|
|
thumbnail: '',
|
|
vtubers: {
|
|
connect: [{ id: vtubers[i % vtubers.length].id }],
|
|
},
|
|
stream: {
|
|
create: {
|
|
date: new Date(),
|
|
announcementUrl: `https://example.com/announcement/${i + 1}`,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
)
|
|
);
|
|
|
|
console.log(`✅ Seed complete with ${length} users and VODs (with vtubers)!`);
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('❌ Seed error:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|