From 2428dfd21bb7a53132723806457137a261cfa0ea Mon Sep 17 00:00:00 2001 From: Bogdan Kyryliuk Date: Thu, 16 Mar 2017 18:08:45 -0700 Subject: [PATCH 1/3] Add verbose name field to the databases --- superset/connectors/druid/models.py | 10 ++++++++-- superset/models/core.py | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py index 33683508f52bb..788c1a5a1a4ea 100644 --- a/superset/connectors/druid/models.py +++ b/superset/connectors/druid/models.py @@ -57,6 +57,8 @@ class DruidCluster(Model, AuditMixinNullable): type = "druid" id = Column(Integer, primary_key=True) + verbose_name = Column(String(250), unique=True) + # short unique name, used in permissions cluster_name = Column(String(250), unique=True) coordinator_host = Column(String(255)) coordinator_port = Column(Integer) @@ -69,7 +71,7 @@ class DruidCluster(Model, AuditMixinNullable): cache_timeout = Column(Integer) def __repr__(self): - return self.cluster_name + return self.verbose_name if self.verbose_name else self.cluster_name def get_pydruid_client(self): cli = PyDruid( @@ -107,7 +109,11 @@ def perm(self): @property def name(self): - return self.cluster_name + return self.verbose_name if self.verbose_name else self.cluster_name + + @property + def unique_name(self): + return self.verbose_name if self.verbose_name else self.cluster_name class DruidColumn(Model, BaseColumn): diff --git a/superset/models/core.py b/superset/models/core.py index d7fb2d9c9897b..c31267f577ea5 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -505,6 +505,8 @@ class Database(Model, AuditMixinNullable): type = "table" id = Column(Integer, primary_key=True) + verbose_name = Column(String(250), unique=True) + # short unique name, used in permissions database_name = Column(String(250), unique=True) sqlalchemy_uri = Column(String(1024)) password = Column(EncryptedType(String(1024), config.get('SECRET_KEY'))) @@ -525,10 +527,14 @@ class Database(Model, AuditMixinNullable): perm = Column(String(1000)) def __repr__(self): - return self.database_name + return self.verbose_name if self.verbose_name else self.database_name @property def name(self): + return self.verbose_name if self.verbose_name else self.database_name + + @property + def unique_name(self): return self.database_name @property From e53a98a9286565bb3b081f2628cfd8a9825b7792 Mon Sep 17 00:00:00 2001 From: Bogdan Kyryliuk Date: Thu, 16 Mar 2017 18:15:38 -0700 Subject: [PATCH 2/3] Add migration --- .../db527d8c4c78_add_db_verbose_name.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py diff --git a/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py b/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py new file mode 100644 index 0000000000000..66b8936ca265e --- /dev/null +++ b/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py @@ -0,0 +1,28 @@ +"""Add verbose name to DruidCluster and Database + +Revision ID: db527d8c4c78 +Revises: b318dfe5fb6c +Create Date: 2017-03-16 18:10:57.193035 + +""" + +# revision identifiers, used by Alembic. +revision = 'db527d8c4c78' +down_revision = 'b318dfe5fb6c' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('clusters', sa.Column('verbose_name', sa.String(length=250), nullable=True)) + op.create_unique_constraint(None, 'clusters', ['verbose_name']) + op.add_column('dbs', sa.Column('verbose_name', sa.String(length=250), nullable=True)) + op.create_unique_constraint(None, 'dbs', ['verbose_name']) + + +def downgrade(): + op.drop_constraint(None, 'dbs', type_='unique') + op.drop_column('dbs', 'verbose_name') + op.drop_constraint(None, 'clusters', type_='unique') + op.drop_column('clusters', 'verbose_name') From 4bc297565ef535eca6f3f33f66487abfd565ad84 Mon Sep 17 00:00:00 2001 From: Bogdan Kyryliuk Date: Thu, 16 Mar 2017 18:18:43 -0700 Subject: [PATCH 3/3] Display verbose name in the view. --- superset/connectors/druid/views.py | 6 +++--- .../db527d8c4c78_add_db_verbose_name.py | 19 +++++++++++++------ superset/views/core.py | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/superset/connectors/druid/views.py b/superset/connectors/druid/views.py index d86e380295269..92e24f9d865a4 100644 --- a/superset/connectors/druid/views.py +++ b/superset/connectors/druid/views.py @@ -103,9 +103,9 @@ def post_update(self, metric): class DruidClusterModelView(SupersetModelView, DeleteMixin): # noqa datamodel = SQLAInterface(models.DruidCluster) add_columns = [ - 'cluster_name', - 'coordinator_host', 'coordinator_port', 'coordinator_endpoint', - 'broker_host', 'broker_port', 'broker_endpoint', 'cache_timeout', + 'verbose_name', 'coordinator_host', 'coordinator_port', + 'coordinator_endpoint', 'broker_host', 'broker_port', + 'broker_endpoint', 'cache_timeout', 'cluster_name', ] edit_columns = add_columns list_columns = ['cluster_name', 'metadata_last_refreshed'] diff --git a/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py b/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py index 66b8936ca265e..e4a36197a3b67 100644 --- a/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py +++ b/superset/migrations/versions/db527d8c4c78_add_db_verbose_name.py @@ -11,18 +11,25 @@ down_revision = 'b318dfe5fb6c' from alembic import op +import logging import sqlalchemy as sa def upgrade(): op.add_column('clusters', sa.Column('verbose_name', sa.String(length=250), nullable=True)) - op.create_unique_constraint(None, 'clusters', ['verbose_name']) op.add_column('dbs', sa.Column('verbose_name', sa.String(length=250), nullable=True)) - op.create_unique_constraint(None, 'dbs', ['verbose_name']) + + try: + op.create_unique_constraint(None, 'dbs', ['verbose_name']) + op.create_unique_constraint(None, 'clusters', ['verbose_name']) + except Exception as e: + logging.exception(e) def downgrade(): - op.drop_constraint(None, 'dbs', type_='unique') - op.drop_column('dbs', 'verbose_name') - op.drop_constraint(None, 'clusters', type_='unique') - op.drop_column('clusters', 'verbose_name') + try: + op.drop_column('dbs', 'verbose_name') + op.drop_column('clusters', 'verbose_name') + except Exception as e: + logging.exception(e) + diff --git a/superset/views/core.py b/superset/views/core.py index ad8ce14286fa2..93f5166d4b218 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -207,8 +207,8 @@ def generate_download_headers(extension): class DatabaseView(SupersetModelView, DeleteMixin): # noqa datamodel = SQLAInterface(models.Database) list_columns = [ - 'database_name', 'backend', 'allow_run_sync', 'allow_run_async', - 'allow_dml', 'creator', 'changed_on_'] + 'verbose_name', 'backend', 'allow_run_sync', 'allow_run_async', + 'allow_dml', 'creator', 'changed_on_', 'database_name'] add_columns = [ 'database_name', 'sqlalchemy_uri', 'cache_timeout', 'extra', 'expose_in_sqllab', 'allow_run_sync', 'allow_run_async',