From 182eb3cf1d60adfd0e41814b1ceda0187b1c4dd2 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Fri, 14 May 2021 13:04:06 -0400 Subject: [PATCH 1/2] save types and update api --- .../src/views/CRUD/data/database/types.ts | 11 +++++++++++ superset/databases/api.py | 1 + superset/models/core.py | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts b/superset-frontend/src/views/CRUD/data/database/types.ts index d0e6f5114d43f..04a5fd996bba6 100644 --- a/superset-frontend/src/views/CRUD/data/database/types.ts +++ b/superset-frontend/src/views/CRUD/data/database/types.ts @@ -21,6 +21,16 @@ type DatabaseUser = { last_name: string; }; +type DatabaseParameters = { + database: string; + engine: string; + host: string; + password?: string; + port: number; + query: Object; + username: string; +}; + export type DatabaseObject = { // Connection + general id?: number; @@ -30,6 +40,7 @@ export type DatabaseObject = { created_by?: null | DatabaseUser; changed_on_delta_humanized?: string; changed_on?: string; + parameters?: DatabaseParameters; // Performance cache_timeout?: string; diff --git a/superset/databases/api.py b/superset/databases/api.py index 5b795a879f4aa..30ece9964e3ad 100644 --- a/superset/databases/api.py +++ b/superset/databases/api.py @@ -107,6 +107,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi): "allow_ctas", "allow_cvas", "allow_dml", + "parameters", "force_ctas_schema", "allow_multi_schema_metadata_fetch", "impersonate_user", diff --git a/superset/models/core.py b/superset/models/core.py index 54247281e96b3..c9efd79bcc4f3 100755 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -54,7 +54,7 @@ from sqlalchemy.sql import expression, Select from superset import app, db_engine_specs, is_feature_enabled -from superset.db_engine_specs.base import TimeGrain +from superset.db_engine_specs.base import BasicParametersMixin, TimeGrain from superset.extensions import cache_manager, encrypted_field_factory, security_manager from superset.models.helpers import AuditMixinNullable, ImportExportMixin from superset.models.tags import FavStarUpdater @@ -212,6 +212,7 @@ def data(self) -> Dict[str, Any]: "allows_cost_estimate": self.allows_cost_estimate, "allows_virtual_table_explore": self.allows_virtual_table_explore, "explore_database_id": self.explore_database_id, + "parameters": self.parameters, } @property @@ -222,6 +223,17 @@ def unique_name(self) -> str: def url_object(self) -> URL: return make_url(self.sqlalchemy_uri_decrypted) + @property + def parameters(self) -> Optional[Dict[str, Any]]: + # Build parameters if db_engine_spec is a subclass of BasicParametersMixin + parameters = {"engine": self.backend} + + if issubclass(self.db_engine_spec, BasicParametersMixin): + uri = make_url(self.sqlalchemy_uri_decrypted) + return {**parameters, **self.db_engine_spec.get_parameters_from_uri(uri)} + + return parameters + @property def backend(self) -> str: sqlalchemy_url = make_url(self.sqlalchemy_uri_decrypted) @@ -568,10 +580,10 @@ def get_all_schema_names( @property def db_engine_spec(self) -> Type[db_engine_specs.BaseEngineSpec]: - return self.get_db_engine_spec_for_backend(self.backend) + engines = db_engine_specs.get_engine_specs() + return engines.get(self.backend, db_engine_specs.BaseEngineSpec) @classmethod - @utils.memoized def get_db_engine_spec_for_backend( cls, backend: str ) -> Type[db_engine_specs.BaseEngineSpec]: From 5f30cee8e1b4ee503d42f1ed6eddd4c3cd3b2a8f Mon Sep 17 00:00:00 2001 From: hughhhh Date: Fri, 14 May 2021 17:18:19 -0400 Subject: [PATCH 2/2] remove parameters for now --- .../src/views/CRUD/data/database/types.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts b/superset-frontend/src/views/CRUD/data/database/types.ts index 04a5fd996bba6..a2803eda5fac3 100644 --- a/superset-frontend/src/views/CRUD/data/database/types.ts +++ b/superset-frontend/src/views/CRUD/data/database/types.ts @@ -21,15 +21,15 @@ type DatabaseUser = { last_name: string; }; -type DatabaseParameters = { - database: string; - engine: string; - host: string; - password?: string; - port: number; - query: Object; - username: string; -}; +// type DatabaseParameters = { +// database: string; +// engine: string; +// host: string; +// password?: string; +// port: number; +// query: Object; +// username: string; +// }; export type DatabaseObject = { // Connection + general @@ -40,7 +40,7 @@ export type DatabaseObject = { created_by?: null | DatabaseUser; changed_on_delta_humanized?: string; changed_on?: string; - parameters?: DatabaseParameters; + // parameters?: DatabaseParameters; // Performance cache_timeout?: string;