[db migration] change datasources-clusters foreign key to cluster_id (#8576)

* [db migration] change datasources foreign key to cluster_id

* address pr comments

* address pr comment, fix ci
This commit is contained in:
serenajiang
2020-01-13 11:02:36 -08:00
committed by John Bodley
parent d9e7db69fe
commit 1f6f4ed879
9 changed files with 184 additions and 42 deletions

View File

@@ -23,7 +23,12 @@ import yaml
from tests.test_app import app
from superset import db
from superset.connectors.druid.models import DruidColumn, DruidDatasource, DruidMetric
from superset.connectors.druid.models import (
DruidColumn,
DruidDatasource,
DruidMetric,
DruidCluster,
)
from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
from superset.utils.core import get_example_database
from superset.utils.dict_import_export import export_to_dict
@@ -87,11 +92,15 @@ class DictImportExportTests(SupersetTestCase):
return table, dict_rep
def create_druid_datasource(self, name, id=0, cols_names=[], metric_names=[]):
name = "{0}{1}".format(NAME_PREFIX, name)
cluster_name = "druid_test"
cluster = self.get_or_create(
DruidCluster, {"cluster_name": cluster_name}, db.session
)
name = "{0}{1}".format(NAME_PREFIX, name)
params = {DBREF: id, "database_name": cluster_name}
dict_rep = {
"cluster_name": cluster_name,
"cluster_id": cluster.id,
"datasource_name": name,
"id": id,
"params": json.dumps(params),
@@ -102,7 +111,7 @@ class DictImportExportTests(SupersetTestCase):
datasource = DruidDatasource(
id=id,
datasource_name=name,
cluster_name=cluster_name,
cluster_id=cluster.id,
params=json.dumps(params),
)
for col_name in cols_names: