30429/backend/src/db/seeders/20231127130745-sample-data.js
2025-04-03 04:35:50 +00:00

233 lines
4.6 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Images = db.images;
const Projects = db.projects;
const Settings = db.settings;
const ImagesData = [
{
url: 'https://example.com/image1.jpg',
// type code here for "relation_one" field
},
{
url: 'https://example.com/image2.jpg',
// type code here for "relation_one" field
},
{
url: 'https://example.com/image3.jpg',
// type code here for "relation_one" field
},
{
url: 'https://example.com/image4.jpg',
// type code here for "relation_one" field
},
{
url: 'https://example.com/image5.jpg',
// type code here for "relation_one" field
},
];
const ProjectsData = [
{
title: 'Portfolio Website',
description: 'A personal portfolio website showcasing projects and skills.',
start_date: new Date('2023-01-01T00:00:00Z'),
end_date: new Date('2023-06-01T00:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'E-commerce Platform',
description: 'An online platform for buying and selling products.',
start_date: new Date('2023-02-15T00:00:00Z'),
end_date: new Date('2023-08-15T00:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'Social Media App',
description:
'A mobile app for connecting with friends and sharing updates.',
start_date: new Date('2023-03-10T00:00:00Z'),
end_date: new Date('2023-09-10T00:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'Task Management Tool',
description: 'A tool for managing tasks and projects efficiently.',
start_date: new Date('2023-04-05T00:00:00Z'),
end_date: new Date('2023-10-05T00:00:00Z'),
// type code here for "relation_many" field
},
{
title: 'Blog Platform',
description: 'A platform for creating and sharing blog posts.',
start_date: new Date('2023-05-20T00:00:00Z'),
end_date: new Date('2023-11-20T00:00:00Z'),
// type code here for "relation_many" field
},
];
const SettingsData = [
{
dark_mode: true,
primary_color: '#3498db',
secondary_color: '#2ecc71',
},
{
dark_mode: false,
primary_color: '#e74c3c',
secondary_color: '#f1c40f',
},
{
dark_mode: true,
primary_color: '#9b59b6',
secondary_color: '#34495e',
},
{
dark_mode: false,
primary_color: '#1abc9c',
secondary_color: '#16a085',
},
{
dark_mode: true,
primary_color: '#e67e22',
secondary_color: '#d35400',
},
];
// Similar logic for "relation_many"
async function associateImageWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Image0 = await Images.findOne({
order: [['id', 'ASC']],
offset: 0,
});
if (Image0?.setProject) {
await Image0.setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Image1 = await Images.findOne({
order: [['id', 'ASC']],
offset: 1,
});
if (Image1?.setProject) {
await Image1.setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Image2 = await Images.findOne({
order: [['id', 'ASC']],
offset: 2,
});
if (Image2?.setProject) {
await Image2.setProject(relatedProject2);
}
const relatedProject3 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Image3 = await Images.findOne({
order: [['id', 'ASC']],
offset: 3,
});
if (Image3?.setProject) {
await Image3.setProject(relatedProject3);
}
const relatedProject4 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Image4 = await Images.findOne({
order: [['id', 'ASC']],
offset: 4,
});
if (Image4?.setProject) {
await Image4.setProject(relatedProject4);
}
}
// Similar logic for "relation_many"
module.exports = {
up: async (queryInterface, Sequelize) => {
await Images.bulkCreate(ImagesData);
await Projects.bulkCreate(ProjectsData);
await Settings.bulkCreate(SettingsData);
await Promise.all([
// Similar logic for "relation_many"
await associateImageWithProject(),
// Similar logic for "relation_many"
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('images', null, {});
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('settings', null, {});
},
};