chore: include dummy channels with seeds
This commit is contained in:
parent
12dff02c6f
commit
336484c13a
@ -2,19 +2,70 @@ import Prisma, { PrismaClient } from "../generated/prisma";
|
||||
|
||||
const client = new PrismaClient();
|
||||
|
||||
async function createManyFeeds() {
|
||||
const records: any = { data: [] };
|
||||
function getRandomDate(from: Date, to: Date) {
|
||||
const fromDate = from.getTime();
|
||||
return new Date(fromDate + Math.random() * (to.getTime() - fromDate));
|
||||
}
|
||||
|
||||
for (let i = 0; i < 35; i++) {
|
||||
records.data.push(<Prisma.Prisma.FeedCreateInput>{
|
||||
name: `News Network ${i}`,
|
||||
url: `https://news-network-${i}.com/rss`,
|
||||
guild_id: "1204426362794811453",
|
||||
active: true
|
||||
function generateRandomChannelId() {
|
||||
const min = 1000000000;
|
||||
const max = 9999999999;
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min + '';
|
||||
}
|
||||
|
||||
function createRandomChannels(): Prisma.Prisma.ChannelCreateNestedManyWithoutFeedInput {
|
||||
if (Math.random() < 0.5) {
|
||||
return { createMany: { data: [] } };
|
||||
}
|
||||
|
||||
const channels: Prisma.Prisma.ChannelCreateNestedManyWithoutFeedInput = {
|
||||
createMany: {
|
||||
data: Array.from({ length: 5 }, () => ({
|
||||
channel_id: generateRandomChannelId()
|
||||
}))
|
||||
}
|
||||
};
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
async function createManyChannels(feedId: number) {
|
||||
const channelData: Prisma.Prisma.ChannelCreateManyInput[] = [ ];
|
||||
|
||||
if (Math.random() < .5) return;
|
||||
|
||||
for (let i = 0; i < Math.floor(Math.random() * 10) + 1; i++) {
|
||||
channelData.push({
|
||||
channel_id: generateRandomChannelId(),
|
||||
feedId: feedId
|
||||
});
|
||||
}
|
||||
|
||||
await client.feed.createMany(records);
|
||||
await client.channel.createMany({ data: channelData });
|
||||
}
|
||||
|
||||
async function createManyFeeds() {
|
||||
const feedData: Prisma.Prisma.FeedCreateManyInput[] = [ ];
|
||||
|
||||
for (let i = 0; i < 35; i++) {
|
||||
feedData.push({
|
||||
name: `News Network ${i}`,
|
||||
url: `https://news-network-${i}.com/rss`,
|
||||
guild_id: "1204426362794811453",
|
||||
active: Math.random() < .5,
|
||||
created_at: getRandomDate(
|
||||
new Date("2020-01-01T00:00:00.000Z"),
|
||||
new Date("2025-04-27T00:00:00.000Z")
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
const feedIds = await client.feed.createManyAndReturn({
|
||||
data: feedData,
|
||||
select: { id: true }
|
||||
});
|
||||
|
||||
feedIds.forEach(async feed => await createManyChannels(feed.id));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user