Issues

Issue #68 wontfix

"don't stop on errors when upgrade or downgrade" option needs

delegans
created an issue

No description provided.

Comments (6)

  1. Mike Bayer repo owner

    not sure what the use case is here. you can just do try/except in your script if you have certain areas that you'd like to skip errors:

    def upgrade():
        try:
            op.alter_column(...)
        except Exception, e:
            log.error("skipping error....")
    
  2. delegans reporter

    yes, but use try-except block for every line of big migration code is not good style IMHO I think this block is better to put inside all alembic operations, however it is not clear now what about sqlalchemy operations like connection.execute() when connection = op.get_bind()

  3. Mike Bayer repo owner

    its a bad idea to have "implicit skipping of failures" IMO in any case. if your migrations have failures, they should be fixed, not silently skipped.

    I'm not sure what the issue with "connection.execute" is. To execute string-based DDL within a migration typically op.execute() is used. get_bind() is not normally needed unless you're in the extremely rare case of retrieving result sets into memory within a migration, which also is not a great idea as it eliminates the possibility of using --sql.

  4. delegans reporter

    its problem appear when error occurs in middle of execution upgrade migration script and some part of migration was successfully done, another is not. after fixing a problem upgrade and downgrade cannot be applied without errors. and here lacks this option. I think it could be better implemented through the database transactions.

    Yes, I have to retrieve sequence next value to insert new record. not invented anything better than get it directly.

  5. Mike Bayer repo owner

    transactional DDL allows the whole operation to be rolled back when an exception occurs. This is enabled by default. if you're using MySQL or Oracle, then the DB doesn't support that, and there's no alternative but to manually repair the migration while testing. skipping failures isn't going to work because subsequent migrations are often dependent on previous ones in any case, and a large series of migrations will take *longer* to fix if the errors were skipped, rather than the migrations stopped short.

    to insert records with a sequence, first of all SQLAlchemy does this automatically if you have the Sequence() defined in the primary key column (I guess this is Oracle, see http://docs.sqlalchemy.org/en/rel_0_7/core/schema.html#defining-sequences), and even if not you can say table.insert().values(id=func.nextval(Sequence("my_sequence")) to embed in the statement.

  6. Log in to comment