ian-james / IFS

Immediate Feedback System for student programming assignments and essay writing
MIT License
5 stars 6 forks source link

Objection.js migrations + model scaffolding #157

Closed kglovern closed 6 years ago

kglovern commented 6 years ago

Added ORM scaffolding using objection/knex. This includes models with relationships setup plus migrations for the database as it exists baseline. It's implemented in such a way that we can replace the old DB code piece-by-piece as components get touched instead of all at once.

Models are located in app/models. Model exports are title case and singular, while table names are plural and snake-case - for example UserInteraction.js exports UserInteraction, which models the user_interactions table. Two exceptions: Class and ClassSkill are implemented as Course and CourseSkill to avoid having a "Class Class" definition. No table names are changed.

Added a global variable __modelPath for easier imports.

All model relationships should be setup for eager loading with the exception of User since it's a foreign key almost everywhere and I wasn't 100% on what relationships we'd need to model.

Migrations create all tables as they currently are created baseline, including foreign keys. I've done extensive testing to make sure the database created by the migration matches the existing database creation script 1:1.

"knex migrate:latest" to create all tables in a new database "knex migrate:rollback" to rollback the last migration.

kglovern commented 6 years ago

Reviewed