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

Issue #68 wontfix
created an issue

No description provided.

Comments (8)

  1. Michael 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():
        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. Michael 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. Michael 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. Thorben Bochenek

    Well, this feature would have really saved my day a few times in the last weeks. There are no transactional DDL in MySQL and sometimes a migration fails midway. I think it's a questionable decision to assign wontfix here, a lot of people will be using MySQL.

  7. Michael Bayer repo owner

    I work with openstack, it's millions of lines of code, many hundreds of developers, and it all works with MySQL. when there's a migration that might not work, we put a conditional check to see that thing we're doing will succeed first. nobody would ever suggest ignoring all errors across the board; you wouldn't even know if any of your migrations succeeded.

  8. Log in to comment