Alembic or SQLAlchemy-Migrate

530 views
Skip to first unread message

John Robson

unread,
Mar 6, 2017, 7:15:36 PM3/6/17
to sqlal...@googlegroups.com
For Migrations (in PostgreSQL), what you guys recommend? Alembic or
SQLAlchemy-Migrate ?

Thank you.

mike bayer

unread,
Mar 6, 2017, 7:19:38 PM3/6/17
to sqlal...@googlegroups.com
sqlalchemy-migrate is legacy at this point, I'd say it's "unmaintained"
but that's only because I've been made the "maintainer" by some kind of
default (because....nobody else was maintaining it. you get the idea).

so yes alembic is the standard now.

John Robson

unread,
Mar 7, 2017, 2:18:16 PM3/7/17
to sqlal...@googlegroups.com
Hi Mike, you did an awesome tool, thank you very much!!!

I started to use Alembic today, excellent tool, tutorial and
"autogenerate" option ;)

Up to now, everything is working well, except by this very small problem:

class:
created = Column(DateTime, server_default=func.now())
updated = Column(DateTime, server_default=func.now(), onupdate=func.now())

from: http://docs.sqlalchemy.org/en/latest/core/defaults.html

generated:
op.add_column('users', sa.Column('created', sa.DateTime(),
server_default=sa.text('now()'), nullable=True))

op.add_column('users', sa.Column('updated', sa.DateTime(),
server_default=sa.text('now()'), nullable=True))

postgresql table:
created timestamp without time zone DEFAULT now(),
updated timestamp without time zone DEFAULT now(),

None "onupdate" function was created, in PostgreSQL or SQLite databases.
But even the SQLalchemy won't create the function, it will generate the
same SQL than Alembic (in PostgreSQL).

Overall, this tool is very useful, saved my life!!!

Thank you again,
John

mike bayer

unread,
Mar 7, 2017, 2:32:51 PM3/7/17
to sqlal...@googlegroups.com
Hi John -

"onupdate" is a Python side directive that does not impact the DDL of
the column as created in the database, so it is not relevant to the
ALTER TABLE directive. The equivalent to "server side ON UPDATE" for
Postgresql would be a database trigger which is out of scope here.

- mike
Reply all
Reply to author
Forward
0 new messages