alakajam-team / alakajam

Website powering the Alakajam! game making community
https://alakajam.com/
Other
29 stars 13 forks source link

Decouple code from Bookshelf #606

Open mkalam-alami opened 3 years ago

mkalam-alami commented 3 years ago

The next overly ambitious technical project, and a good exercise at migrations & code refactoring.

Strategy

For each major DB entity:

  1. Create a xxx.repository.ts to be used exclusively as a DAO layer
  2. Migrate all Bookshelf/Knex queries from the service layer down to the repository
  3. Migrate all model.save() and model.destroy() calls down to the repository
  4. Make the matching TypeORM entity class implement a fromBookshelfModel() to convert a TypeORM entity to Bookshelf, be careful about how relations are mapped
  5. Update the repository API to only expose entity classes instead of Bookshelf models. Migrate all impacted classes. Bookshelf-style API (.get() etc.) can be left as is for now.

This opens things up for a migration towards either TypeORM, Knex or whatever since we'll then be using plain TS classes.

Progress

(number is line count)