mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
Add verbose name to db and druid cluster (#2429)
* Add verbose name field to the databases * Add migration * Display verbose name in the view.
This commit is contained in:
parent
3d77a12aa9
commit
c3be58db43
@ -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 @@ class DruidCluster(Model, AuditMixinNullable):
|
||||
|
||||
@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):
|
||||
|
@ -103,9 +103,9 @@ appbuilder.add_view_no_menu(DruidMetricInlineView)
|
||||
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']
|
||||
|
@ -0,0 +1,35 @@
|
||||
"""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 logging
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('clusters', sa.Column('verbose_name', sa.String(length=250), nullable=True))
|
||||
op.add_column('dbs', sa.Column('verbose_name', sa.String(length=250), nullable=True))
|
||||
|
||||
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():
|
||||
try:
|
||||
op.drop_column('dbs', 'verbose_name')
|
||||
op.drop_column('clusters', 'verbose_name')
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user