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

Require the SQLAlchemy URI on the database model #8720

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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.
"""add_not_null_to_dbs_sqlalchemy_url

Revision ID: 817e1c9b09d0
Revises: db4b49eb0782
Create Date: 2019-12-03 10:24:16.201580

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "817e1c9b09d0"
down_revision = "89115a40e8ea"


def upgrade():
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"sqlalchemy_uri", existing_type=sa.VARCHAR(length=1024), nullable=False
)


def downgrade():
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"sqlalchemy_uri", existing_type=sa.VARCHAR(length=1024), nullable=True
)
2 changes: 1 addition & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ class Database(Model, AuditMixinNullable, ImportMixin):
verbose_name = Column(String(250), unique=True)
# short unique name, used in permissions
database_name = Column(String(250), unique=True, nullable=False)
sqlalchemy_uri = Column(String(1024))
sqlalchemy_uri = Column(String(1024), nullable=False)
password = Column(EncryptedType(String(1024), config["SECRET_KEY"]))
cache_timeout = Column(Integer)
select_as_create_table_as = Column(Boolean, default=False)
Expand Down
1 change: 1 addition & 0 deletions tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def create_fake_db(self):
cls=models.Database,
criteria={"database_name": database_name},
session=db.session,
sqlalchemy_uri="sqlite://test",
id=db_id,
extra=extra,
)
Expand Down
8 changes: 6 additions & 2 deletions tests/security_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ def test_set_perm_druid_cluster(self):

def test_set_perm_database(self):
session = db.session
database = Database(database_name="tmp_database")
database = Database(
database_name="tmp_database", sqlalchemy_uri="sqlite://test"
)
session.add(database)

stored_db = (
Expand Down Expand Up @@ -346,7 +348,9 @@ def test_set_perm_database(self):

def test_set_perm_slice(self):
session = db.session
database = Database(database_name="tmp_database")
database = Database(
database_name="tmp_database", sqlalchemy_uri="sqlite://test"
)
table = SqlaTable(table_name="tmp_perm_table", database=database)
session.add(database)
session.add(table)
Expand Down