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

"downgrade --sql" handles revision abbreviations differently from "upgrade --sql" #269

Closed
sqlalchemy-bot opened this issue Feb 3, 2015 · 5 comments
Labels

Comments

@sqlalchemy-bot
Copy link

@sqlalchemy-bot sqlalchemy-bot commented Feb 3, 2015

Migrated issue, originally created by Jani Hautamaki

I am using alembic-0.7.4py2.7

Apparently downgrade --sql from:to handles the revisions for "from" and "to" differently from upgrade --sql. In case of upgrade, it is possible to abbreviate the revision strings (which, I think, is desirable). However, if I use the same abbreviated revision strings (in reverse order, of course) with downgrade --sql, I end up with KeyError.

Example:

$ alembic -c file.ini history
fc6f95f31aa -> 48c19228b1f6 (head), migration_2
<base> -> fc6f95f31aa, migration_1

$ alembic -c file.ini upgrade --sql fc6f:48c1
[works fine]

$ alembic -c file.ini downgrade --sql 48c1:fc6f
  [...]
  File "[...]/site-packages/alembic-0.7.4-py2.7.egg/alembic/migration.py", line 502, in update_to_step
    self._update_version(from_, to_)
  File "[...]/site-packages/alembic-0.7.4-py2.7.egg/alembic/migration.py", line 455, in _update_version
    self.heads.remove(from_)
KeyError: '48c19228b1f6'

I added some log.info()s to the program, and apparently
self.heads is set(['48c1'])), while from_ is '48c19228b1f6',
and therefore the key is not found from the heads.

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Feb 3, 2015

Changes by Jani Hautamaki:

  • edited description
1 similar comment
@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Feb 3, 2015

Changes by Jani Hautamaki:

  • edited description
@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Feb 3, 2015

Michael Bayer (@zzzeek) wrote:

  • move resolution of "starting rev" for --sql mode into
    get_current_heads() directly; therefore we don't need to
    do this in alembic.command, which we were doing for stamp but
    not downgrade/upgrade. The slight change here is that the
    context.get_starting_revision_argument() method will
    return an abbreviated starting rev as abbreviated in
    all cases, including the stamp command, where we previously
    were converting a stamp argument first, but not for the
    upgrade or downgrade commands.
  • Fixed bug where using a partial revision identifier as the
    "starting revision" in --sql mode in a downgrade operation
    would fail to resolve properly. fixes #269

0955d44

@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Feb 3, 2015

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
@sqlalchemy-bot
Copy link
Author

@sqlalchemy-bot sqlalchemy-bot commented Feb 3, 2015

Michael Bayer (@zzzeek) wrote:

thanks for the report, this is all set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.