On 01/10/2017 06:10 PM, Роберт Шотланд wrote:
Thanks Mike,

Our developers use the ORM exclusively for database access. We maintain
a package containing the tables, relationships, validates, etc.
(*our_db.py*)  which is imported in the front-end, back-end modules and
utilities. Recently we added new fields to a table that are calculated
by @validates functions. This "alpha" version of*our_db.p*y-v0.3 depends
on a database that has been migrated to revision id "+2". Then a "beta"
developer working on a database migrated to revision "+1" mistakenly
imports v0.3, (not v0.2) into their venv, it will fail somewhere in the
@validates function probably with 3-pages of indecipherable stack trace.
We'd like to have our_db.py* *catch this error when the database is
opened, perhaps by checking a list of revision id's that are known to be
earlier migrations that are not supported by *our_db-v0.3*.

If you have a list of revision identifiers that are known to be earlier, you can look up the numbers in the current alembic_version table to see if they are present, and that would tell you the database is not up to date, but that means you need to have *all* those revision identifiers in that list - if one is missing then it might be missed. You'd also need to devise some way of keeping this list current with each migration identifier that gets generated - most likely something that happens at the same time as when you run the "alembic revision" command to create a new revision file.

Technically, any revision identifier that you read within alembic_version should be present in this list and you'd know which ones are the most current - if an identifier in alembic_version is not present in your list, you'd throw an error - that would likely mean the database is against a newer version of the code.

If you are using branches in your migrations then there may be more than one row in alembic_version also (and more than one "head" at a time) which would make this a multiple-row set operation.

Again, if the actual migration files are locally present in your application's module base, there's no need to maintain a separate list, you can construct this "list" from those version files directly using the ScriptDirectory API.





On Tuesday, January 10, 2017 at 1:02:43 PM UTC-7, Роберт Шотланд wrote:

    We have a project in active development that will have periodic
    alembic migrations driven by an evolving declarative package. We are
    looking for a means of automatically checking (say, at bind-=engine
    time?) a list of obsolete alembic revision ids (embedded in our
    declarative package), that would throw a custom exception if that
    declarative was used with a database that had not been migrated to a
    version compatible with that declarative package.

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to