basic seed files and restructuring

This commit is contained in:
Arjun Patel
2019-03-13 21:22:01 -07:00
parent 66173a978b
commit 0c88460b54
26 changed files with 104 additions and 202 deletions
+33
View File
@@ -0,0 +1,33 @@
'use strict';
const bcrypt = require('bcrypt-nodejs');
// DOESNT WORK AS NEED TO HASH PASSWORD TO DB
module.exports = {
up: async (queryInterface, Sequelize) => {
var hash = bcrypt.hashSync('test', null);
return queryInterface.bulkInsert('donors', [
{
first_name: 'Arjun',
last_name: 'Patel',
email: '[email protected]',
password: hash, //hashed password
age: 20,
phone: 9499230445,
address: '14872 Waverly Lane',
city: 'Irvine',
state: 'CA',
country: 'US',
created_at: new Date(),
updated_at: new Date()
}
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('donors', {
email: '[email protected]'
});
}
};
+22
View File
@@ -0,0 +1,22 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('causes', [
{
name: 'Animal Care',
created_at: new Date(),
updated_at: new Date()
},
{
name: 'Water',
created_at: new Date(),
updated_at: new Date()
}
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('causes', [{ name: 'Water' }, { name: 'Animal Care' }]);
}
};
+17
View File
@@ -0,0 +1,17 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('regions', [
{
name: 'North India',
created_at: new Date(),
updated_at: new Date()
}
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('regions', { name: 'North India' });
}
};
+73
View File
@@ -0,0 +1,73 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('organizations', [
{
name: 'Gopala Goshala',
email: '[email protected]',
password: hashedPass, //hashed password
short_description:
'We are focused on bringing lawful animal treatment in North India. Check out our many projects such as city water fountains for animals',
primary_cause: 'Animal',
primary_region,
ein,
primary_contact_first_name,
primary_contact_last_name,
phone,
country,
address,
city,
zip,
estimate_assets,
estimate_year_operating_cost
},
{
name,
email,
password: hashedPass, //hashed password
short_description,
primary_cause,
primary_region,
ein,
primary_contact_first_name,
primary_contact_last_name,
phone,
country,
address,
city,
zip,
estimate_assets,
estimate_year_operating_cost
},
{
name,
email,
password: hashedPass, //hashed password
short_description,
primary_cause,
primary_region,
ein,
primary_contact_first_name,
primary_contact_last_name,
phone,
country,
address,
city,
zip,
estimate_assets,
estimate_year_operating_cost
}
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('organizations', {
[Sequelize.Op.or]: [
{ name: 'Gopala Goshala' },
{ name: 'Water Organization India' },
{ name: "Pete's Animals" }
]
});
}
};
+65
View File
@@ -0,0 +1,65 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
var sequelize = queryInterface.sequelize;
const causes = [1, 2],
regions = [1],
organizations = [1, 2, 3];
return Promise.all([
sequelize.query(
`INSERT INTO grants (id, name, amount, monthly, last_payment, num_causes, num_regions, created_at, updated_at, donor_id)
VALUES (1, 'Max Impact in the South', 1000, 1, :last_payment, 2, 1, :created_at, :updated_at, (select id from donors where email='[email protected]'))`,
{
replacements: {
last_payment: new Date(),
created_at: new Date(),
updated_at: new Date()
},
type: sequelize.QueryTypes.INSERT
}
),
sequelize.query(
`INSERT INTO grants_causes (grant_id, cause_id, created_at, updated_at)
VALUES ((select id from grants where id=1), select id from causes where name='Animal Care', :created_at, :updated_at),
((select id from grants where id=1), select id from causes where name='Water', :created_at, :updated_at)`,
{
replacements: {
created_at: new Date(),
updated_at: new Date()
},
type: sequelize.QueryTypes.INSERT
}
),
sequelize.query(
`INSERT INTO grants_regions (grant_id, cause_id, created_at, updated_at)
VALUES ((select id from grants where id=1), select id from causes where name='Animal Care', :created_at, :updated_at),
((select id from grants where id=1), select id from causes where name='Water', :created_at, :updated_at)`,
{
replacements: {
created_at: new Date(),
updated_at: new Date()
},
type: sequelize.QueryTypes.INSERT
}
),
sequelize.query(
`INSERT INTO grants_causes (grant_id, cause_id, created_at, updated_at)
VALUES ((select id from grants where id=1), select id from causes where name='Animal Care', :created_at, :updated_at),
((select id from grants where id=1), select id from causes where name='Water', :created_at, :updated_at)`,
{
replacements: {
created_at: new Date(),
updated_at: new Date()
},
type: sequelize.QueryTypes.INSERT
}
)
]);
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('grants', null, {});
}
};