-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Fix #529 2 - "This Session's transaction has been rolled back" #531
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6de50b5
Created migration to fix the bug
29ffe03
Working also on MySQL
839fb02
Update models.py (#541)
jimexist 1ff5304
Added support for Vertica Grains (#515)
LAlbertalli e283af9
i18n: Fix typo in Druid cluster broker port label (#512)
xrmx 1650138
Fix #529 1 "This Session's transaction has been rolled back" (#530)
LAlbertalli 938f6cd
Modified the migration function to to automatically detect the the fo…
7308cf6
Merge branch 'master' into fix529-2
LAlbertalli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
caravel/migrations/versions/1226819ee0e3_fix_wrong_constraint_on_table_columns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Fix wrong constraint on table columns | ||
|
||
Revision ID: 1226819ee0e3 | ||
Revises: 956a063c52b3 | ||
Create Date: 2016-05-27 15:03:32.980343 | ||
|
||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '1226819ee0e3' | ||
down_revision = '956a063c52b3' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
naming_convention = { | ||
"fk": | ||
"fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
} | ||
|
||
def find_constraint_name(upgrade = True): | ||
__table = 'columns' | ||
__cols = {'column_name'} if upgrade else {'datasource_name'} | ||
__referenced = 'datasources' | ||
__ref_cols = {'datasource_name'} if upgrade else {'column_name'} | ||
|
||
engine = op.get_bind().engine | ||
m = sa.MetaData({}) | ||
t=sa.Table(__table,m, autoload=True, autoload_with=engine) | ||
|
||
for fk in t.foreign_key_constraints: | ||
if fk.referred_table.name == __referenced and \ | ||
set(fk.column_keys) == __cols: | ||
return fk.name | ||
return None | ||
|
||
def upgrade(): | ||
constraint = find_constraint_name() or 'fk_columns_column_name_datasources' | ||
with op.batch_alter_table("columns", | ||
naming_convention=naming_convention) as batch_op: | ||
batch_op.drop_constraint(constraint, type_="foreignkey") | ||
batch_op.create_foreign_key('fk_columns_datasource_name_datasources', 'datasources', ['datasource_name'], ['datasource_name']) | ||
|
||
def downgrade(): | ||
constraint = find_constraint_name(False) or 'fk_columns_datasource_name_datasources' | ||
with op.batch_alter_table("columns", | ||
naming_convention=naming_convention) as batch_op: | ||
batch_op.drop_constraint(constraint, type_="foreignkey") | ||
batch_op.create_foreign_key('fk_columns_column_name_datasources', 'datasources', ['column_name'], ['datasource_name']) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On top of this should we probabily generalize this function so can be reused in other migrations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in general.
There's just a question of timing, I don't have much time to dedicate on this bug fix right now and I think this issue is pretty urgent (basically Druid doesn't work on any DB that support Foreign Keys).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, i can do it after this is in :)