Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version should be written after every migration #112

Closed
sqlalchemy-bot opened this issue Mar 25, 2013 · 4 comments
Closed

Version should be written after every migration #112

sqlalchemy-bot opened this issue Mar 25, 2013 · 4 comments
Labels
bug Something isn't working

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by kaukas (@kaukas)

Consider two migrations: A and B; A succeeds while B fails due to some error. After database migration you get A fully applied and B partially applied or not applied at all.

However, the migrations table remains empty. Once I fix B I should be able to rerun just B but A is executed as well.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

Consider two migrations: A and B; A succeeds while B fails due to some error. After database migration you get A fully applied and B partially applied or not applied at all.

this is because your database doesn't support transactional ddl.

However, the migrations table remains empty. Once I fix B I should be able to rerun just B but A is executed as well.

alembic does do this for when transactional DDL isn't on, on line 212 of migrations.py:

        change(**kw)
        if not self.impl.transactional_ddl:
            self._update_current_rev(prev_rev, rev)
        prev_rev = rev

so then I checked what env.py does, by default it's this:

try:
    with context.begin_transaction():
        context.run_migrations()
finally:
    connection.close()

so that's the problem right? wrong, begin_transaction() also checks transactional DDL, and doesn't actually run a transaction:

def begin_transaction(self):
    if not self.is_transactional_ddl():
        @contextmanager
        def do_nothing():
            yield
        return do_nothing()
    elif self.is_offline_mode():
        @contextmanager
        def begin_commit():
            self.get_context().impl.emit_begin()
            yield
            self.get_context().impl.emit_commit()
        return begin_commit()
    else:
        return self.get_bind().begin()

so I am not seeing how your error is occurring, unless your tranasctional_ddl flag is incorrectly set. The version table is written after each migration and the connection is in autocommit mode when transactional_ddl is false. I need a lot more detail here including database in use as well as some log output.

@sqlalchemy-bot
Copy link
Author

Iuri de Silvio (@iurisilvio) wrote:

I had this issue with sqlite too.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

the flag was not set properly for SQLite (note http://bugs.python.org/issue10740) or MySQL, fixed in 3d1ed96

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added the bug Something isn't working label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant