From acf6421251aa2d1354300c5bd625b80af5bc1bfa Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Wed, 13 Mar 2019 22:50:20 -0700 Subject: [PATCH] database changes and initial causes and regions --- models/cause.model.js | 2 +- models/organization.model.js | 28 ++++++-- models/region.model.js | 2 +- seeders/20190122052354-base-causes.js | 53 +++++++++++++++- seeders/20190122053404-base-regions.js | 88 +++++++++++++++++++++++++- seeders/20190122053544-base-orgs.js | 10 +-- 6 files changed, 165 insertions(+), 18 deletions(-) diff --git a/models/cause.model.js b/models/cause.model.js index 1499e3e..f037615 100644 --- a/models/cause.model.js +++ b/models/cause.model.js @@ -5,7 +5,7 @@ module.exports = (sequelize, DataTypes) => { primaryKey: true, autoIncrement: true }, - name: { type: DataTypes.STRING, allowNull: false } + name: { type: DataTypes.STRING, allowNull: false, unique: true } }); return Cause; }; diff --git a/models/organization.model.js b/models/organization.model.js index 1fc58dd..d22eb58 100644 --- a/models/organization.model.js +++ b/models/organization.model.js @@ -1,4 +1,6 @@ -const uuidv4 = require('uuid/v4'); +const uuidv4 = require('uuid/v4'), + Cause = require('./cause.model'), + Region = require('./region.model'); module.exports = (sequelize, DataTypes) => { const Organization = sequelize.define('organizations', { @@ -45,21 +47,35 @@ module.exports = (sequelize, DataTypes) => { allowNull: false }, - primary_cause: { type: DataTypes.STRING, allowNull: false }, - primary_region: { type: DataTypes.STRING, allowNull: false }, + primary_cause: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Cause(sequelize, DataTypes), + key: 'name' + } + }, + primary_region: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Region(sequelize, DataTypes), + key: 'name' + } + }, total_rating: { type: DataTypes.INTEGER, defaultValue: 0 }, ein: { - type: DataTypes.INTEGER, + type: DataTypes.STRING(10), allowNull: false }, - estimate_assets: { + estimate_asset_value: { type: DataTypes.BIGINT, defaultValue: 0 }, estimate_year_operating_cost: { - type: DataTypes.INTEGER, + type: DataTypes.BIGINT, defaultValue: 0 }, diff --git a/models/region.model.js b/models/region.model.js index a5980bd..040a7aa 100644 --- a/models/region.model.js +++ b/models/region.model.js @@ -5,7 +5,7 @@ module.exports = (sequelize, DataTypes) => { primaryKey: true, autoIncrement: true }, - name: { type: DataTypes.STRING, allowNull: false } + name: { type: DataTypes.STRING, allowNull: false, unique: true } }); return Region; }; diff --git a/seeders/20190122052354-base-causes.js b/seeders/20190122052354-base-causes.js index 5a7c1d7..f134c3d 100644 --- a/seeders/20190122052354-base-causes.js +++ b/seeders/20190122052354-base-causes.js @@ -4,12 +4,37 @@ module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.bulkInsert('causes', [ { - name: 'Animal Care', + name: 'Animal', created_at: new Date(), updated_at: new Date() }, { - name: 'Water', + name: 'Environment', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Health', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Human Services', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Education', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Arts and Culture', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Religion', created_at: new Date(), updated_at: new Date() } @@ -17,6 +42,28 @@ module.exports = { }, down: (queryInterface, Sequelize) => { - return queryInterface.bulkDelete('causes', [{ name: 'Water' }, { name: 'Animal Care' }]); + return queryInterface.bulkDelete('causes', [ + { + name: 'Animal' + }, + { + name: 'Environment' + }, + { + name: 'Health' + }, + { + name: 'Human Services' + }, + { + name: 'Education' + }, + { + name: 'Arts and Culture' + }, + { + name: 'Religion' + } + ]); } }; diff --git a/seeders/20190122053404-base-regions.js b/seeders/20190122053404-base-regions.js index 679278f..ad26c14 100644 --- a/seeders/20190122053404-base-regions.js +++ b/seeders/20190122053404-base-regions.js @@ -4,7 +4,57 @@ module.exports = { up: (queryInterface, Sequelize) => { return queryInterface.bulkInsert('regions', [ { - name: 'North India', + name: 'Africa', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'East Asia', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'South Asia', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Central America', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'North America', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'South America', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Eastern Europe', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Western Europe', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Middle East', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Oceania', + created_at: new Date(), + updated_at: new Date() + }, + { + name: 'Caribbean', created_at: new Date(), updated_at: new Date() } @@ -12,6 +62,40 @@ module.exports = { }, down: (queryInterface, Sequelize) => { - return queryInterface.bulkDelete('regions', { name: 'North India' }); + return queryInterface.bulkDelete('regions', [ + { + name: 'Africa' + }, + { + name: 'East Asia' + }, + { + name: 'South Asia' + }, + { + name: 'Central America' + }, + { + name: 'North America' + }, + { + name: 'South America' + }, + { + name: 'Eastern Europe' + }, + { + name: 'Western Europe' + }, + { + name: 'Middle East' + }, + { + name: 'Oceania' + }, + { + name: 'Caribbean' + } + ]); } }; diff --git a/seeders/20190122053544-base-orgs.js b/seeders/20190122053544-base-orgs.js index 11cc882..c507974 100644 --- a/seeders/20190122053544-base-orgs.js +++ b/seeders/20190122053544-base-orgs.js @@ -18,13 +18,13 @@ module.exports = { zip: '92604', primary_cause: 'Animal', - primary_region: '', + primary_region: 'North India', - ein, - estimate_assets, - estimate_year_operating_cost, + ein: '63-6088665', + estimate_asset_value: 200000, + estimate_yearly_operating_cost: 40000, - isNonprofit, + isNonprofit: true, primary_contact_phone, primary_contact_first_name,