thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
325 stars 40 forks source link

Model::sync & Model::migrate manager. #4

Closed thedodd closed 6 years ago

thedodd commented 6 years ago

A manager object is needed to resolve the following difficulties:

  1. models need to have their indices synced with the backend. We want this to be done as close to startup time as possible, and only once per the lifetime of the program's instantiation. If the backend is unreachable, we want the models to be synced at some future point in time without crashing the service. This is simple enough. Will have it done in no time.
  2. models are going to accrue some number of logical schema migrations over time. We need a way to automate the mutation/evolution of data — which already exists in a live database — in a straightforward & simple way. This last point merits greater discussion, as there are many different approaches to data schema migrations.

proposed schema migrations pattern

two-phase schema migration pattern

phase one
phase two
pros/cons

schema migration pattern comparison

django style schema migrations (SQL)

pros/cons

diesel style schema migrations

pros/cons

document versioning

pros/cons


far out option

Leverage Rust nightly plugins/custom attributes/&c to define a system which will use the document __version field to automatically handle document updates from version to version, removing fields, changing field types, adding new fields &c from lower versions up to the latest version of the Model.

This would be shooting for the stars ... and I don't currently have time to explore this. But it would be fucking awesome. And better than anything else out there in any other language, including interpreted languages (Python & Ruby have solid stories in this realm).

thedodd commented 6 years ago

@arturomc && @codenamekt definitely interested in your opinion on this one ;p just in general.