eliasdoehne / stellaris-dashboard

A graph dashboard and event log for Stellaris.
122 stars 14 forks source link

Automatic DB migrations #151

Closed MichaelMakesGames closed 2 months ago

MichaelMakesGames commented 2 months ago

Currently, any schema change results in a breaking release (old DBs will not work and either need to be deleted or manually edited).

We could use alembic (part of the SQLAlchemy project) to automatically compare the saved DBs to the data model, automatically generating and applying migrations. See https://alembic.sqlalchemy.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect

Alternatively, we could set up alembic to run manually written (or automatically generated then manually reviewed/edited) migrations.

MichaelMakesGames commented 2 months ago

This seems relevant for going full auto https://alembic.sqlalchemy.org/en/latest/cookbook.html#run-alembic-operation-objects-directly-as-in-from-autogenerate

MichaelMakesGames commented 2 months ago

Still needs some more testing, but got a basic implementation working. It detects and adds the new column on my old origin-less db: Screenshot from 2024-05-15 17-10-00

2024-05-15 17:09:05,011 - alembic.autogenerate.compare - INFO - Detected added column 'country.origin'