什么是 Superset
Superset 是一款由 Airbnb 开源的“现代化的企业级 BI(商业智能) Web 应用程序”,其通过创建和分享 dashboard,为数据分析提供了轻量级的数据查询和可视化方案。
Superset 的前端主要用到了 React 和 NVD3/D3,而后端则基于 Python 的 Flask 框架和 Pandas、SQLAlchemy 等依赖库,主要提供了这几方面的功能:
- 集成数据查询功能,支持多种数据库,包括 MySQL、PostgresSQL、Oracle、SQL Server、SQLite、SparkSQL 等,并深度支持 Druid。
- 通过 NVD3/D3 预定义了多种可视化图表,满足大部分的数据展示功能。如果还有其他需求,也可以自开发更多的图表类型,或者嵌入其他的 JavaScript 图表库(如 HighCharts、ECharts)。
- 提供细粒度安全模型,可以在功能层面和数据层面进行访问控制。支持多种鉴权方式(如数据库、OpenID、LDAP、OAuth、REMOTE_USER 等)。
准备环境
声明:本安装手册基于 Mac 系统搭建。
安装 conda
用于管理 Python 环境。
这一步很简单,首先访问清华镜像网站,https://mirrors.tuna.tsinghua.edu.cn/,如下图所示,点击【获取下载链接】。
在弹出的界面中,选择应用软件,选择 Conda,点击下载如图所示的 Mac 安装包即可,选择mini版就行,安装包很很小。
下载完成,双击打开安装即可,我已经安装过了,这里就不演示了,一路next即可。
安装完成之后,验证安装成功,运行 conda env list ,不报错就表示成功了。
创建虚拟环境
上一节我们安装了 conda,在本节中可以发挥它的作用啦。
1.创建虚拟环境,在终端执行以下命令,xxx 为环境的名字,这里随便起。
conda create -n xxx python=python3.7
2.激活环境,xxx 为你刚刚起的名字。
conda activate xxx
激活之后,终端会变成这样:注意,我的环境名字是 superset-env,所以这里前面会显示这个名字。
需要注意的是,如果新开一个终端,需要手动执行 conda activate xxx
来使得终端用的是你刚刚创建的虚拟环境。
这一小节就结束了,是不是很简单啊?哈哈哈哈
下载 Superset 源码
现在技术人访问 Github 的速度大不如从前了,所以这里非常推荐大家使用码云的一个免费服务来下载 GitHub上面的仓库代码。具体操作如下:
浏览器访问:https://gitee.com/mirrors,然后在搜索框搜索:superset
复制仓库地址之后,执行一下命令,拉到本地
git clone https://gitee.com/mirrors/Superset.git
等待片刻即可。
配置后端
进入项目代码目录,可以看到项目结构如下:
.
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── DISCLAIMER
├── Dockerfile
├── Dockerfile-dev
├── INSTALL.md
├── LICENSE.txt
├── MANIFEST.in
├── NOTICE
├── README.md
├── RELEASING
├── UPDATING.md
├── alembic.ini
├── apache_superset.egg-info
├── babel-node
├── docker
├── docker-compose.yml
├── docs
├── gen_changelog.sh
├── helm
├── pypi_push.sh
├── requirements-dev.txt
├── requirements.txt
├── scripts
├── setup.cfg
├── setup.py
├── superset
├── superset-frontend
├── tests
└── tox.ini
安装依赖
下面,开始安装服务端项目依赖,注意,需要保证自己的终端激活了虚拟环境。
执行 pip install -r requirements.txt,等待执行结束。
执行 pip install -r requirements-dev.txt 等待结束。这里可能会报错,安装 pydruid 的时候,可以先单独安装下面两个语句:
pip install --user pytest-runner
pip install pydruid
# 然后执行下面
pip install -r requirements-dev.txt
执行 pip install -e .
注意,后面有个 点
配置数据库
这里项目默认使用 sqllite 数据库,也支持配置成其他的,比如 Mysql,我这里本地正好装了 Mysql,就改成 Mysql 吧,怎么改呢,看下面:
找到 superset/config.py 文件,找到这个配置项 SQLALCHEMY_DATABASE_URI
从图中,可以看出 默认是用的 sqllite 数据,我这里改成 mysql。
安装 mysql 的依赖,python 3.7 安装 mysql 客户端方法如下:pip install mysqlclient
配置管理员信息
执行 superset fab create-admin
执行 superset db upgrade
执行 superset init
执行 superset load_examples,这个执行过程中可能会遇到网络超时,多次执行这个语句即可。
执行 FLASK_ENV=development superset run -p 8088 —with-threads —reload —debugger
配置前端
安装 Node
访问 https://nodejs.org/zh-cn/ 直接安装即可。
安装前端依赖
cd superset-frontend
执行 npm ci 安装依赖,依赖来自 package-lock.json
启动前端 npm run dev-server
界面
根据之前启动,默认是监听 9000 端口,浏览器王文 localhost:9000 即可访问主界面。
数据库设计
语句
create table if not exists superset.ab_permission
(
id int auto_increment
primary key,
name varchar(100) not null,
constraint name
unique (name)
);
create table if not exists superset.ab_register_user
(
id int auto_increment
primary key,
first_name varchar(64) not null,
last_name varchar(64) not null,
username varchar(64) not null,
password varchar(256) null,
email varchar(64) not null,
registration_date datetime null,
registration_hash varchar(256) null,
constraint username
unique (username)
);
create table if not exists superset.ab_role
(
id int auto_increment
primary key,
name varchar(64) not null,
constraint name
unique (name)
);
create table if not exists superset.ab_user
(
id int auto_increment
primary key,
first_name varchar(64) not null,
last_name varchar(64) not null,
username varchar(64) not null,
password varchar(256) null,
active tinyint(1) null,
email varchar(64) not null,
last_login datetime null,
login_count int null,
fail_login_count int null,
created_on datetime null,
changed_on datetime null,
created_by_fk int null,
changed_by_fk int null,
constraint email
unique (email),
constraint username
unique (username),
constraint ab_user_ibfk_1
foreign key (created_by_fk) references superset.ab_user (id),
constraint ab_user_ibfk_2
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.ab_user (changed_by_fk);
create index created_by_fk
on superset.ab_user (created_by_fk);
create table if not exists superset.ab_user_role
(
id int auto_increment
primary key,
user_id int null,
role_id int null,
constraint user_id
unique (user_id, role_id),
constraint ab_user_role_ibfk_1
foreign key (user_id) references superset.ab_user (id),
constraint ab_user_role_ibfk_2
foreign key (role_id) references superset.ab_role (id)
);
create index role_id
on superset.ab_user_role (role_id);
create table if not exists superset.ab_view_menu
(
id int auto_increment
primary key,
name varchar(255) not null,
constraint name
unique (name)
);
create table if not exists superset.ab_permission_view
(
id int auto_increment
primary key,
permission_id int null,
view_menu_id int null,
constraint permission_id
unique (permission_id, view_menu_id),
constraint ab_permission_view_ibfk_1
foreign key (permission_id) references superset.ab_permission (id),
constraint ab_permission_view_ibfk_2
foreign key (view_menu_id) references superset.ab_view_menu (id)
);
create index view_menu_id
on superset.ab_permission_view (view_menu_id);
create table if not exists superset.ab_permission_view_role
(
id int auto_increment
primary key,
permission_view_id int null,
role_id int null,
constraint permission_view_id
unique (permission_view_id, role_id),
constraint ab_permission_view_role_ibfk_1
foreign key (permission_view_id) references superset.ab_permission_view (id),
constraint ab_permission_view_role_ibfk_2
foreign key (role_id) references superset.ab_role (id)
);
create index role_id
on superset.ab_permission_view_role (role_id);
create table if not exists superset.access_request
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
datasource_type varchar(200) null,
datasource_id int null,
changed_by_fk int null,
created_by_fk int null,
constraint access_request_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint access_request_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.access_request (changed_by_fk);
create index created_by_fk
on superset.access_request (created_by_fk);
create table if not exists superset.alembic_version
(
version_num varchar(32) not null
primary key
);
create table if not exists superset.annotation_layer
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
name varchar(250) null,
descr text null,
changed_by_fk int null,
created_by_fk int null,
constraint annotation_layer_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint annotation_layer_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id)
);
create table if not exists superset.annotation
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
start_dttm datetime null,
end_dttm datetime null,
layer_id int null,
short_descr varchar(500) null,
long_descr text null,
changed_by_fk int null,
created_by_fk int null,
json_metadata text null,
constraint annotation_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint annotation_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint annotation_ibfk_3
foreign key (layer_id) references superset.annotation_layer (id)
);
create index changed_by_fk
on superset.annotation (changed_by_fk);
create index created_by_fk
on superset.annotation (created_by_fk);
create index ti_dag_state
on superset.annotation (layer_id, start_dttm, end_dttm);
create index changed_by_fk
on superset.annotation_layer (changed_by_fk);
create index created_by_fk
on superset.annotation_layer (created_by_fk);
create table if not exists superset.clusters
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
cluster_name varchar(250) not null,
broker_host varchar(255) null,
broker_port int null,
broker_endpoint varchar(255) null,
metadata_last_refreshed datetime null,
created_by_fk int null,
changed_by_fk int null,
cache_timeout int null,
verbose_name varchar(250) null,
broker_pass blob null,
broker_user varchar(255) null,
constraint cluster_name
unique (cluster_name),
constraint verbose_name
unique (verbose_name),
constraint clusters_ibfk_1
foreign key (created_by_fk) references superset.ab_user (id),
constraint clusters_ibfk_2
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.clusters (changed_by_fk);
create index created_by_fk
on superset.clusters (created_by_fk);
create table if not exists superset.css_templates
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
template_name varchar(250) null,
css text null,
changed_by_fk int null,
created_by_fk int null,
constraint css_templates_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint css_templates_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.css_templates (changed_by_fk);
create index created_by_fk
on superset.css_templates (created_by_fk);
create table if not exists superset.dashboards
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
dashboard_title varchar(500) null,
position_json mediumtext null,
created_by_fk int null,
changed_by_fk int null,
css text null,
description text null,
slug varchar(255) null,
json_metadata text null,
published tinyint(1) null,
constraint idx_unique_slug
unique (slug),
constraint dashboards_ibfk_1
foreign key (created_by_fk) references superset.ab_user (id),
constraint dashboards_ibfk_2
foreign key (changed_by_fk) references superset.ab_user (id)
);
create table if not exists superset.dashboard_email_schedules
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
active tinyint(1) null,
crontab varchar(50) null,
recipients text null,
deliver_as_group tinyint(1) null,
delivery_type enum('attachment', 'inline') null,
dashboard_id int null,
created_by_fk int null,
changed_by_fk int null,
user_id int null,
constraint dashboard_email_schedules_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint dashboard_email_schedules_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint dashboard_email_schedules_ibfk_3
foreign key (dashboard_id) references superset.dashboards (id),
constraint dashboard_email_schedules_ibfk_4
foreign key (user_id) references superset.ab_user (id)
);
create index changed_by_fk
on superset.dashboard_email_schedules (changed_by_fk);
create index created_by_fk
on superset.dashboard_email_schedules (created_by_fk);
create index dashboard_id
on superset.dashboard_email_schedules (dashboard_id);
create index ix_dashboard_email_schedules_active
on superset.dashboard_email_schedules (active);
create index user_id
on superset.dashboard_email_schedules (user_id);
create table if not exists superset.dashboard_user
(
id int auto_increment
primary key,
user_id int null,
dashboard_id int null,
constraint dashboard_user_ibfk_1
foreign key (dashboard_id) references superset.dashboards (id),
constraint dashboard_user_ibfk_2
foreign key (user_id) references superset.ab_user (id)
);
create index dashboard_id
on superset.dashboard_user (dashboard_id);
create index user_id
on superset.dashboard_user (user_id);
create index changed_by_fk
on superset.dashboards (changed_by_fk);
create index created_by_fk
on superset.dashboards (created_by_fk);
create table if not exists superset.datasources
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
datasource_name varchar(255) not null,
is_featured tinyint(1) null,
is_hidden tinyint(1) null,
description text null,
default_endpoint text null,
created_by_fk int null,
changed_by_fk int null,
offset int null,
cache_timeout int null,
perm varchar(1000) null,
filter_select_enabled tinyint(1) null,
params varchar(1000) null,
fetch_values_from varchar(100) null,
schema_perm varchar(1000) null,
cluster_id int not null,
constraint uq_datasources_cluster_id
unique (cluster_id, datasource_name),
constraint datasources_ibfk_3
foreign key (created_by_fk) references superset.ab_user (id),
constraint datasources_ibfk_4
foreign key (changed_by_fk) references superset.ab_user (id),
constraint fk_datasources_cluster_id_clusters
foreign key (cluster_id) references superset.clusters (id)
);
create table if not exists superset.columns
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
column_name varchar(255) not null,
is_active tinyint(1) null,
type varchar(32) null,
groupby tinyint(1) null,
filterable tinyint(1) null,
description text null,
created_by_fk int null,
changed_by_fk int null,
dimension_spec_json text null,
verbose_name varchar(1024) null,
datasource_id int null,
constraint uq_columns_column_name
unique (column_name, datasource_id),
constraint columns_ibfk_1
foreign key (created_by_fk) references superset.ab_user (id),
constraint columns_ibfk_2
foreign key (changed_by_fk) references superset.ab_user (id),
constraint fk_columns_datasource_id_datasources
foreign key (datasource_id) references superset.datasources (id)
);
create index changed_by_fk
on superset.columns (changed_by_fk);
create index created_by_fk
on superset.columns (created_by_fk);
create index changed_by_fk
on superset.datasources (changed_by_fk);
create index created_by_fk
on superset.datasources (created_by_fk);
create table if not exists superset.dbs
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
database_name varchar(250) not null,
sqlalchemy_uri varchar(1024) not null,
created_by_fk int null,
changed_by_fk int null,
password blob null,
cache_timeout int null,
extra text null,
select_as_create_table_as tinyint(1) null,
allow_ctas tinyint(1) null,
expose_in_sqllab tinyint(1) null,
force_ctas_schema varchar(250) null,
allow_run_async tinyint(1) null,
allow_dml tinyint(1) null,
perm varchar(1000) null,
verbose_name varchar(250) null,
impersonate_user tinyint(1) null,
allow_multi_schema_metadata_fetch tinyint(1) null,
allow_csv_upload tinyint(1) default 1 not null,
encrypted_extra blob null,
server_cert blob null,
constraint database_name
unique (database_name),
constraint verbose_name
unique (verbose_name),
constraint dbs_ibfk_1
foreign key (created_by_fk) references superset.ab_user (id),
constraint dbs_ibfk_2
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.dbs (changed_by_fk);
create index created_by_fk
on superset.dbs (created_by_fk);
create table if not exists superset.druiddatasource_user
(
id int auto_increment
primary key,
user_id int null,
datasource_id int null,
constraint druiddatasource_user_ibfk_1
foreign key (datasource_id) references superset.datasources (id),
constraint druiddatasource_user_ibfk_2
foreign key (user_id) references superset.ab_user (id)
);
create index datasource_id
on superset.druiddatasource_user (datasource_id);
create index user_id
on superset.druiddatasource_user (user_id);
create table if not exists superset.energy_usage
(
source varchar(255) null,
target varchar(255) null,
value float null
);
create table if not exists superset.favstar
(
id int auto_increment
primary key,
user_id int null,
class_name varchar(50) null,
obj_id int null,
dttm datetime null,
constraint favstar_ibfk_1
foreign key (user_id) references superset.ab_user (id)
);
create index user_id
on superset.favstar (user_id);
create table if not exists superset.keyvalue
(
id int auto_increment
primary key,
value text not null
);
create table if not exists superset.logs
(
id int auto_increment
primary key,
action varchar(512) null,
user_id int null,
json text null,
dttm datetime null,
dashboard_id int null,
slice_id int null,
duration_ms int null,
referrer varchar(1024) null,
constraint logs_ibfk_1
foreign key (user_id) references superset.ab_user (id)
);
create index user_id
on superset.logs (user_id);
create table if not exists superset.metrics
(
id int auto_increment
primary key,
metric_name varchar(255) not null,
verbose_name varchar(1024) null,
metric_type varchar(32) null,
json text not null,
description text null,
changed_by_fk int null,
changed_on datetime null,
created_by_fk int null,
created_on datetime null,
d3format varchar(128) null,
warning_text text null,
datasource_id int null,
constraint uq_metrics_metric_name
unique (metric_name, datasource_id),
constraint fk_metrics_datasource_id_datasources
foreign key (datasource_id) references superset.datasources (id),
constraint metrics_ibfk_3
foreign key (changed_by_fk) references superset.ab_user (id),
constraint metrics_ibfk_4
foreign key (created_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.metrics (changed_by_fk);
create index created_by_fk
on superset.metrics (created_by_fk);
create table if not exists superset.query
(
id int auto_increment
primary key,
client_id varchar(11) not null,
database_id int not null,
tmp_table_name varchar(256) null,
tab_name varchar(256) null,
sql_editor_id varchar(256) null,
user_id int null,
status varchar(16) null,
`schema` varchar(256) null,
`sql` longtext null,
select_sql longtext null,
executed_sql longtext null,
`limit` int null,
select_as_cta tinyint(1) null,
select_as_cta_used tinyint(1) null,
progress int null,
rows int null,
error_message text null,
start_time decimal(20,6) null,
changed_on datetime null,
end_time decimal(20,6) null,
results_key varchar(64) null,
start_running_time decimal(20,6) null,
end_result_backend_time decimal(20,6) null,
tracking_url text null,
extra_json text null,
tmp_schema_name varchar(256) null,
constraint client_id
unique (client_id),
constraint query_ibfk_1
foreign key (database_id) references superset.dbs (id),
constraint query_ibfk_2
foreign key (user_id) references superset.ab_user (id)
);
create index database_id
on superset.query (database_id);
create index ix_query_results_key
on superset.query (results_key);
create index ti_user_id_changed_on
on superset.query (user_id, changed_on);
create table if not exists superset.saved_query
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
user_id int null,
db_id int null,
label varchar(256) null,
`schema` varchar(128) null,
`sql` text null,
description text null,
changed_by_fk int null,
created_by_fk int null,
extra_json text null,
constraint saved_query_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint saved_query_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint saved_query_ibfk_3
foreign key (user_id) references superset.ab_user (id),
constraint saved_query_ibfk_4
foreign key (db_id) references superset.dbs (id)
);
create index changed_by_fk
on superset.saved_query (changed_by_fk);
create index created_by_fk
on superset.saved_query (created_by_fk);
create index db_id
on superset.saved_query (db_id);
create index user_id
on superset.saved_query (user_id);
create table if not exists superset.tab_state
(
created_on datetime null,
changed_on datetime null,
extra_json text null,
id int auto_increment,
user_id int null,
label varchar(256) null,
active tinyint(1) null,
database_id int null,
`schema` varchar(256) null,
`sql` text null,
query_limit int null,
latest_query_id varchar(11) null,
autorun tinyint(1) not null,
template_params text null,
created_by_fk int null,
changed_by_fk int null,
constraint ix_tab_state_id
unique (id),
constraint tab_state_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint tab_state_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint tab_state_ibfk_3
foreign key (database_id) references superset.dbs (id),
constraint tab_state_ibfk_4
foreign key (latest_query_id) references superset.query (client_id),
constraint tab_state_ibfk_5
foreign key (user_id) references superset.ab_user (id)
);
create index changed_by_fk
on superset.tab_state (changed_by_fk);
create index created_by_fk
on superset.tab_state (created_by_fk);
create index database_id
on superset.tab_state (database_id);
create index latest_query_id
on superset.tab_state (latest_query_id);
create index user_id
on superset.tab_state (user_id);
alter table superset.tab_state
add primary key (id);
create table if not exists superset.table_schema
(
created_on datetime null,
changed_on datetime null,
extra_json text null,
id int auto_increment,
tab_state_id int null,
database_id int not null,
`schema` varchar(256) null,
`table` varchar(256) null,
description longtext null,
expanded tinyint(1) null,
created_by_fk int null,
changed_by_fk int null,
constraint ix_table_schema_id
unique (id),
constraint table_schema_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint table_schema_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint table_schema_ibfk_3
foreign key (database_id) references superset.dbs (id),
constraint table_schema_ibfk_4
foreign key (tab_state_id) references superset.tab_state (id)
on delete cascade
);
create index changed_by_fk
on superset.table_schema (changed_by_fk);
create index created_by_fk
on superset.table_schema (created_by_fk);
create index database_id
on superset.table_schema (database_id);
create index tab_state_id
on superset.table_schema (tab_state_id);
alter table superset.table_schema
add primary key (id);
create table if not exists superset.tables
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
table_name varchar(250) not null,
main_dttm_col varchar(250) null,
default_endpoint text null,
database_id int not null,
created_by_fk int null,
changed_by_fk int null,
offset int null,
description text null,
is_featured tinyint(1) null,
cache_timeout int null,
`schema` varchar(255) null,
`sql` text null,
params text null,
perm varchar(1000) null,
filter_select_enabled tinyint(1) null,
fetch_values_predicate varchar(1000) null,
is_sqllab_view tinyint(1) default 0 null,
template_params text null,
schema_perm varchar(1000) null,
constraint table_name
unique (table_name),
constraint tables_ibfk_1
foreign key (database_id) references superset.dbs (id),
constraint tables_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint tables_ibfk_3
foreign key (changed_by_fk) references superset.ab_user (id)
);
create table if not exists superset.row_level_security_filters
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
table_id int not null,
clause text not null,
created_by_fk int null,
changed_by_fk int null,
constraint row_level_security_filters_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint row_level_security_filters_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint row_level_security_filters_ibfk_3
foreign key (table_id) references superset.tables (id)
);
create table if not exists superset.rls_filter_roles
(
id int auto_increment
primary key,
role_id int not null,
rls_filter_id int null,
constraint rls_filter_roles_ibfk_1
foreign key (rls_filter_id) references superset.row_level_security_filters (id),
constraint rls_filter_roles_ibfk_2
foreign key (role_id) references superset.ab_role (id)
);
create index rls_filter_id
on superset.rls_filter_roles (rls_filter_id);
create index role_id
on superset.rls_filter_roles (role_id);
create index changed_by_fk
on superset.row_level_security_filters (changed_by_fk);
create index created_by_fk
on superset.row_level_security_filters (created_by_fk);
create index table_id
on superset.row_level_security_filters (table_id);
create table if not exists superset.slices
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
slice_name varchar(250) null,
druid_datasource_id int null,
table_id int null,
datasource_type varchar(200) null,
datasource_name varchar(2000) null,
viz_type varchar(250) null,
params text null,
created_by_fk int null,
changed_by_fk int null,
description text null,
cache_timeout int null,
perm varchar(2000) null,
datasource_id int null,
schema_perm varchar(1000) null,
constraint slices_ibfk_1
foreign key (druid_datasource_id) references superset.datasources (id),
constraint slices_ibfk_2
foreign key (table_id) references superset.tables (id),
constraint slices_ibfk_3
foreign key (created_by_fk) references superset.ab_user (id),
constraint slices_ibfk_4
foreign key (changed_by_fk) references superset.ab_user (id)
);
create table if not exists superset.dashboard_slices
(
id int auto_increment
primary key,
dashboard_id int null,
slice_id int null,
constraint uq_dashboard_slice
unique (dashboard_id, slice_id),
constraint dashboard_slices_ibfk_1
foreign key (dashboard_id) references superset.dashboards (id),
constraint dashboard_slices_ibfk_2
foreign key (slice_id) references superset.slices (id)
);
create index slice_id
on superset.dashboard_slices (slice_id);
create table if not exists superset.slice_email_schedules
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
active tinyint(1) null,
crontab varchar(50) null,
recipients text null,
deliver_as_group tinyint(1) null,
delivery_type enum('attachment', 'inline') null,
slice_id int null,
email_format enum('visualization', 'data') null,
created_by_fk int null,
changed_by_fk int null,
user_id int null,
constraint slice_email_schedules_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint slice_email_schedules_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint slice_email_schedules_ibfk_3
foreign key (slice_id) references superset.slices (id),
constraint slice_email_schedules_ibfk_4
foreign key (user_id) references superset.ab_user (id)
);
create index changed_by_fk
on superset.slice_email_schedules (changed_by_fk);
create index created_by_fk
on superset.slice_email_schedules (created_by_fk);
create index ix_slice_email_schedules_active
on superset.slice_email_schedules (active);
create index slice_id
on superset.slice_email_schedules (slice_id);
create index user_id
on superset.slice_email_schedules (user_id);
create table if not exists superset.slice_user
(
id int auto_increment
primary key,
user_id int null,
slice_id int null,
constraint slice_user_ibfk_1
foreign key (slice_id) references superset.slices (id),
constraint slice_user_ibfk_2
foreign key (user_id) references superset.ab_user (id)
);
create index slice_id
on superset.slice_user (slice_id);
create index user_id
on superset.slice_user (user_id);
create index changed_by_fk
on superset.slices (changed_by_fk);
create index created_by_fk
on superset.slices (created_by_fk);
create index druid_datasource_id
on superset.slices (druid_datasource_id);
create index table_id
on superset.slices (table_id);
create table if not exists superset.sql_metrics
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
metric_name varchar(255) not null,
verbose_name varchar(1024) null,
metric_type varchar(32) null,
table_id int null,
expression text not null,
description text null,
created_by_fk int null,
changed_by_fk int null,
d3format varchar(128) null,
warning_text text null,
constraint uq_sql_metrics_metric_name
unique (metric_name, table_id),
constraint sql_metrics_ibfk_1
foreign key (table_id) references superset.tables (id),
constraint sql_metrics_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint sql_metrics_ibfk_3
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.sql_metrics (changed_by_fk);
create index created_by_fk
on superset.sql_metrics (created_by_fk);
create index table_id
on superset.sql_metrics (table_id);
create table if not exists superset.sqlatable_user
(
id int auto_increment
primary key,
user_id int null,
table_id int null,
constraint sqlatable_user_ibfk_1
foreign key (table_id) references superset.tables (id),
constraint sqlatable_user_ibfk_2
foreign key (user_id) references superset.ab_user (id)
);
create index table_id
on superset.sqlatable_user (table_id);
create index user_id
on superset.sqlatable_user (user_id);
create table if not exists superset.table_columns
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
table_id int null,
column_name varchar(255) not null,
is_dttm tinyint(1) null,
is_active tinyint(1) null,
type varchar(32) null,
groupby tinyint(1) null,
filterable tinyint(1) null,
description text null,
created_by_fk int null,
changed_by_fk int null,
expression text null,
verbose_name varchar(1024) null,
python_date_format varchar(255) null,
constraint uq_table_columns_column_name
unique (column_name, table_id),
constraint table_columns_ibfk_1
foreign key (table_id) references superset.tables (id),
constraint table_columns_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint table_columns_ibfk_3
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.table_columns (changed_by_fk);
create index created_by_fk
on superset.table_columns (created_by_fk);
create index table_id
on superset.table_columns (table_id);
create index changed_by_fk
on superset.tables (changed_by_fk);
create index created_by_fk
on superset.tables (created_by_fk);
create index database_id
on superset.tables (database_id);
create table if not exists superset.tag
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
name varchar(250) null,
type enum('custom', 'type', 'owner', 'favorited_by') null,
created_by_fk int null,
changed_by_fk int null,
constraint name
unique (name),
constraint tag_ibfk_1
foreign key (created_by_fk) references superset.ab_user (id),
constraint tag_ibfk_2
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.tag (changed_by_fk);
create index created_by_fk
on superset.tag (created_by_fk);
create table if not exists superset.tagged_object
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
tag_id int null,
object_id int null,
object_type enum('query', 'chart', 'dashboard') null,
created_by_fk int null,
changed_by_fk int null,
constraint tagged_object_ibfk_1
foreign key (tag_id) references superset.tag (id),
constraint tagged_object_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint tagged_object_ibfk_3
foreign key (changed_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.tagged_object (changed_by_fk);
create index created_by_fk
on superset.tagged_object (created_by_fk);
create index ix_tagged_object_object_id
on superset.tagged_object (object_id);
create index tag_id
on superset.tagged_object (tag_id);
create table if not exists superset.url
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
url text null,
created_by_fk int null,
changed_by_fk int null,
constraint url_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint url_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id)
);
create index changed_by_fk
on superset.url (changed_by_fk);
create index created_by_fk
on superset.url (created_by_fk);
create table if not exists superset.user_attribute
(
created_on datetime null,
changed_on datetime null,
id int auto_increment
primary key,
user_id int null,
welcome_dashboard_id int null,
created_by_fk int null,
changed_by_fk int null,
constraint user_attribute_ibfk_1
foreign key (changed_by_fk) references superset.ab_user (id),
constraint user_attribute_ibfk_2
foreign key (created_by_fk) references superset.ab_user (id),
constraint user_attribute_ibfk_3
foreign key (user_id) references superset.ab_user (id),
constraint user_attribute_ibfk_4
foreign key (welcome_dashboard_id) references superset.dashboards (id)
);
create index changed_by_fk
on superset.user_attribute (changed_by_fk);
create index created_by_fk
on superset.user_attribute (created_by_fk);
create index user_id
on superset.user_attribute (user_id);
create index welcome_dashboard_id
on superset.user_attribute (welcome_dashboard_id);