Is it right way to use Alembic?

75 views
Skip to first unread message

junepeach

unread,
Nov 6, 2012, 1:59:24 PM11/6/12
to sqlal...@googlegroups.com
In our team, right now all developers are using sqlite as a testing database in which we have defined all of the tables in the schema and inserted all of the dataset. Eventually we will support 4 to 6 databases, such as MySQL, Postgresql, etc. At the beginning when reading alembic tutorial web site:
http://alembic.readthedocs.org/en/latest/tutorial.html
, I googled if alembic migration tool will automatically pull out the schemas from Sqlite into a schema model file in which all of the table schemas were defined as classes, such as:
class SomeClass(Base):
__tablename__ = 'some_table'
id = Column(Integer, primary_key=True)
name = Column(String(50))
if it is successful, it will save us lots of time, and we don't need to write the table classes by hand. Unfortunately I couldn't figure out how to do it, and maybe it is impossible. So we ended up writting all of the table classes by hand, and use alembic's 'autogenerate' command to automatically generate the migration script. Then update the migration script to make it compatiable with all supporting databases. Finally run 'alembic upgrade head' against supporting databases. We are not sure if we are doing right thing,and would like to have your suggestions. Thanks so much!

Michael Bayer

unread,
Nov 7, 2012, 9:48:28 AM11/7/12
to sqlal...@googlegroups.com

On Nov 6, 2012, at 1:59 PM, junepeach wrote:

> In our team, right now all developers are using sqlite as a testing database in which we have defined all of the tables in the schema and inserted all of the dataset. Eventually we will support 4 to 6 databases, such as MySQL, Postgresql, etc. At the beginning when reading alembic tutorial web site:
> http://alembic.readthedocs.org/en/latest/tutorial.html
> , I googled if alembic migration tool will automatically pull out the schemas from Sqlite into a schema model file in which all of the table schemas were defined as classes, such as:
> class SomeClass(Base):
> __tablename__ = 'some_table'
> id = Column(Integer, primary_key=True)
> name = Column(String(50))

Alembic doesn't generate ORM models. At best, it will generate migration directives that represent the changes between a database schema and the tables as defined in your application as either Table objects or declarative models.


> if it is successful, it will save us lots of time, and we don't need to write the table classes by hand.

the usual model is that the table metadata is defined in Python, and that metadata is used to generate schemas. Right now it seems like your developers are writing schemas by hand in SQLite, so there's always the task of "writing the tables by hand", its just where and when you do it that changes.


Reply all
Reply to author
Forward
0 new messages