-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from atlp-rwanda/ft-seeders
Ft seeders done
- Loading branch information
Showing
20 changed files
with
542 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
'use strict'; | ||
|
||
const { v4: uuidv4 } = require('uuid'); | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
const profileUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSXhCG6nff2emBYOKGHb6jU2zQ4C2m0LBg4Mj-eydwZyg&s' | ||
await queryInterface.bulkInsert('Users', [ | ||
{ | ||
userId: uuidv4(), | ||
name: 'User1', | ||
email: '[email protected]', | ||
password: 'password1', | ||
status: 'active', | ||
wishlistId: null, | ||
cartId: null, | ||
role: 'buyer', | ||
profile: profileUrl, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
{ | ||
userId: uuidv4(), | ||
name: 'User2', | ||
email: '[email protected]', | ||
password: 'password1', | ||
status: 'active', | ||
wishlistId: null, | ||
cartId: null, | ||
role: 'buyer', | ||
profile: profileUrl, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, { | ||
userId: uuidv4(), | ||
name: 'User3', | ||
email: '[email protected]', | ||
password: 'password1', | ||
status: 'active', | ||
wishlistId: null, | ||
cartId: null, | ||
role: 'buyer', | ||
profile: profileUrl, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
{ | ||
userId: uuidv4(), | ||
name: 'User4', | ||
email: '[email protected]', | ||
password: 'password1', | ||
status: 'active', | ||
wishlistId: null, | ||
cartId: null, | ||
role: 'buyer', | ||
profile: profileUrl, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, | ||
{ | ||
userId: uuidv4(), | ||
name: 'User5', | ||
email: '[email protected]', | ||
password: 'password1', | ||
status: 'active', | ||
wishlistId: null, | ||
cartId: null, | ||
role: 'buyer', | ||
profile: profileUrl, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}, { | ||
|
||
userId: uuidv4(), | ||
name: 'User6', | ||
email: '[email protected]', | ||
password: 'password1', | ||
status: 'active', | ||
wishlistId: null, | ||
cartId: null, | ||
role: 'buyer', | ||
profile: profileUrl, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
} | ||
], {}); | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
// @ts-ignore | ||
await queryInterface.bulkDelete('Users', null, {}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const { v4: uuidv4 } = require('uuid'); | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
console.log('Getting the users') | ||
const [users] = await queryInterface.sequelize.query(`SELECT "userId" FROM "Users"`); | ||
|
||
users.map(user => ( | ||
console.log('The users ', user) | ||
)) | ||
|
||
const carts = users.map(user => ({ | ||
cartId: uuidv4(), | ||
// @ts-ignore | ||
userId: user.userId, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})); | ||
|
||
await queryInterface.bulkInsert('Carts', carts, {}); | ||
|
||
for (const cart of carts) { | ||
await queryInterface.bulkUpdate('Users', | ||
{ cartId: cart.cartId }, | ||
{ userId: cart.userId } | ||
); | ||
} | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
// @ts-ignore | ||
await queryInterface.bulkDelete('Carts', null, {}); | ||
await queryInterface.bulkUpdate('Users', { cartId: null }, { cartId: { [Sequelize.Op.ne]: null } }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const { v4: uuidv4 } = require('uuid'); | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
const [users] = await queryInterface.sequelize.query(` | ||
SELECT "userId" | ||
FROM "Users" | ||
ORDER BY "createdAt" DESC | ||
LIMIT 3; | ||
`); | ||
|
||
const vendors = users.map(user => ({ | ||
vendorId: uuidv4(), | ||
// @ts-ignore | ||
userId: user.userId, | ||
storeName: `Store ${Math.floor(Math.random() * (11))}`, | ||
address: JSON.stringify({ | ||
street: 'KG 111 ST', | ||
city: 'Kigali' | ||
}), | ||
TIN: Math.floor(Math.random() * 100000000), | ||
bankAccount: Math.floor(Math.random() * 1000000000), | ||
paymentDetails: JSON.stringify({ | ||
method: 'Bank Transfer', | ||
bankName: 'Bank Of Kigali' | ||
}), | ||
status: 'pending', | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
})) | ||
|
||
await queryInterface.bulkInsert('Vendors', vendors, {}); | ||
|
||
await queryInterface.bulkUpdate('Users', | ||
{ role: 'vendor' }, | ||
// @ts-ignore | ||
{ userId: users.map(user => user.userId) } | ||
); | ||
}, | ||
|
||
|
||
async down(queryInterface, Sequelize) { | ||
// @ts-ignore | ||
await queryInterface.bulkDelete('Vendors', null, {}); | ||
await queryInterface.bulkUpdate('Users', { role: 'buyer' }, { role: 'vendor' }); | ||
} | ||
}; |
Oops, something went wrong.