-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03b35b3
commit ce0b8cf
Showing
10 changed files
with
174 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
123 changes: 123 additions & 0 deletions
123
superset/migrations/versions/b6fa807eac07_make_names_non_nullable.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,123 @@ | ||
# 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. | ||
"""make_names_non_nullable | ||
Revision ID: b6fa807eac07 | ||
Revises: 1495eb914ad3 | ||
Create Date: 2019-10-02 00:29:16.679272 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from superset.utils.core import generic_find_fk_constraint_name | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "b6fa807eac07" | ||
down_revision = "1495eb914ad3" | ||
|
||
conv = { | ||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", | ||
"uq": "uq_%(table_name)s_%(column_0_name)s", | ||
} | ||
|
||
|
||
def upgrade(): | ||
bind = op.get_bind() | ||
insp = sa.engine.reflection.Inspector.from_engine(bind) | ||
|
||
# First, drop the foreign key constraint prior to altering columns. | ||
fk_datasources_cluster_name_clusters = ( | ||
generic_find_fk_constraint_name( | ||
"datasources", {"cluster_name"}, "clusters", insp | ||
) | ||
or "fk_datasources_cluster_name_clusters" | ||
) | ||
with op.batch_alter_table("datasources", naming_convention=conv) as batch_op: | ||
batch_op.drop_constraint( | ||
fk_datasources_cluster_name_clusters, type_="foreignkey" | ||
) | ||
|
||
# Second, make the columns non-nullable. | ||
with op.batch_alter_table("datasources") as batch_op: | ||
batch_op.alter_column( | ||
"cluster_name", existing_type=sa.String(250), nullable=False | ||
) | ||
with op.batch_alter_table("clusters") as batch_op: | ||
batch_op.alter_column( | ||
"cluster_name", existing_type=sa.String(250), nullable=False | ||
) | ||
with op.batch_alter_table("dbs") as batch_op: | ||
batch_op.alter_column( | ||
"database_name", existing_type=sa.String(250), nullable=False | ||
) | ||
with op.batch_alter_table("tables") as batch_op: | ||
batch_op.alter_column( | ||
"table_name", existing_type=sa.String(250), nullable=False | ||
) | ||
|
||
# Finally, re-add the foreign key constraint. | ||
with op.batch_alter_table("datasources") as batch_op: | ||
batch_op.create_foreign_key( | ||
fk_datasources_cluster_name_clusters, | ||
"clusters", | ||
["cluster_name"], | ||
["cluster_name"], | ||
) | ||
|
||
|
||
def downgrade(): | ||
bind = op.get_bind() | ||
insp = sa.engine.reflection.Inspector.from_engine(bind) | ||
|
||
# First, drop the foreign key constraint prior to altering columns. | ||
fk_datasources_cluster_name_clusters = ( | ||
generic_find_fk_constraint_name( | ||
"datasources", {"cluster_name"}, "clusters", insp | ||
) | ||
or "fk_datasources_cluster_name_clusters" | ||
) | ||
with op.batch_alter_table("datasources", naming_convention=conv) as batch_op: | ||
batch_op.drop_constraint( | ||
fk_datasources_cluster_name_clusters, type_="foreignkey" | ||
) | ||
|
||
# Second, make the columns nullable. | ||
with op.batch_alter_table("datasources") as batch_op: | ||
batch_op.alter_column( | ||
"cluster_name", existing_type=sa.String(250), nullable=True | ||
) | ||
|
||
with op.batch_alter_table("clusters") as batch_op: | ||
batch_op.alter_column( | ||
"cluster_name", existing_type=sa.String(250), nullable=True | ||
) | ||
with op.batch_alter_table("dbs") as batch_op: | ||
batch_op.alter_column( | ||
"database_name", existing_type=sa.String(250), nullable=True | ||
) | ||
with op.batch_alter_table("tables") as batch_op: | ||
batch_op.alter_column("table_name", existing_type=sa.String(250), nullable=True) | ||
|
||
# Finally, re-add the foreign key constraint. | ||
with op.batch_alter_table("datasources") as batch_op: | ||
batch_op.create_foreign_key( | ||
fk_datasources_cluster_name_clusters, | ||
"clusters", | ||
["cluster_name"], | ||
["cluster_name"], | ||
) |
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
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
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
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
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 |
---|---|---|
|
@@ -32,7 +32,7 @@ class DatabaseModelTestCase(SupersetTestCase): | |
) | ||
def test_database_schema_presto(self): | ||
sqlalchemy_uri = "presto://presto.airbnb.io:8080/hive/default" | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
model = Database(database_name="test_database", sqlalchemy_uri=sqlalchemy_uri) | ||
|
||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals("hive/default", db) | ||
|
@@ -41,7 +41,7 @@ def test_database_schema_presto(self): | |
self.assertEquals("hive/core_db", db) | ||
|
||
sqlalchemy_uri = "presto://presto.airbnb.io:8080/hive" | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
model = Database(database_name="test_database", sqlalchemy_uri=sqlalchemy_uri) | ||
|
||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals("hive", db) | ||
|
@@ -51,7 +51,7 @@ def test_database_schema_presto(self): | |
|
||
def test_database_schema_postgres(self): | ||
sqlalchemy_uri = "postgresql+psycopg2://postgres.airbnb.io:5439/prod" | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
model = Database(database_name="test_database", sqlalchemy_uri=sqlalchemy_uri) | ||
|
||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals("prod", db) | ||
|
@@ -67,7 +67,7 @@ def test_database_schema_postgres(self): | |
) | ||
def test_database_schema_hive(self): | ||
sqlalchemy_uri = "hive://[email protected]:10000/default?auth=NOSASL" | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
model = Database(database_name="test_database", sqlalchemy_uri=sqlalchemy_uri) | ||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals("default", db) | ||
|
||
|
@@ -79,7 +79,7 @@ def test_database_schema_hive(self): | |
) | ||
def test_database_schema_mysql(self): | ||
sqlalchemy_uri = "mysql://root@localhost/superset" | ||
model = Database(sqlalchemy_uri=sqlalchemy_uri) | ||
model = Database(database_name="test_database", sqlalchemy_uri=sqlalchemy_uri) | ||
|
||
db = make_url(model.get_sqla_engine().url).database | ||
self.assertEquals("superset", db) | ||
|
@@ -93,7 +93,7 @@ def test_database_schema_mysql(self): | |
def test_database_impersonate_user(self): | ||
uri = "mysql://root@localhost" | ||
example_user = "giuseppe" | ||
model = Database(sqlalchemy_uri=uri) | ||
model = Database(database_name="test_database", sqlalchemy_uri=uri) | ||
|
||
model.impersonate_user = True | ||
user_name = make_url(model.get_sqla_engine(user_name=example_user).url).username | ||
|
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