-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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: alter sql columns to long text #7463
Merged
betodealmeida
merged 5 commits into
apache:lyft-release-sp8
from
lyft:alter_sql_columns_to_long_text
May 8, 2019
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
61 changes: 61 additions & 0 deletions
61
superset/migrations/versions/afc69274c25a_update_sql_column_data_type_in_query_.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,61 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""update the sql, select_sql, and executed_sql columns in the | ||
query table to support larger text | ||
|
||
Revision ID: afc69274c25a | ||
Revises: e9df189e5c7e | ||
Create Date: 2019-05-06 14:30:26.181449 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'afc69274c25a' | ||
down_revision = 'e9df189e5c7e' | ||
|
||
text_len = 10 ** 9 - 1 | ||
|
||
|
||
def upgrade(): | ||
try: | ||
# Set text length if database accepts it | ||
with op.batch_alter_table('query') as batch_op: | ||
batch_op.alter_column( | ||
'sql', existing_type=sa.Text, type_=sa.Text(length=text_len)) | ||
batch_op.alter_column( | ||
'select_sql', existing_type=sa.Text, type_=sa.Text(length=text_len)) | ||
batch_op.alter_column( | ||
'executed_sql', existing_type=sa.Text, type_=sa.Text(length=text_len)) | ||
except: | ||
# Many databases do not have a length on text objects | ||
# so skip altering for those databases | ||
pass | ||
|
||
|
||
def downgrade(): | ||
try: | ||
with op.batch_alter_table('query') as batch_op: | ||
batch_op.alter_column( | ||
'sql', existing_type=sa.Text(length=text_len), type_=sa.Text) | ||
batch_op.alter_column( | ||
'select_sql', existing_type=sa.Text(length=text_len), type_=sa.Text) | ||
batch_op.alter_column( | ||
'executed_sql', existing_type=sa.Text(length=text_len), type_=sa.Text) | ||
except: | ||
pass |
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.
I'd prefer having a MySQL-specific if block then a
try
silencing all errorsThere 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.
Actually after reading https://docs.sqlalchemy.org/en/13/core/type_basics.html#sqlalchemy.types.Text I'm not sure either way. It's probably ok as is since catching a more specific exception might be hard because driver-specific...
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 would feel uncomfortable leaving a migration in an indeterminate state thought... this is a bit ugly but since there is divergent behavior between dbs for this column type, what about:
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.
Wait, are you suggesting that if it errors out then it didn't wan't/need the migration in the first place? That makes sense to me I think.
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.
Yes, if it errors out, it doesn't need the migration in the first place.
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.
Just a thought for the record: If we get rid of the
batch_alter_table
, it will fail after the first one and we will skip it gracefully. I think that's what we want. Not sure we need the batch here. A failure will fail as a batch anyway. Some really weird degenerate case would be if it is a mysql db and gets through 1 or 2 then the db crashes leaving one unmigrated. But that is not a catastrophic bad state.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 ended up making the migration script only update the query table for mysql dbs. I know that it is very specific to Lyft's situation but I felt that my original implementation was not a good solution since every db has different requirements and data storage sizes for Text columns. So I don't think it is a good idea for me to try to set an arbitrary size and I wouldn't be surprised if it messed up for some other dbs.