90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const LandingPages = db.landing_pages;
|
|
|
|
const LandingPagesData = [
|
|
{
|
|
title: 'Tech Innovators',
|
|
|
|
description: 'A platform for tech enthusiasts to explore innovations.',
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Anime Tech Hub',
|
|
|
|
description: 'Discover the latest in tech with an anime twist.',
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
|
|
{
|
|
title: 'Future Tech Insights',
|
|
|
|
description: 'Insights into the future of technology and innovation.',
|
|
|
|
// type code here for "images" field
|
|
|
|
// type code here for "relation_one" field
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateLandingPageWithCreated_by_user() {
|
|
const relatedCreated_by_user0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LandingPage0 = await LandingPages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (LandingPage0?.setCreated_by_user) {
|
|
await LandingPage0.setCreated_by_user(relatedCreated_by_user0);
|
|
}
|
|
|
|
const relatedCreated_by_user1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LandingPage1 = await LandingPages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (LandingPage1?.setCreated_by_user) {
|
|
await LandingPage1.setCreated_by_user(relatedCreated_by_user1);
|
|
}
|
|
|
|
const relatedCreated_by_user2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const LandingPage2 = await LandingPages.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (LandingPage2?.setCreated_by_user) {
|
|
await LandingPage2.setCreated_by_user(relatedCreated_by_user2);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await LandingPages.bulkCreate(LandingPagesData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateLandingPageWithCreated_by_user(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('landing_pages', null, {});
|
|
},
|
|
};
|