alembic icon indicating copy to clipboard operation
alembic copied to clipboard

Record a history of when particular migrations were applied

Open sqlalchemy-bot opened this issue 10 years ago • 12 comments

Migrated issue, originally created by Josh Kupershmidt (@schmiddy)

I was a little surprised to see that the alembic_version table records only the current version_num, without even a timestamp indicating when that version was applied. For forensic purposes, it's often handy to know when past migrations were applied to a target database, e.g. when trying to track what happened to a database in the past, determine why some errors popped up in a production database around some time, etc. The alembic history command is useful, but not quite what I'm looking for, since it doesn't tell me when the migrations were actually run in production.

(I'm currently using alembic 0.6.7, but didn't see this feature requested or mentioned anywhere else, so am assuming the situation is the same in the bleeding edge.)

sqlalchemy-bot avatar Jul 22 '15 13:07 sqlalchemy-bot

Michael Bayer (@zzzeek) wrote:

not a bad idea but the irony is that while we are all about migrating databases, changing the structure of the alembic_version table itself is tricky. Whether Alembic does it automatically when people upgrade or whether its some kind of option is a decision to be made. or if the structure of alembic_version itself is open ended and there's some kind of extension pattern to use.

sqlalchemy-bot avatar Jul 22 '15 14:07 sqlalchemy-bot

Michael Bayer (@zzzeek) wrote:

maybe have this be enabled by a flag, "store_version_history", indicates the alembic_version table will be generated with additional columns up front. then have some other system for people who want to move an existing alembic_version table.

or we have a separate table for history. still might be something we enable w/ a flag though - all the issues, what schema is the table within, what is it named, etc., all that happens again. a separate table at least can show the status of versions that are no longer the current head version.

sqlalchemy-bot avatar Nov 23 '16 22:11 sqlalchemy-bot

Changes by Michael Bayer (@zzzeek):

  • added labels: versioning model

sqlalchemy-bot avatar Apr 21 '18 14:04 sqlalchemy-bot

Changes by Michael Bayer (@zzzeek):

  • set milestone to "tier 1"

sqlalchemy-bot avatar Apr 21 '18 14:04 sqlalchemy-bot

just a note, I think separate auditing table would be much easier to implement and also it should be enabled via an option to suit environments that don't currently have such a table present.

zzzeek avatar Jul 29 '20 17:07 zzzeek

See https://github.com/jpassaro/Audit-Alembic for an example of how this could be done. It would be nice to update and absorb this project into Alembic proper.

jasenj1 avatar Aug 19 '20 20:08 jasenj1

Hi, Do we any news for this? I think this would be an awesome feature to have. The mechanism is proved to work well by Sequelize :)

terrynguyen255 avatar Mar 28 '22 04:03 terrynguyen255

I am a newbie to database version control and have looked into flyway (java), yoyo-migrations (python) and finally alembic (python).

As a heavy python user, I would love to do everything in python. However, the lack of alembic_version_history table really makes auditing difficult.

It would be great to see it implemented like in flyway and yoyo-migrations!

kenho811 avatar Apr 23 '22 12:04 kenho811

good idea at #1075, record the first line of the "message" also.

zzzeek avatar Aug 05 '22 16:08 zzzeek

Anything new around this?

Maimonator avatar Nov 14 '22 14:11 Maimonator

you'd see it here first

zzzeek avatar Nov 14 '22 14:11 zzzeek

an additional use case that may make use of this feature could be the one mentioned in #1298

CaselIT avatar Aug 21 '23 18:08 CaselIT