Replies: 2 comments 8 replies
-
Implementation details should be like this: classDiagram
class Operation{
<<abstract>>
+upgrade()
+downgrade()
}
class NewTable
NewTable <|-- Operation
This is a simple object-oriented way to define the model, but more functionality can be added. |
Beta Was this translation helpful? Give feedback.
-
well there already is a declarative structure of your schema in SQLAlchemy , which is your Table metadata and/or ORM model. So a system that looks at a "declared" state of truth and figures out on the fly what migrations that would require, we already have that declared state of truth. the given code example you gave doesn't seem to be substantively different from What i'd assume is that you are looking for a Ruby-esque "idempotent" approach that I would assume looks at a given databases state on a per-operation basis and tries to bring it up to date based on individual comparison operations. I'm not sure what Django's approach is, my vague understanding was that their migrations were fully automatic and that they have some kind of storage that can produce migrations on the fly based on model comparison alone. I'm not sure how this relates to your proposal. But in any case we don't have any model versioning system in Alembic, our only "comparison" is against a live database. It works only at the whole model level and not at the level of individual operations. Alembic's individual operations are one-directional; they are DDL statements only that can be run as a flat SQL script without any introspection. This allows them to be efficient. if you've ever used an "idempotent" system like Ansible you'd know that all the "checking if each thing is already there" is really slow and cumbersome. If django has somehow figured out a way to make it all fast and easy, that's good for them, it's not a competency we have on this end nor do we have development /maintenance resources for a new migration paradigm. Alembic is however very modular and open ended and a new kind of migration system could certainly be built on top of it. As an example, check out the recipe Run Alembic Operation Objects Directly which illustrates how to have a command that determines migrations on the fly and runs them directly. that's not something we can support as the reflection / comparison process is not designed to be foolproof in all cases (django here benefits by the fact that django models have fairly rigid structural requirements compared to SQLAlchemy that allows anything). But it does show how something like this can be done perhaps for the benefit of a 3rd party Alembic extension. |
Beta Was this translation helpful? Give feedback.
-
Hello all,
Is there a possibility to make a declarative migrations mode like those found in django?
I found that in most situations declarative approach is better and less error-prone than imperative.
For example a migration script could look like this:
This will give us a one-time up/down migration declaration with a single source of truth.
Thanks,
Beta Was this translation helpful? Give feedback.
All reactions