Skip to content

Commit

Permalink
feat: creating tables and queries
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Nov 25, 2021
1 parent 1c82051 commit c1f7d76
Show file tree
Hide file tree
Showing 21 changed files with 1,607 additions and 51 deletions.
4 changes: 4 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
exports.connectionString = process.env.DATABASE_URL;
<<<<<<< HEAD
exports.sentryDSN = '';
=======
exports.sentryDSN = '';
>>>>>>> feat: creating tables and queries
5 changes: 5 additions & 0 deletions database/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const environment = process.env.NODE_ENV || 'development';
const config = require('../knexfile')[environment];
const knex = require('knex')(config);

module.exports = knex;
19 changes: 19 additions & 0 deletions database/migrations/20211119035928_createStakeholder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports.up = function (knex) {
return knex.schema.createTable('stakeholder', (table) => {
table.uuid('id').primary();
table.string('type').notNullable();
table.string('logo').notNullable();
table.string('name');
table.string('map').notNullable();
table.string('email');
table.string('phone');
table.string('website').notNullable();
table.string('children').notNullable();
table.string('parents').notNullable();
table.string('users').notNullable();
});
};

exports.down = function (knex) {
return knex.schema.dropTable('stakeholder');
};
16 changes: 16 additions & 0 deletions database/migrations/20211121004552_createStakeholder_Relations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exports.up = function (knex) {
return knex.schema.createTable('stakeholder_relations', (table) => {
table.uuid('org_id').notNullable();
table
.enu('relation_type', ['parent', 'child'], {
useNative: true,
enumName: 'relation',
})
.notNullable();
table.uuid('relation_id').notNullable();
});
};

exports.down = function (knex) {
return knex.schema.dropTable('stakeholder_relations');
};
109 changes: 109 additions & 0 deletions database/seeds/seed_stakeholder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
exports.seed = function (knex) {
// Deletes ALL existing entries
return knex('stakeholder')
.del()
.then(function () {
// Inserts seed entries
return knex('stakeholder').insert([
{
type: 'org',
logo_url: './logo_192x192.png',
first_name: '',
last_name: '',
stakeholder_uuid: '',
org_name: 'Greenstand',
id: '792a4eee-8e18-4750-a56f-91bdec383aa6',
map_name: '/greenstandMap',
email: 'hello@greenstand.com',
phone: '123-123-2122',
website: 'greenstand.org',
children: JSON.stringify([
'1a05ec87-3c38-4395-b9f3-aa15becedc31',
'1d2fb06e-e8f7-40de-8e13-ed3eba1abb3a',
]),
parents: [],
users: [],
},
{
type: 'org',
logo_url: './logo_192x192.png',
first_name: '',
last_name: '',
stakeholder_uuid: '',
org_name: 'Greenstance',
id: 'a8567323-88b1-4870-8c48-68d2da3ab356',
map_name: '/greenstance',
email: 'hello@greenstance.com',
phone: '123-123-1234',
website: 'greenstance.com',
children: [],
parents: [],
users: [],
},
{
type: 'org',
logo_url: './logo_192x192.png',
first_name: '',
last_name: '',
stakeholder_uuid: '',
org_name: 'Green Space',
id: 'c92189d2-2d55-44bc-a0b4-0dad25dc9f35',
map_name: '/greenspace',
email: 'greenspace@green.com',
phone: '123-123-1324',
website: 'greenspace.com',
children: [],
parents: [],
users: [],
},
{
type: 'org',
logo_url: './logo_192x192.png',
first_name: '',
last_name: '',
stakeholder_uuid: '',
org_name: 'Green World',
id: '344a6130-9094-4a05-8fd6-faf176593fbc',
map_name: '/greenworld',
email: 'hi@greenworld.com',
phone: '123-123-1234',
website: 'greenworld.com',
children: [],
parents: [],
users: [],
},
{
type: 'person',
logo_url: './logo_192x192.png',
first_name: '',
last_name: '',
stakeholder_uuid: '',
org_name: 'Child One',
id: '1a05ec87-3c38-4395-b9f3-aa15becedc31',
map_name: '/childOne',
email: 'child@gmail.com',
phone: '123-123-1234',
website: 'childone.com',
children: [],
parents: JSON.stringify(['792a4eee-8e18-4750-a56f-91bdec383aa6']),
users: JSON.stringify(['1234']),
},
{
type: 'person',
logo_url: './logo_192x192.png',
first_name: '',
last_name: '',
stakeholder_uuid: '',
org_name: 'Child Two',
id: '1d2fb06e-e8f7-40de-8e13-ed3eba1abb3a',
map_name: '/childtwo',
email: 'childtwo@gmail.com',
phone: '123-234-1234',
website: 'childtwo.com',
children: [],
parents: JSON.stringify(['792a4eee-8e18-4750-a56f-91bdec383aa6']),
users: JSON.stringify(['1235']),
},
]);
});
};
30 changes: 30 additions & 0 deletions database/seeds/seed_stakeholder_relations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exports.seed = function (knex) {
// Deletes ALL existing entries
return knex('stakeholder_relations')
.del()
.then(function () {
// Inserts seed entries
return knex('stakeholder_relations').insert([
{
org_id: '792a4eee-8e18-4750-a56f-91bdec383aa6',
relation_type: 'child',
relation_id: '1a05ec87-3c38-4395-b9f3-aa15becedc31',
},
{
org_id: '792a4eee-8e18-4750-a56f-91bdec383aa6',
relation_type: 'child',
relation_id: '1d2fb06e-e8f7-40de-8e13-ed3eba1abb3a',
},
{
org_id: '1a05ec87-3c38-4395-b9f3-aa15becedc31',
relation_type: 'parent',
relation_id: '792a4eee-8e18-4750-a56f-91bdec383aa6',
},
{
org_id: '1d2fb06e-e8f7-40de-8e13-ed3eba1abb3a',
relation_type: 'parent',
relation_id: '792a4eee-8e18-4750-a56f-91bdec383aa6',
},
]);
});
};
Loading

0 comments on commit c1f7d76

Please sign in to comment.