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]: