211 lines
3.9 KiB
JavaScript
211 lines
3.9 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const Channels = db.channels;
|
|
|
|
const Subscriptions = db.subscriptions;
|
|
|
|
const Videos = db.videos;
|
|
|
|
const ChannelsData = [
|
|
{
|
|
name: 'Motivation Daily',
|
|
|
|
youtube_id: 'UC1234567890',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Inspire Now',
|
|
|
|
youtube_id: 'UC0987654321',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Success Stories',
|
|
|
|
youtube_id: 'UC1122334455',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
|
|
{
|
|
name: 'Leadership Talks',
|
|
|
|
youtube_id: 'UC5566778899',
|
|
|
|
// type code here for "relation_many" field
|
|
},
|
|
];
|
|
|
|
const SubscriptionsData = [
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
price: 30,
|
|
|
|
start_date: new Date('2023-10-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-01T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
price: 30,
|
|
|
|
start_date: new Date('2023-10-02T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-02T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
price: 30,
|
|
|
|
start_date: new Date('2023-10-03T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-03T00:00:00Z'),
|
|
},
|
|
|
|
{
|
|
// type code here for "relation_one" field
|
|
|
|
price: 30,
|
|
|
|
start_date: new Date('2023-10-04T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-04T00:00:00Z'),
|
|
},
|
|
];
|
|
|
|
const VideosData = [
|
|
{
|
|
theme: 'Inspiration',
|
|
|
|
mood: 'Motivational',
|
|
|
|
inspiration: 'Steve Jobs',
|
|
|
|
scheduled_at: new Date('2023-11-01T10:00:00Z'),
|
|
|
|
is_posted: true,
|
|
},
|
|
|
|
{
|
|
theme: 'Success',
|
|
|
|
mood: 'Uplifting',
|
|
|
|
inspiration: 'Oprah Winfrey',
|
|
|
|
scheduled_at: new Date('2023-11-02T11:00:00Z'),
|
|
|
|
is_posted: true,
|
|
},
|
|
|
|
{
|
|
theme: 'Perseverance',
|
|
|
|
mood: 'Encouraging',
|
|
|
|
inspiration: 'Nelson Mandela',
|
|
|
|
scheduled_at: new Date('2023-11-03T12:00:00Z'),
|
|
|
|
is_posted: true,
|
|
},
|
|
|
|
{
|
|
theme: 'Leadership',
|
|
|
|
mood: 'Empowering',
|
|
|
|
inspiration: 'Simon Sinek',
|
|
|
|
scheduled_at: new Date('2023-11-04T13:00:00Z'),
|
|
|
|
is_posted: true,
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateSubscriptionWithUser() {
|
|
const relatedUser0 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscription0 = await Subscriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Subscription0?.setUser) {
|
|
await Subscription0.setUser(relatedUser0);
|
|
}
|
|
|
|
const relatedUser1 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscription1 = await Subscriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Subscription1?.setUser) {
|
|
await Subscription1.setUser(relatedUser1);
|
|
}
|
|
|
|
const relatedUser2 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscription2 = await Subscriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Subscription2?.setUser) {
|
|
await Subscription2.setUser(relatedUser2);
|
|
}
|
|
|
|
const relatedUser3 = await Users.findOne({
|
|
offset: Math.floor(Math.random() * (await Users.count())),
|
|
});
|
|
const Subscription3 = await Subscriptions.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Subscription3?.setUser) {
|
|
await Subscription3.setUser(relatedUser3);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await Channels.bulkCreate(ChannelsData);
|
|
|
|
await Subscriptions.bulkCreate(SubscriptionsData);
|
|
|
|
await Videos.bulkCreate(VideosData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateSubscriptionWithUser(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('channels', null, {});
|
|
|
|
await queryInterface.bulkDelete('subscriptions', null, {});
|
|
|
|
await queryInterface.bulkDelete('videos', null, {});
|
|
},
|
|
};
|