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

Can not longer "downgrade base" in 1.6.0 #838

Closed
nhumrich opened this issue May 6, 2021 · 11 comments
Closed

Can not longer "downgrade base" in 1.6.0 #838

nhumrich opened this issue May 6, 2021 · 11 comments
Labels
bug Something isn't working versioning model

Comments

@nhumrich
Copy link

nhumrich commented May 6, 2021

Describe the bug
alembic downgrade no longer recognizes the revision "base", and likewise, you can no longer downgrade completely.
When you run downgrade base, you get an error that the revision base is not found.

This works great on any previous alembic version. Is broken in 1.6.0

Expected behavior
alembic downgrade base should downgrade all revisions.

To Reproduce
Install the alembic 1.6.0, have some revisions, upgrade to head, then run alembic downgrade base.

# Copy error here. Please include the full stack trace.
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
ERROR [alembic.util.messaging] Destination base is not a valid downgrade target from current head(s)
  FAILED: Destination base is not a valid downgrade target from current head(s)

Versions.

  • OS: linux
  • Python: 3.9.4
  • Alembic: 1.6.0
  • SQLAlchemy: 1.4.13
  • Database: postgres
  • DBAPI: psycopg2
@nhumrich nhumrich added the requires triage New issue that requires categorization label May 6, 2021
@zzzeek zzzeek added awaiting info waiting for the submitter to give more information bug Something isn't working cant reproduce versioning model and removed requires triage New issue that requires categorization labels May 6, 2021
@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

hi there -

We need to see a revision structure that reproduces this. "alembic downgrade base" is of course tested and working with a fresh set of files as below, there's no issue:

[classic@photon3 alembic:master]$ PYTHONPATH=~/dev/sqlalchemy/lib/ python -m alembic init foo
  Creating directory /home/classic/dev/alembic/foo ...  done
  Creating directory /home/classic/dev/alembic/foo/versions ...  done
  Generating /home/classic/dev/alembic/foo/script.py.mako ...  done
  Generating /home/classic/dev/alembic/foo/README ...  done
  File /home/classic/dev/alembic/alembic.ini already exists, skipping
  Generating /home/classic/dev/alembic/foo/env.py ...  done
  Please edit configuration/connection/logging settings in '/home/classic/dev/alembic/alembic.ini' before proceeding.
[classic@photon3 alembic:master]$ PYTHONPATH=~/dev/sqlalchemy/lib/ python -m alembic revision -m "rev1" 
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] SELECT alembic_version.version_num 
FROM alembic_version
INFO  [sqlalchemy.engine.Engine] [generated in 0.00009s] ()
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] COMMIT
  Generating /home/classic/dev/alembic/foo/versions/ee80fc2540c6_rev1.py ...  done
  Running post write hook "black" ...
reformatted /home/classic/dev/alembic/foo/versions/ee80fc2540c6_rev1.py
All done! ✨ 🍰 ✨
1 file reformatted.
  done
  Running post write hook "zimports" ...
[Writing]       /home/classic/dev/alembic/foo/versions/ee80fc2540c6_rev1.py ([18% of lines are imports] [source +0L/-1L] [1 imports removed in 0.0023 sec])
  done
[classic@photon3 alembic:master]$ PYTHONPATH=~/dev/sqlalchemy/lib/ python -m alembic revision -m "rev2" 
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] SELECT alembic_version.version_num 
FROM alembic_version
INFO  [sqlalchemy.engine.Engine] [generated in 0.00008s] ()
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] COMMIT
  Generating /home/classic/dev/alembic/foo/versions/1e3337826fb7_rev2.py ...  done
  Running post write hook "black" ...
reformatted /home/classic/dev/alembic/foo/versions/1e3337826fb7_rev2.py
All done! ✨ 🍰 ✨
1 file reformatted.
  done
  Running post write hook "zimports" ...
[Writing]       /home/classic/dev/alembic/foo/versions/1e3337826fb7_rev2.py ([18% of lines are imports] [source +0L/-1L] [1 imports removed in 0.0022 sec])
  done
[classic@photon3 alembic:master]$ PYTHONPATH=~/dev/sqlalchemy/lib/ python -m alembic upgrade head
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] SELECT alembic_version.version_num 
FROM alembic_version
INFO  [sqlalchemy.engine.Engine] [generated in 0.00007s] ()
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] COMMIT
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [alembic.runtime.migration] Running upgrade  -> ee80fc2540c6, rev1
INFO  [sqlalchemy.engine.Engine] INSERT INTO alembic_version (version_num) VALUES ('ee80fc2540c6')
INFO  [sqlalchemy.engine.Engine] [generated in 0.00008s] ()
INFO  [sqlalchemy.engine.Engine] COMMIT
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [alembic.runtime.migration] Running upgrade ee80fc2540c6 -> 1e3337826fb7, rev2
INFO  [sqlalchemy.engine.Engine] UPDATE alembic_version SET version_num='1e3337826fb7' WHERE alembic_version.version_num = 'ee80fc2540c6'
INFO  [sqlalchemy.engine.Engine] [generated in 0.00007s] ()
INFO  [sqlalchemy.engine.Engine] COMMIT
[classic@photon3 alembic:master]$ PYTHONPATH=~/dev/sqlalchemy/lib/ python -m alembic downgrade base
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [sqlalchemy.engine.Engine] PRAGMA main.table_info("alembic_version")
INFO  [sqlalchemy.engine.Engine] [raw sql] ()
INFO  [sqlalchemy.engine.Engine] SELECT alembic_version.version_num 
FROM alembic_version
INFO  [sqlalchemy.engine.Engine] [generated in 0.00008s] ()
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [alembic.runtime.migration] Running downgrade 1e3337826fb7 -> ee80fc2540c6, rev2
INFO  [sqlalchemy.engine.Engine] UPDATE alembic_version SET version_num='ee80fc2540c6' WHERE alembic_version.version_num = '1e3337826fb7'
INFO  [sqlalchemy.engine.Engine] [generated in 0.00008s] ()
INFO  [sqlalchemy.engine.Engine] COMMIT
INFO  [sqlalchemy.engine.Engine] BEGIN (implicit)
INFO  [alembic.runtime.migration] Running downgrade ee80fc2540c6 -> , rev1
INFO  [sqlalchemy.engine.Engine] DELETE FROM alembic_version WHERE alembic_version.version_num = 'ee80fc2540c6'
INFO  [sqlalchemy.engine.Engine] [generated in 0.00007s] ()
INFO  [sqlalchemy.engine.Engine] COMMIT

@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

cc @simonbowly

@nhumrich
Copy link
Author

nhumrich commented May 6, 2021

Here is my revision chain, its just a linear graph, no branches.

2495d6ed2fca -> 93db6fd0a57f (head), add description
c58c10dde263 -> 2495d6ed2fca, increse limit
3094b6d27bc4 -> c58c10dde263, components
2774eb193274 -> 3094b6d27bc4, datamigration2
f8d63b07d4d1 -> 2774eb193274, datamigration1
e7aa88f1f76f -> f8d63b07d4d1, id on components
434c3ca80478 -> e7aa88f1f76f, Remove role
a8312bc2775a -> 434c3ca80478, commenting system
5b16eb9c9524 -> a8312bc2775a, config is specific
c8213684c654 -> 5b16eb9c9524, conversion migration
7b34feaad1eb -> c8213684c654, add default column
54cc14b31868 -> 7b34feaad1eb, id should be text
90785ecd62d7 -> 54cc14b31868, add components table
38a452b30df8 -> 90785ecd62d7, add records table
b204470cfb8f -> 38a452b30df8, natural sort things
<base> -> b204470cfb8f, initial structure```

@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

is your project open source ?

@nhumrich
Copy link
Author

nhumrich commented May 6, 2021

no. Let me see if I can reproduce somehow

@nhumrich
Copy link
Author

nhumrich commented May 6, 2021

Ok, I found the issue. The issue is when the database is completely clean, aka, there is no alembic_version table in the database.

We run a "reset database" script that cleans the database in a test environment. Sometimes the database is already clean. Before, downgrade base would work, even on a clean database. Now, it breaks if there isn't a alembic_versions table.

@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

OK that sounds more localized, let's see

@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

OK! sure I just run "downgrade base" again and I get the error :)

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

narrow rangenotancestor to exclude target heads already present https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/2810

@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

thanks for reporting!

@zzzeek zzzeek removed awaiting info waiting for the submitter to give more information cant reproduce labels May 6, 2021
@zzzeek
Copy link
Member

zzzeek commented May 6, 2021

jhust FYI that's been released in 1.6.1, you should have no problems now let me know otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working versioning model
Projects
None yet
Development

No branches or pull requests

3 participants