1920 lines
36 KiB
JavaScript
1920 lines
36 KiB
JavaScript
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Books = db.books;
|
|
|
|
const BookPrompts = db.book_prompts;
|
|
|
|
const GenerationJobs = db.generation_jobs;
|
|
|
|
const PdfFiles = db.pdf_files;
|
|
|
|
const StorageLocations = db.storage_locations;
|
|
|
|
const DownloadEvents = db.download_events;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BooksData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "The Lantern That Laughed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"genre": "fairy_tale",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"tone": "sad",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pace": "slow",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "en_us",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"target_pages": 120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "draft",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"generation_started_at": new Date('2026-03-18T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"generation_finished_at": new Date('2026-03-18T10:25:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"failure_reason": "",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "Milo and the Moon Picnic",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"genre": "childrens",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"tone": "sad",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pace": "slow",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "en_us",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"target_pages": 56,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "deleted",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"generation_started_at": new Date('2026-03-20T14:10:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"generation_finished_at": new Date('2026-03-20T14:19:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"failure_reason": "",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"title": "The Quiet Forest Wish",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"genre": "fairy_tale",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"tone": "sad",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pace": "slow",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"language": "en_us",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"target_pages": 220,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"status": "queued",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"generation_started_at": new Date('2026-03-28T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"generation_finished_at": new Date('2026-03-28T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 62.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"failure_reason": "",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const BookPromptsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_text": "Write a gentle fairy tale about a lantern that giggles when it helps lost travelers, with cozy imagery and simple vocabulary.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_kind": "system",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_text": "Create a childrens story about Milo packing a moon picnic, focusing on kindness, sharing, and small everyday wonders.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_kind": "system",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_text": "Tell a slow-paced fairy tale about a forest spirit granting one wish that teaches patience and empathy, ending bittersweet.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"prompt_kind": "user",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const GenerationJobsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"job_status": "failed",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pages_requested": 120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pages_generated": 120,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"queued_at": new Date('2026-03-18T09:58:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-03-18T10:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"finished_at": new Date('2026-03-18T10:25:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"error_message": "",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"job_status": "succeeded",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pages_requested": 56,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pages_generated": 56,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 100,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"queued_at": new Date('2026-03-20T14:08:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-03-20T14:10:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"finished_at": new Date('2026-03-20T14:19:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"error_message": "",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"job_status": "canceled",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pages_requested": 220,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"pages_generated": 138,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"progress_percent": 62.5,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"queued_at": new Date('2026-03-28T15:58:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"started_at": new Date('2026-03-28T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"finished_at": new Date('2026-03-28T16:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"error_message": "",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const PdfFilesData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_name": "lantern-that-laughed.pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content_type": "application/pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_size_bytes": 2485760,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"storage_key": "my-books/jordan-lee/lantern-that-laughed.pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"uploaded_at": new Date('2026-03-18T10:26:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_deleted": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"deleted_at_time": new Date('2026-03-18T10:26:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_name": "milo-and-the-moon-picnic.pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content_type": "application/pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_size_bytes": 1459200,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"storage_key": "my-books/avery-patel/milo-and-the-moon-picnic.pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"uploaded_at": new Date('2026-03-20T14:20:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_deleted": true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"deleted_at_time": new Date('2026-03-20T14:20:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "files" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_name": "quiet-forest-wish.pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"content_type": "application/pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"file_size_bytes": 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"storage_key": "my-books/riley-chen/quiet-forest-wish.pdf",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"uploaded_at": new Date('2026-03-28T16:05:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_deleted": false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"deleted_at_time": new Date('2026-03-28T16:05:00Z'),
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const StorageLocationsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"display_name": "My Books",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"directory_name": "my-books",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"storage_kind": "cloud",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"display_name": "My Books",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"directory_name": "my-books",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"storage_kind": "cloud",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"display_name": "My Books",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"directory_name": "my-books",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"storage_kind": "cloud",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"is_default": true,
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const DownloadEventsData = [
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"downloaded_at": new Date('2026-03-18T12:05:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.10",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Mozilla/5.0 Chrome",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"downloaded_at": new Date('2026-03-20T15:00:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.11",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Mozilla/5.0 Safari",
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"downloaded_at": new Date('2026-03-28T18:22:00Z'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"ip_address": "203.0.113.12",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"user_agent": "Mozilla/5.0 Firefox",
|
|
|
|
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateBookWithOwner() {
|
|
|
|
const relatedOwner0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Book0 = await Books.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Book0?.setOwner)
|
|
{
|
|
await
|
|
Book0.
|
|
setOwner(relatedOwner0);
|
|
}
|
|
|
|
const relatedOwner1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Book1 = await Books.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Book1?.setOwner)
|
|
{
|
|
await
|
|
Book1.
|
|
setOwner(relatedOwner1);
|
|
}
|
|
|
|
const relatedOwner2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Book2 = await Books.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Book2?.setOwner)
|
|
{
|
|
await
|
|
Book2.
|
|
setOwner(relatedOwner2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateBookWithStorage_location() {
|
|
|
|
const relatedStorage_location0 = await StorageLocations.findOne({
|
|
offset: Math.floor(Math.random() * (await StorageLocations.count())),
|
|
});
|
|
const Book0 = await Books.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (Book0?.setStorage_location)
|
|
{
|
|
await
|
|
Book0.
|
|
setStorage_location(relatedStorage_location0);
|
|
}
|
|
|
|
const relatedStorage_location1 = await StorageLocations.findOne({
|
|
offset: Math.floor(Math.random() * (await StorageLocations.count())),
|
|
});
|
|
const Book1 = await Books.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (Book1?.setStorage_location)
|
|
{
|
|
await
|
|
Book1.
|
|
setStorage_location(relatedStorage_location1);
|
|
}
|
|
|
|
const relatedStorage_location2 = await StorageLocations.findOne({
|
|
offset: Math.floor(Math.random() * (await StorageLocations.count())),
|
|
});
|
|
const Book2 = await Books.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (Book2?.setStorage_location)
|
|
{
|
|
await
|
|
Book2.
|
|
setStorage_location(relatedStorage_location2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateBookPromptWithBook() {
|
|
|
|
const relatedBook0 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const BookPrompt0 = await BookPrompts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (BookPrompt0?.setBook)
|
|
{
|
|
await
|
|
BookPrompt0.
|
|
setBook(relatedBook0);
|
|
}
|
|
|
|
const relatedBook1 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const BookPrompt1 = await BookPrompts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (BookPrompt1?.setBook)
|
|
{
|
|
await
|
|
BookPrompt1.
|
|
setBook(relatedBook1);
|
|
}
|
|
|
|
const relatedBook2 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const BookPrompt2 = await BookPrompts.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (BookPrompt2?.setBook)
|
|
{
|
|
await
|
|
BookPrompt2.
|
|
setBook(relatedBook2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateGenerationJobWithBook() {
|
|
|
|
const relatedBook0 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const GenerationJob0 = await GenerationJobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (GenerationJob0?.setBook)
|
|
{
|
|
await
|
|
GenerationJob0.
|
|
setBook(relatedBook0);
|
|
}
|
|
|
|
const relatedBook1 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const GenerationJob1 = await GenerationJobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (GenerationJob1?.setBook)
|
|
{
|
|
await
|
|
GenerationJob1.
|
|
setBook(relatedBook1);
|
|
}
|
|
|
|
const relatedBook2 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const GenerationJob2 = await GenerationJobs.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (GenerationJob2?.setBook)
|
|
{
|
|
await
|
|
GenerationJob2.
|
|
setBook(relatedBook2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associatePdfFileWithBook() {
|
|
|
|
const relatedBook0 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const PdfFile0 = await PdfFiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (PdfFile0?.setBook)
|
|
{
|
|
await
|
|
PdfFile0.
|
|
setBook(relatedBook0);
|
|
}
|
|
|
|
const relatedBook1 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const PdfFile1 = await PdfFiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (PdfFile1?.setBook)
|
|
{
|
|
await
|
|
PdfFile1.
|
|
setBook(relatedBook1);
|
|
}
|
|
|
|
const relatedBook2 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const PdfFile2 = await PdfFiles.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (PdfFile2?.setBook)
|
|
{
|
|
await
|
|
PdfFile2.
|
|
setBook(relatedBook2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateStorageLocationWithOwner() {
|
|
|
|
const relatedOwner0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StorageLocation0 = await StorageLocations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (StorageLocation0?.setOwner)
|
|
{
|
|
await
|
|
StorageLocation0.
|
|
setOwner(relatedOwner0);
|
|
}
|
|
|
|
const relatedOwner1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StorageLocation1 = await StorageLocations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (StorageLocation1?.setOwner)
|
|
{
|
|
await
|
|
StorageLocation1.
|
|
setOwner(relatedOwner1);
|
|
}
|
|
|
|
const relatedOwner2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const StorageLocation2 = await StorageLocations.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (StorageLocation2?.setOwner)
|
|
{
|
|
await
|
|
StorageLocation2.
|
|
setOwner(relatedOwner2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function associateDownloadEventWithUser() {
|
|
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const DownloadEvent0 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (DownloadEvent0?.setUser)
|
|
{
|
|
await
|
|
DownloadEvent0.
|
|
setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const DownloadEvent1 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (DownloadEvent1?.setUser)
|
|
{
|
|
await
|
|
DownloadEvent1.
|
|
setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const DownloadEvent2 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (DownloadEvent2?.setUser)
|
|
{
|
|
await
|
|
DownloadEvent2.
|
|
setUser(relatedUser2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDownloadEventWithBook() {
|
|
|
|
const relatedBook0 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const DownloadEvent0 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (DownloadEvent0?.setBook)
|
|
{
|
|
await
|
|
DownloadEvent0.
|
|
setBook(relatedBook0);
|
|
}
|
|
|
|
const relatedBook1 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const DownloadEvent1 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (DownloadEvent1?.setBook)
|
|
{
|
|
await
|
|
DownloadEvent1.
|
|
setBook(relatedBook1);
|
|
}
|
|
|
|
const relatedBook2 = await Books.findOne({
|
|
offset: Math.floor(Math.random() * (await Books.count())),
|
|
});
|
|
const DownloadEvent2 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (DownloadEvent2?.setBook)
|
|
{
|
|
await
|
|
DownloadEvent2.
|
|
setBook(relatedBook2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function associateDownloadEventWithPdf_file() {
|
|
|
|
const relatedPdf_file0 = await PdfFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await PdfFiles.count())),
|
|
});
|
|
const DownloadEvent0 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0
|
|
});
|
|
if (DownloadEvent0?.setPdf_file)
|
|
{
|
|
await
|
|
DownloadEvent0.
|
|
setPdf_file(relatedPdf_file0);
|
|
}
|
|
|
|
const relatedPdf_file1 = await PdfFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await PdfFiles.count())),
|
|
});
|
|
const DownloadEvent1 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1
|
|
});
|
|
if (DownloadEvent1?.setPdf_file)
|
|
{
|
|
await
|
|
DownloadEvent1.
|
|
setPdf_file(relatedPdf_file1);
|
|
}
|
|
|
|
const relatedPdf_file2 = await PdfFiles.findOne({
|
|
offset: Math.floor(Math.random() * (await PdfFiles.count())),
|
|
});
|
|
const DownloadEvent2 = await DownloadEvents.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2
|
|
});
|
|
if (DownloadEvent2?.setPdf_file)
|
|
{
|
|
await
|
|
DownloadEvent2.
|
|
setPdf_file(relatedPdf_file2);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Books.bulkCreate(BooksData);
|
|
|
|
|
|
|
|
|
|
await BookPrompts.bulkCreate(BookPromptsData);
|
|
|
|
|
|
|
|
|
|
await GenerationJobs.bulkCreate(GenerationJobsData);
|
|
|
|
|
|
|
|
|
|
await PdfFiles.bulkCreate(PdfFilesData);
|
|
|
|
|
|
|
|
|
|
await StorageLocations.bulkCreate(StorageLocationsData);
|
|
|
|
|
|
|
|
|
|
await DownloadEvents.bulkCreate(DownloadEventsData);
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateBookWithOwner(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateBookWithStorage_location(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateBookPromptWithBook(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateGenerationJobWithBook(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associatePdfFileWithBook(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateStorageLocationWithOwner(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await associateDownloadEventWithUser(),
|
|
|
|
|
|
|
|
|
|
await associateDownloadEventWithBook(),
|
|
|
|
|
|
|
|
|
|
await associateDownloadEventWithPdf_file(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await queryInterface.bulkDelete('books', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('book_prompts', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('generation_jobs', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('pdf_files', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('storage_locations', null, {});
|
|
|
|
|
|
await queryInterface.bulkDelete('download_events', null, {});
|
|
|
|
|
|
},
|
|
}; |