Skip to content

Commit

Permalink
chore: add seeders
Browse files Browse the repository at this point in the history
  • Loading branch information
apsantiso committed Feb 27, 2024
1 parent 721328b commit fa9e75b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions seeders/20230620032601-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ module.exports = {
await queryInterface.bulkInsert('roles', [
{
id: uuidv4(),
name: 'role_1',
name: 'EDITOR',
created_at: new Date(),
updated_at: new Date(),
},
{
id: uuidv4(),
name: 'role_2',
name: 'READER',
created_at: new Date(),
updated_at: new Date(),
},
Expand Down
45 changes: 45 additions & 0 deletions seeders/20240227151157-add-paid-plans-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

module.exports = {
async up(queryInterface, Sequelize) {
const plans = [
{ name: '200gb_individual', planId: 'prod_NXNUMFRQaiKaIf' },
{ name: '2tb_individual', planId: 'prod_NXNX7KNAAf5mZZ' },
{ name: '2tb_individual', planId: 'prod_NXNYonsdtj7yvn' },
{ name: '5tb_individual', planId: 'prod_NXNaYLBRNJDvOs' },
{ name: '10tb_individual', planId: 'prod_NXNb9cOS28ubg5' },
];

for (let plan of plans) {
const tiers = await queryInterface.sequelize.query(
`SELECT id FROM tiers WHERE label = '${plan.name}' LIMIT 1`,
{ type: Sequelize.QueryTypes.SELECT },
);

if (tiers.length > 0) {
const tierId = tiers[0].id;

await queryInterface.sequelize.query(
`INSERT INTO paid_plans (plan_id, tier_id, description, created_at, updated_at)
VALUES ('${plan.planId}', '${tierId}', '${plan.name}' ,NOW(), NOW())`,
);
}
}
},

async down(queryInterface) {
const planIds = [
'prod_NXNUMFRQaiKaIf',
'prod_NXNX7KNAAf5mZZ',
'prod_NXNYonsdtj7yvn',
'prod_NXNaYLBRNJDvOs',
'prod_NXNb9cOS28ubg5',
];

for (let planId of planIds) {
await queryInterface.sequelize.query(
`DELETE FROM paid_plans WHERE plan_id = '${planId}'`,
);
}
},
};

0 comments on commit fa9e75b

Please sign in to comment.