Use migrators for Storage
ukstv opened this issue · comments
Currently Machinomy lib uses following DB engines:
- Postgresql
- Mongodb
- Nedb
- Sqlite
Migrations are ad hoc.
Proposal: Add explicit migrator to Storage subsystem, that handles database-related details on how to manage schema and data.
Expected API, per engine:
storage.migrate: Migrator
Migrator.isLatest: Promise<boolean>
= returns true if latest migration is applied
Migrator.up(n?): Promise<void>
= migrates up to n
migration. Actual type of n
is to be discovered based on underlying migration mechanism.
Migrator.down(n?): Promise<void>
= migrates down to n
migration. The same notice regarding n as for up
is applied.
If the very concept of migrations do not make sense, provide dummy methods.
Start with Sqlite and Postgresql.
Use existing migration mechanism.
Expose migration strategy to Machinomy options as migrate
option:
silent
silently applies migrations where needed, default value.raise
raise an error if some migrations are pending.
Additionally, append mc_
prefix to all the tables managed by the library.
Additionally, expose SQL-schema-aware things from code logic to Migrator.
BTW, get rid of Mongodb.