31471/backend/src/db/seeders/20231127130745-sample-data.js
2025-05-13 02:13:55 +00:00

204 lines
4.4 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const CodeGenerations = db.code_generations;
const Projects = db.projects;
const CodeGenerationsData = [
{
description: 'Initial setup for Project Alpha',
status: 'pending',
// type code here for "relation_one" field
generated_at: new Date('2023-10-01T10:00:00Z'),
filename: 'Alexander Fleming',
filecontent: 'William Bayliss',
},
{
description: 'Performance improvements for Project Beta',
status: 'pending',
// type code here for "relation_one" field
generated_at: new Date('2023-10-02T11:00:00Z'),
filename: 'Ernst Haeckel',
filecontent: 'Galileo Galilei',
},
{
description: 'Bug fixes for Project Gamma',
status: 'in_progress',
// type code here for "relation_one" field
generated_at: new Date('2023-10-03T12:00:00Z'),
filename: 'Alfred Binet',
filecontent: 'Louis Victor de Broglie',
},
{
description: 'Code refactoring for Project Delta',
status: 'in_progress',
// type code here for "relation_one" field
generated_at: new Date('2023-10-04T13:00:00Z'),
filename: 'Sigmund Freud',
filecontent: 'Galileo Galilei',
},
{
description: 'UI enhancements for Project Epsilon',
status: 'completed',
// type code here for "relation_one" field
generated_at: new Date('2023-10-05T14:00:00Z'),
filename: 'Charles Lyell',
filecontent: 'Jonas Salk',
},
];
const ProjectsData = [
{
name: 'Project Alpha',
description: 'A project to develop a new feature.',
// type code here for "relation_many" field
},
{
name: 'Project Beta',
description: 'A project to improve performance.',
// type code here for "relation_many" field
},
{
name: 'Project Gamma',
description: 'A project to fix bugs.',
// type code here for "relation_many" field
},
{
name: 'Project Delta',
description: 'A project to refactor code.',
// type code here for "relation_many" field
},
{
name: 'Project Epsilon',
description: 'A project to enhance UI.',
// type code here for "relation_many" field
},
];
// Similar logic for "relation_many"
async function associateCodeGenerationWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const CodeGeneration0 = await CodeGenerations.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (CodeGeneration0?.setProject) {
await CodeGeneration0.setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const CodeGeneration1 = await CodeGenerations.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (CodeGeneration1?.setProject) {
await CodeGeneration1.setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const CodeGeneration2 = await CodeGenerations.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (CodeGeneration2?.setProject) {
await CodeGeneration2.setProject(relatedProject2);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const CodeGeneration3 = await CodeGenerations.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (CodeGeneration3?.setProject) {
await CodeGeneration3.setProject(relatedProject3);
}
const relatedProject4 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const CodeGeneration4 = await CodeGenerations.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (CodeGeneration4?.setProject) {
await CodeGeneration4.setProject(relatedProject4);
}
}
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await CodeGenerations.bulkCreate(CodeGenerationsData);
await Projects.bulkCreate(ProjectsData);
await Promise.all([
// Similar logic for "relation_many"
await associateCodeGenerationWithProject(),
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('code_generations', null, {});
await queryInterface.bulkDelete('projects', null, {});
},
};