Hi , I am testing sqlalchemy-migrate with a DB revision script that adds a table to my database. Two questions here, but first system info:
TG2 Framework (tg.devtools 2.0.2) with sqlalchemy_migrate-0.5.2-py2.6.egg MySQL 5.1.41 sqlalchemy V0.5.1 OS X 10.6.4 1) How do I use DeclarativeBase when defining my tables in migrate scripts? I Googled this and saw nothing in the manual. Is it possible? This works fine: test_case = Table ('test_case', meta, Column ('id', Integer, primary_key=True), Column('name', Unicode(255), nullable=False), mysql_engine='InnoDB' ) def upgrade(): test_case.create() But do I do this? Part of the problem is that I don't know of a way to generate tables other than create_all() (or drop_all()) when using declarative syntax. Is there another way? mysql_engine_type = InnoDB class TestCase (DeclarativeBase): __tablename__='test_case' __table_args__ = {'mysql_engine':mysql_engine_type} id = Column (Integer, primary_key=True) name = Column (Unicode(255), nullable=False) def __init__(self, name): self.name = name def upgrade(): ??? 2) Can MySQL wrap Table.create() in a transaction so that if something fails during upgrade/downgrade I don't litter up my DB with tables? I don't think MySQL can, but maybe I am wrong. I think some others (PostgreSQL) can. def upgrade(): connection = migrate_engine.connect() transaction = connection.begin() try: test_case.create(bind=connection) # Always seems to happen, even during rollback w1 = WeightCode('testw1') w2 = WeightCode('testw2') session.add(w1) # Doesn't insert on rollback session.add(w2) # Doesn't insert on rollback session.add(w3) # Fail transaction.commit() except: print "UPGRADE FAILURE, ROLLING BACK" transaction.rollback() I like the idea behind migrate, but have been using DeclarativeBase throughout my application. Having to switch between the Table/mapper & Base syntax is a bit awkward, so I am hoping there is a more direct, all DeclarativeBase way of doing things. Thanks for the help, Shane -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.