-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e03fa22
commit 8d90ac1
Showing
1 changed file
with
135 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import db from '../src/db'; | ||
|
||
async function seedUsers() { | ||
const users = [ | ||
{ | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User 1', | ||
disableDrm: false, | ||
}, | ||
{ | ||
id: '2', | ||
email: '[email protected]', | ||
name: 'Test User 2', | ||
disableDrm: false, | ||
}, | ||
]; | ||
|
||
try { | ||
for (const user of users) { | ||
await db.user.upsert({ | ||
where: { | ||
id: user.id, | ||
}, | ||
create: user, | ||
update: {}, | ||
}); | ||
} | ||
await db.user.upsert({ | ||
where: { | ||
id: '1', | ||
}, | ||
create: { | ||
id: '1', | ||
email: '[email protected]', | ||
name: 'Test User 1', | ||
disableDrm: false, | ||
}, | ||
update: {}, | ||
}); | ||
|
||
await db.user.upsert({ | ||
where: { | ||
id: '2', | ||
}, | ||
create: { | ||
id: '2', | ||
email: '[email protected]', | ||
name: 'Test User 2', | ||
disableDrm: false, | ||
}, | ||
update: {}, | ||
}); | ||
} catch (error) { | ||
console.error('Error seeding users:', error); | ||
throw error; | ||
|
@@ -45,7 +46,50 @@ async function seedCourses() { | |
openToEveryone: false, | ||
slug: 'test-course-1', | ||
}, | ||
// Add more courses if needed | ||
{ | ||
id: 2, | ||
appxCourseId: 2, | ||
discordRoleId: '3', | ||
title: 'test course 2', | ||
imageUrl: | ||
'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', | ||
description: 'test course 2', | ||
openToEveryone: false, | ||
slug: 'test-course-2', | ||
}, | ||
{ | ||
id: 3, | ||
appxCourseId: 2, | ||
discordRoleId: '3', | ||
title: 'test course 2', | ||
imageUrl: | ||
'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', | ||
description: 'test course 2', | ||
openToEveryone: false, | ||
slug: 'test-course-2', | ||
}, | ||
{ | ||
id: 4, | ||
appxCourseId: 2, | ||
discordRoleId: '3', | ||
title: 'test course 2', | ||
imageUrl: | ||
'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', | ||
description: 'test course 2', | ||
openToEveryone: false, | ||
slug: 'test-course-2', | ||
}, | ||
{ | ||
id: 5, | ||
appxCourseId: 2, | ||
discordRoleId: '3', | ||
title: 'test course 2', | ||
imageUrl: | ||
'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/images/test2.png', | ||
description: 'test course 2', | ||
openToEveryone: false, | ||
slug: 'test-course-2', | ||
}, | ||
]; | ||
|
||
try { | ||
|
@@ -98,40 +142,22 @@ async function seedContent() { | |
}, | ||
]; | ||
|
||
await db.content.createMany({ data: contentData }); | ||
console.log('Created content:', contentData); | ||
const createdContent = await db.content.createMany({ data: contentData }); | ||
console.log('Created content:', createdContent); | ||
} catch (error) { | ||
console.error('Error seeding content:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async function seedCourseContent() { | ||
const courseContentData = [ | ||
{ courseId: 1, contentId: 1 }, | ||
// Add more course-content pairs if needed | ||
]; | ||
|
||
try { | ||
for (const data of courseContentData) { | ||
const existingCourseContent = await db.courseContent.findUnique({ | ||
where: { | ||
courseId_contentId: { | ||
courseId: data.courseId, | ||
contentId: data.contentId, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!existingCourseContent) { | ||
await db.courseContent.create({ | ||
data, | ||
}); | ||
console.log('Created course content:', data); | ||
} else { | ||
console.log('Course content already exists:', data); | ||
} | ||
} | ||
await db.courseContent.create({ | ||
data: { | ||
courseId: 1, | ||
contentId: 1, | ||
}, | ||
}); | ||
} catch (error) { | ||
console.error('Error seeding course content:', error); | ||
throw error; | ||
|
@@ -140,24 +166,13 @@ async function seedCourseContent() { | |
|
||
async function seedNotionMetadata() { | ||
try { | ||
const existingMetadata = await db.notionMetadata.findUnique({ | ||
where: { | ||
await db.notionMetadata.create({ | ||
data: { | ||
id: 1, | ||
notionId: '39298af78c0f4c4ea780fd448551bad3', | ||
contentId: 2, | ||
}, | ||
}); | ||
|
||
if (!existingMetadata) { | ||
await db.notionMetadata.create({ | ||
data: { | ||
id: 1, | ||
notionId: '39298af78c0f4c4ea780fd448551bad3', | ||
contentId: 2, | ||
}, | ||
}); | ||
console.log('Created Notion metadata'); | ||
} else { | ||
console.log('Notion metadata already exists'); | ||
} | ||
} catch (error) { | ||
console.error('Error seeding Notion metadata:', error); | ||
throw error; | ||
|
@@ -166,83 +181,72 @@ async function seedNotionMetadata() { | |
|
||
async function seedVideoMetadata() { | ||
try { | ||
const existingMetadata = await db.videoMetadata.findUnique({ | ||
where: { | ||
await db.videoMetadata.create({ | ||
data: { | ||
id: 1, | ||
contentId: 3, | ||
video_1080p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
slides: | ||
'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/slides/Loops%2C+callbacks.pdf', | ||
}, | ||
}); | ||
|
||
if (!existingMetadata) { | ||
await db.videoMetadata.create({ | ||
data: { | ||
id: 1, | ||
contentId: 3, | ||
video_1080p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_1080p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_720p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_mp4_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_1: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_2: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_3: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
video_360p_4: 'https://www.w3schools.com/html/mov_bbb.mp4', | ||
slides: | ||
'https://appx-recordings.s3.ap-south-1.amazonaws.com/drm/100x/slides/Loops%2C+callbacks.pdf', | ||
}, | ||
}); | ||
console.log('Created video metadata'); | ||
} else { | ||
console.log('Video metadata already exists'); | ||
} | ||
} catch (error) { | ||
console.error('Error seeding video metadata:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
async function seedPurchases() { | ||
const purchases = [ | ||
{ userId: '1', courseId: 1 }, | ||
{ userId: '2', courseId: 1 }, | ||
{ userId: '1', courseId: 2 }, | ||
{ userId: '2', courseId: 2 }, | ||
]; | ||
|
||
try { | ||
for (const purchase of purchases) { | ||
const existingPurchase = await db.userPurchases.findUnique({ | ||
where: { | ||
userId_courseId: { | ||
userId: purchase.userId, | ||
courseId: purchase.courseId, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!existingPurchase) { | ||
await db.userPurchases.create({ data: purchase }); | ||
console.log('Created user purchase:', purchase); | ||
} else { | ||
console.log('User purchase already exists:', purchase); | ||
} | ||
} | ||
await db.userPurchases.create({ | ||
data: { | ||
userId: '1', | ||
courseId: 1, | ||
}, | ||
}); | ||
await db.userPurchases.create({ | ||
data: { | ||
userId: '2', | ||
courseId: 1, | ||
}, | ||
}); | ||
await db.userPurchases.create({ | ||
data: { | ||
userId: '1', | ||
courseId: 2, | ||
}, | ||
}); | ||
await db.userPurchases.create({ | ||
data: { | ||
userId: '2', | ||
courseId: 2, | ||
}, | ||
}); | ||
} catch (error) { | ||
console.error('Error while seeding purchases:', error); | ||
console.error('Error while seeding purchases'); | ||
throw error; | ||
} | ||
} | ||
|