-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Misc. fixes to migration revision scripts #15746
Misc. fixes to migration revision scripts #15746
Conversation
package test failure unrelated. |
lib/galaxy/model/migrations/alembic/versions_gxy/518c8438a91b_add_when_expression_column.py
Outdated
Show resolved
Hide resolved
I don't know if this is the right approach, it seems like you'd easily be left with columns that were never merged into a stable release, or columns that don't have the right type. If you're working on migrations yourself you check out the branch that added the migration and you downgrade, it has worked like that since we've added migrations, I am worried about hard to predict database schemas here. |
We do it, just inconsistently (here, here and here: we check when upgrading, but we don't check when downgrading - which was an oversight). In the past (pre-alembic), we did it for everything (like this): we logged an exception, but proceeded without raising one. I see your point. But I think the logic here is harmless. Here's what happens:
It is, actually, much tighter than previously (where we logged any exception and proceeded): if a step fails, migrations don't proceed. It does not apply to altering a column. When we add that type of revision, we won't be checking for column existence. If I end up with an invalid In summary, I think this approach is reasonably safe (and consistent), but I'm absolutely open to considering other approaches. (As a minor change, do you think |
That doesn't seem safe to me. The things you've linked seem suboptimal, but we're probably copied from someplace ?
How is this safe ? If you look at the else branch of drop_index and add_column, do you really think that is safe ?
That's the big thing I think we're doing wrong, how can this happen outside of an alembic bug ?
How can that possibly be safe if the code doesn't know a revision ? |
Closed in favor of #15811 |
These fixes were triggered by a variety of migration errors experienced independently by @ahmedhamidawan and myself in (at least) two different contexts while moving between revisions. These fixes should address all or most of the root causes.
Inlcuded:
./manage_db.sh upgrade
(or downgrade) because most conflicting steps raised an error. This fixes it: migration steps that conflict with the state of the database will be noops, with appropriate messages logged. Also, now one can simply delete the rows fromalembic_version
and run./manage_db.sh upgrade
: all migrations will be re-applied regardless of the state of the database.alter
operations: this is required to make column additions/drops possible under SQLite; this was used for adding columns, but not dropping (this may have caused inconsistent sqlite database state in dev environments).alter
operations: this raises an error under sqlite: there's no elegant fix for this.It seems reasonable to target
release_23.0
, as this fixes some bugs; but I can re-target todev
if needed.How to test the changes?
(Select all options that apply)
psql -c "\c your-database" -c "delete from alembic_version;"
This empties the version table./manage_db.sh upgrade
Observe error../manage_db.sh dbversion
or psql to your database)database_connection
inconfig/galaxy.yml
to point to a sqlite database. Then redo the steps above (using sqlite3 instead of psql).License