Skip to content

Commit

Permalink
Completed seed file that creates a site with a siteleader, mentor and…
Browse files Browse the repository at this point in the history
… admin along with lessons
  • Loading branch information
MahMago committed Dec 17, 2018
1 parent be07957 commit b6ca663
Show file tree
Hide file tree
Showing 45 changed files with 743 additions and 346 deletions.
77 changes: 77 additions & 0 deletions SEEDDOC.MD
@@ -0,0 +1,77 @@
Seed File Contents

- [ ] **semester** Primary Table

- [ ] type fk // field **term_id**
- [ ] type fk // field **year_id**

- [ ] **Site** Primary Table

- [ ] type fk // field **semester_id**
- [ ] type fk // field **style_id**
- [ ] type fk // field **level_id**
- [ ] type fk // field **school_id**

- [ ] **TIME** Primary Table

- [ ] type time // field **start_time**
- [ ] type time // field **end_time**
- [ ] type fk // field **weekday_id**

- [ ] **site_time** Inner Table

- [ ] type fk // field **site_id**
- [ ] type fk // field **time_id**

- [ ] **Account** Primary Table

- [ ] type string // field **first_name**
- [ ] type string // field **last_name**
- [ ] type string // field **email**
- [ ] type fk integer // field **authentication_id**

- [ ] **Local** Primary Table

- [ ] type string email // field email
- [ ] type string // field password
- [ ] type integer **unique** fk // field **account_id**

- [ ] **account_role_permissions**

- [ ] type fk integer unique // **account_id**
- [ ] type fk integer // **role_id**
- [ ] type fk integer // **permission_id**

- [ ] **Account_time**

- [ ] type fk integer // **account_id**
- [ ] type fk integer // **time_id**

- [ ] **lesson**

- [ ] type string // field **title**
- [ ] type string // field **summary**
- [ ] type string // field **guide**
- [ ] type string // field **plan**
- [ ] type fk integer // field **week_id**
- [ ] type fk integer // field **write_id** (Draft or Publish)

- [ ] **site_lesson** (what site does this lesson get used at)

- [ ] type fk integer // field **site_id**
- [ ] type fk integer // field **lesson_id**

- [ ] **account_lesson** (who is the/are authors of the lesson - created when lesson is crerated)

- [ ] type fk integer // field **account_id**
- [ ] type fk integer // field **lesson_id**

- [ ] **lesson_time** (what day of the week and time is this lesson associated with)

- [ ] type fk integer // field **Lesson_id**
- [ ] type fk integer // field **Time_id**

- [ ] **Site_lesson** (what lessons/sites are connected to one another)

- [ ] type fk integer // field **site_id**
- [ ] type fk integer // field **lesson_id**
122 changes: 101 additions & 21 deletions TODO.md
Expand Up @@ -5,6 +5,95 @@
- [x] setup Knex project
- [x] setup PostgreSQL
- [x] setup API routes
## 🌱 Migration File Creates The Following
#### authentication

* Google
* Local

#### level

* Middle School
* High School
* Adult School

#### permission

* 1 Admin
* 2 Mentor
* 3 Site Leader
* 4 Student

#### role

* 1 Admin
* 2 Mentor
* 3 Site Leader
* 4 Student

#### school

* 1 College Track
* 2 Downtown Charter Academy
* 3 Montera
* 4 Oakland Technical
* 5 REALM Charter
* 6 Root
* 7 Rudsdale

#### status

* 1 Approved
* 2 Pending
* 3 Rejected

#### style

* 1 Teaching
* 2 Lab Assisting

#### term

* 1 Fall
* 2 Spring

#### week

* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10

#### weekday

1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday

#### Year

-2018
-2019


- [ ] Semester
* table.integer('term_id');
* table.integer('year_id');
* table.timestamp('created_at').defaultTo(knex.fn.now());
* table.timestamp('updated_at').defaultTo(knex.fn.now());
* table.foreign('term_id').references('term.id').onDelete('CASCADE');
* table.foreign('year_id').references('year.id').onDelete('CASCADE');


## 🏓 Tables
Order of creation of tables
Expand All @@ -18,6 +107,7 @@ Order of creation of tables
- [x] School - Reference

- [x] Level - Reference

- [x] Style - Reference

- [x] Week - Reference
Expand All @@ -31,46 +121,36 @@ Order of creation of tables
- [x] Semester -primary

- [x] Time - primary

- [x] Lesson - primary

- [x] Resource - Primary

- [x] Authentication - Reference

- [x] Account - primary

- [x] local - primary

- [x] google - primary

- [x] Site - primary (join table)

- [x] exit_ticket - primary






Join Tables
- [x] site_time
- [x] account_time
- [x] lesson_time
- [x] site_lesson
- [x] account_lesson
- [x] site_time -
- [x] account_time -
- [x] lesson_time -
- [x] site_lesson -
- [x] account_lesson

- [x] account_site
- [x] account_role
- [x] account_request

- [x] role_permission
- [x] account_role_permission


- [x] account table
- [x] role table

- [x] semester table
- [x] site table
- [x] lesson table

- [x] account_role table
- [x] account_site table



Expand Down
2 changes: 1 addition & 1 deletion anovalabs_server/db/account.js
Expand Up @@ -7,7 +7,7 @@ module.exports = {
},
getOneById: id => {
return knex('account')
.where('accountId', id)
.where('id', id)
.first();
},
getOneByEmail: email => {
Expand Down
6 changes: 3 additions & 3 deletions anovalabs_server/db/lesson.js
Expand Up @@ -7,20 +7,20 @@ module.exports = {
},
getOne: id => {
return knex('lesson')
.where('lessonId', id)
.where('id', id)
.first();
},
create: lesson => {
return knex('lesson').insert(lesson, '*');
},
update: (id, lesson) => {
return knex('lesson')
.where('lessonId', id)
.where('id', id)
.update(lesson, '*');
},
delete: id => {
return knex('lesson')
.where('lessonId', id)
.where('id', id)
.del();
}
};
7 changes: 5 additions & 2 deletions anovalabs_server/knexfile.js
Expand Up @@ -2,8 +2,11 @@

module.exports = {
development: {
client: "pg",
connection: "postgres://localhost/anovalabs-db"
client: 'pg',
connection: 'postgres://localhost/anovalabs-db',
seeds: {
directory: './seeds/dev'
}
}

// staging: {
Expand Down
5 changes: 2 additions & 3 deletions anovalabs_server/migrations/20181215145327_week.js
Expand Up @@ -25,7 +25,6 @@ exports.up = function(knex, Promise) {
.then(() => updateTimestampTrigger(knex, 'week'))
.then(() => {
return knex('week').insert([
{ week: 0 },
{ week: 1 },
{ week: 2 },
{ week: 3 },
Expand All @@ -36,8 +35,8 @@ exports.up = function(knex, Promise) {
{ week: 8 },
{ week: 9 },
{ week: 10 },
{ week: 12 },
{ week: 13 }
{ week: 11 },
{ week: 12 }
]);
});
};
Expand Down
33 changes: 33 additions & 0 deletions anovalabs_server/migrations/20181215151730_write.js
@@ -0,0 +1,33 @@
function updateTimestampTrigger(knex, tableName) {
return knex.raw(`
CREATE OR REPLACE FUNCTION update_modified_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER update_${tableName}_updated_at
BEFORE UPDATE ON ${tableName}
FOR EACH ROW
EXECUTE PROCEDURE update_modified_column();
`);
}
exports.up = function(knex, Promise) {
return knex.schema
.createTable('write', function(table) {
table.increments();
table.string('status').comment('status on writing entity - draft or publish');
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(knex.fn.now());
})
.then(() => updateTimestampTrigger(knex, 'write'))
.then(() => {
return knex('write').insert([{ status: 'Draft' }, { status: 'Publish' }]);
});
};

exports.down = function(knex, Promise) {
return knex.schema.dropTableIfExists('write');
};
10 changes: 8 additions & 2 deletions anovalabs_server/migrations/20181215162033_semester.js
Expand Up @@ -18,8 +18,14 @@ exports.up = function(knex, Promise) {
return knex.schema
.createTable('semester', function(table) {
table.increments();
table.integer('term_id');
table.integer('year_id');
table
.integer('term_id')
.notNullable()
.unsigned();
table
.integer('year_id')
.notNullable()
.unsigned();
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(knex.fn.now());
table
Expand Down
13 changes: 12 additions & 1 deletion anovalabs_server/migrations/20181215170127_lesson.js
Expand Up @@ -22,7 +22,14 @@ exports.up = function(knex, Promise) {
table.string('summary').comment('summary of what the lesson will be about');
table.text('guide').comment('guide for mentors - written in markdown');
table.text('plan').comment('lesson plan for students - written in markdown');
table.integer('week_id');
table
.integer('week_id')
.notNullable()
.unsigned();
table
.integer('write_id')
.notNullable()
.unsigned();

table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(knex.fn.now());
Expand All @@ -31,6 +38,10 @@ exports.up = function(knex, Promise) {
.foreign('week_id')
.references('week.id')
.onDelete('CASCADE');
table
.foreign('write_id')
.references('write.id')
.onDelete('CASCADE');
})
.then(() => updateTimestampTrigger(knex, 'lesson'))
.catch(function(error) {
Expand Down

0 comments on commit b6ca663

Please sign in to comment.