什么是 Superset

Superset 是一款由 Airbnb 开源的“现代化的企业级 BI(商业智能) Web 应用程序”,其通过创建和分享 dashboard,为数据分析提供了轻量级的数据查询和可视化方案。

Superset 的前端主要用到了 ReactNVD3/D3,而后端则基于 Python 的 Flask 框架和 PandasSQLAlchemy 等依赖库,主要提供了这几方面的功能:

  • 集成数据查询功能,支持多种数据库,包括 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/,如下图所示,点击【获取下载链接】。
image.png
在弹出的界面中,选择应用软件,选择 Conda,点击下载如图所示的 Mac 安装包即可,选择mini版就行,安装包很很小。

image.png

下载完成,双击打开安装即可,我已经安装过了,这里就不演示了,一路next即可。

image.png

安装完成之后,验证安装成功,运行 conda env list ,不报错就表示成功了。

创建虚拟环境

上一节我们安装了 conda,在本节中可以发挥它的作用啦。

1.创建虚拟环境,在终端执行以下命令,xxx 为环境的名字,这里随便起。

conda create -n xxx python=python3.7

2.激活环境,xxx 为你刚刚起的名字

conda activate xxx

激活之后,终端会变成这样:注意,我的环境名字是 superset-env,所以这里前面会显示这个名字。
image.png

需要注意的是,如果新开一个终端,需要手动执行 conda activate xxx来使得终端用的是你刚刚创建的虚拟环境。

这一小节就结束了,是不是很简单啊?哈哈哈哈

下载 Superset 源码

现在技术人访问 Github 的速度大不如从前了,所以这里非常推荐大家使用码云的一个免费服务来下载 GitHub上面的仓库代码。具体操作如下:

浏览器访问:https://gitee.com/mirrors,然后在搜索框搜索:superset

image.png

image.png

复制仓库地址之后,执行一下命令,拉到本地

git clone https://gitee.com/mirrors/Superset.git

等待片刻即可。

配置后端

进入项目代码目录,可以看到项目结构如下:

  1. .
  2. ├── CHANGELOG.md
  3. ├── CODE_OF_CONDUCT.md
  4. ├── CONTRIBUTING.md
  5. ├── DISCLAIMER
  6. ├── Dockerfile
  7. ├── Dockerfile-dev
  8. ├── INSTALL.md
  9. ├── LICENSE.txt
  10. ├── MANIFEST.in
  11. ├── NOTICE
  12. ├── README.md
  13. ├── RELEASING
  14. ├── UPDATING.md
  15. ├── alembic.ini
  16. ├── apache_superset.egg-info
  17. ├── babel-node
  18. ├── docker
  19. ├── docker-compose.yml
  20. ├── docs
  21. ├── gen_changelog.sh
  22. ├── helm
  23. ├── pypi_push.sh
  24. ├── requirements-dev.txt
  25. ├── requirements.txt
  26. ├── scripts
  27. ├── setup.cfg
  28. ├── setup.py
  29. ├── superset
  30. ├── superset-frontend
  31. ├── tests
  32. └── tox.ini

安装依赖

下面,开始安装服务端项目依赖,注意,需要保证自己的终端激活了虚拟环境。

执行 pip install -r requirements.txt,等待执行结束。

执行 pip install -r requirements-dev.txt 等待结束。这里可能会报错,安装 pydruid 的时候,可以先单独安装下面两个语句:

  1. pip install --user pytest-runner
  2. pip install pydruid
  3. # 然后执行下面
  4. pip install -r requirements-dev.txt

执行 pip install -e .

注意,后面有个 点

配置数据库

这里项目默认使用 sqllite 数据库,也支持配置成其他的,比如 Mysql,我这里本地正好装了 Mysql,就改成 Mysql 吧,怎么改呢,看下面:

找到 superset/config.py 文件,找到这个配置项 SQLALCHEMY_DATABASE_URI

image.png
从图中,可以看出 默认是用的 sqllite 数据,我这里改成 mysql。
image.png

安装 mysql 的依赖,python 3.7 安装 mysql 客户端方法如下:pip install mysqlclient

配置管理员信息

执行 superset fab create-admin

image.png
执行 superset db upgrade
image.png
执行 superset init
image.png

执行 superset load_examples,这个执行过程中可能会遇到网络超时,多次执行这个语句即可。

执行 FLASK_ENV=development superset run -p 8088 —with-threads —reload —debugger
image.png

配置前端

安装 Node

访问 https://nodejs.org/zh-cn/ 直接安装即可。

安装前端依赖

cd superset-frontend

执行 npm ci 安装依赖,依赖来自 package-lock.json

启动前端 npm run dev-server

image.png

界面

根据之前启动,默认是监听 9000 端口,浏览器王文 localhost:9000 即可访问主界面。

image.png

数据库设计

数据库设计ER图.pdf

语句

  1. create table if not exists superset.ab_permission
  2. (
  3. id int auto_increment
  4. primary key,
  5. name varchar(100) not null,
  6. constraint name
  7. unique (name)
  8. );
  9. create table if not exists superset.ab_register_user
  10. (
  11. id int auto_increment
  12. primary key,
  13. first_name varchar(64) not null,
  14. last_name varchar(64) not null,
  15. username varchar(64) not null,
  16. password varchar(256) null,
  17. email varchar(64) not null,
  18. registration_date datetime null,
  19. registration_hash varchar(256) null,
  20. constraint username
  21. unique (username)
  22. );
  23. create table if not exists superset.ab_role
  24. (
  25. id int auto_increment
  26. primary key,
  27. name varchar(64) not null,
  28. constraint name
  29. unique (name)
  30. );
  31. create table if not exists superset.ab_user
  32. (
  33. id int auto_increment
  34. primary key,
  35. first_name varchar(64) not null,
  36. last_name varchar(64) not null,
  37. username varchar(64) not null,
  38. password varchar(256) null,
  39. active tinyint(1) null,
  40. email varchar(64) not null,
  41. last_login datetime null,
  42. login_count int null,
  43. fail_login_count int null,
  44. created_on datetime null,
  45. changed_on datetime null,
  46. created_by_fk int null,
  47. changed_by_fk int null,
  48. constraint email
  49. unique (email),
  50. constraint username
  51. unique (username),
  52. constraint ab_user_ibfk_1
  53. foreign key (created_by_fk) references superset.ab_user (id),
  54. constraint ab_user_ibfk_2
  55. foreign key (changed_by_fk) references superset.ab_user (id)
  56. );
  57. create index changed_by_fk
  58. on superset.ab_user (changed_by_fk);
  59. create index created_by_fk
  60. on superset.ab_user (created_by_fk);
  61. create table if not exists superset.ab_user_role
  62. (
  63. id int auto_increment
  64. primary key,
  65. user_id int null,
  66. role_id int null,
  67. constraint user_id
  68. unique (user_id, role_id),
  69. constraint ab_user_role_ibfk_1
  70. foreign key (user_id) references superset.ab_user (id),
  71. constraint ab_user_role_ibfk_2
  72. foreign key (role_id) references superset.ab_role (id)
  73. );
  74. create index role_id
  75. on superset.ab_user_role (role_id);
  76. create table if not exists superset.ab_view_menu
  77. (
  78. id int auto_increment
  79. primary key,
  80. name varchar(255) not null,
  81. constraint name
  82. unique (name)
  83. );
  84. create table if not exists superset.ab_permission_view
  85. (
  86. id int auto_increment
  87. primary key,
  88. permission_id int null,
  89. view_menu_id int null,
  90. constraint permission_id
  91. unique (permission_id, view_menu_id),
  92. constraint ab_permission_view_ibfk_1
  93. foreign key (permission_id) references superset.ab_permission (id),
  94. constraint ab_permission_view_ibfk_2
  95. foreign key (view_menu_id) references superset.ab_view_menu (id)
  96. );
  97. create index view_menu_id
  98. on superset.ab_permission_view (view_menu_id);
  99. create table if not exists superset.ab_permission_view_role
  100. (
  101. id int auto_increment
  102. primary key,
  103. permission_view_id int null,
  104. role_id int null,
  105. constraint permission_view_id
  106. unique (permission_view_id, role_id),
  107. constraint ab_permission_view_role_ibfk_1
  108. foreign key (permission_view_id) references superset.ab_permission_view (id),
  109. constraint ab_permission_view_role_ibfk_2
  110. foreign key (role_id) references superset.ab_role (id)
  111. );
  112. create index role_id
  113. on superset.ab_permission_view_role (role_id);
  114. create table if not exists superset.access_request
  115. (
  116. created_on datetime null,
  117. changed_on datetime null,
  118. id int auto_increment
  119. primary key,
  120. datasource_type varchar(200) null,
  121. datasource_id int null,
  122. changed_by_fk int null,
  123. created_by_fk int null,
  124. constraint access_request_ibfk_1
  125. foreign key (changed_by_fk) references superset.ab_user (id),
  126. constraint access_request_ibfk_2
  127. foreign key (created_by_fk) references superset.ab_user (id)
  128. );
  129. create index changed_by_fk
  130. on superset.access_request (changed_by_fk);
  131. create index created_by_fk
  132. on superset.access_request (created_by_fk);
  133. create table if not exists superset.alembic_version
  134. (
  135. version_num varchar(32) not null
  136. primary key
  137. );
  138. create table if not exists superset.annotation_layer
  139. (
  140. created_on datetime null,
  141. changed_on datetime null,
  142. id int auto_increment
  143. primary key,
  144. name varchar(250) null,
  145. descr text null,
  146. changed_by_fk int null,
  147. created_by_fk int null,
  148. constraint annotation_layer_ibfk_1
  149. foreign key (changed_by_fk) references superset.ab_user (id),
  150. constraint annotation_layer_ibfk_2
  151. foreign key (created_by_fk) references superset.ab_user (id)
  152. );
  153. create table if not exists superset.annotation
  154. (
  155. created_on datetime null,
  156. changed_on datetime null,
  157. id int auto_increment
  158. primary key,
  159. start_dttm datetime null,
  160. end_dttm datetime null,
  161. layer_id int null,
  162. short_descr varchar(500) null,
  163. long_descr text null,
  164. changed_by_fk int null,
  165. created_by_fk int null,
  166. json_metadata text null,
  167. constraint annotation_ibfk_1
  168. foreign key (changed_by_fk) references superset.ab_user (id),
  169. constraint annotation_ibfk_2
  170. foreign key (created_by_fk) references superset.ab_user (id),
  171. constraint annotation_ibfk_3
  172. foreign key (layer_id) references superset.annotation_layer (id)
  173. );
  174. create index changed_by_fk
  175. on superset.annotation (changed_by_fk);
  176. create index created_by_fk
  177. on superset.annotation (created_by_fk);
  178. create index ti_dag_state
  179. on superset.annotation (layer_id, start_dttm, end_dttm);
  180. create index changed_by_fk
  181. on superset.annotation_layer (changed_by_fk);
  182. create index created_by_fk
  183. on superset.annotation_layer (created_by_fk);
  184. create table if not exists superset.clusters
  185. (
  186. created_on datetime null,
  187. changed_on datetime null,
  188. id int auto_increment
  189. primary key,
  190. cluster_name varchar(250) not null,
  191. broker_host varchar(255) null,
  192. broker_port int null,
  193. broker_endpoint varchar(255) null,
  194. metadata_last_refreshed datetime null,
  195. created_by_fk int null,
  196. changed_by_fk int null,
  197. cache_timeout int null,
  198. verbose_name varchar(250) null,
  199. broker_pass blob null,
  200. broker_user varchar(255) null,
  201. constraint cluster_name
  202. unique (cluster_name),
  203. constraint verbose_name
  204. unique (verbose_name),
  205. constraint clusters_ibfk_1
  206. foreign key (created_by_fk) references superset.ab_user (id),
  207. constraint clusters_ibfk_2
  208. foreign key (changed_by_fk) references superset.ab_user (id)
  209. );
  210. create index changed_by_fk
  211. on superset.clusters (changed_by_fk);
  212. create index created_by_fk
  213. on superset.clusters (created_by_fk);
  214. create table if not exists superset.css_templates
  215. (
  216. created_on datetime null,
  217. changed_on datetime null,
  218. id int auto_increment
  219. primary key,
  220. template_name varchar(250) null,
  221. css text null,
  222. changed_by_fk int null,
  223. created_by_fk int null,
  224. constraint css_templates_ibfk_1
  225. foreign key (changed_by_fk) references superset.ab_user (id),
  226. constraint css_templates_ibfk_2
  227. foreign key (created_by_fk) references superset.ab_user (id)
  228. );
  229. create index changed_by_fk
  230. on superset.css_templates (changed_by_fk);
  231. create index created_by_fk
  232. on superset.css_templates (created_by_fk);
  233. create table if not exists superset.dashboards
  234. (
  235. created_on datetime null,
  236. changed_on datetime null,
  237. id int auto_increment
  238. primary key,
  239. dashboard_title varchar(500) null,
  240. position_json mediumtext null,
  241. created_by_fk int null,
  242. changed_by_fk int null,
  243. css text null,
  244. description text null,
  245. slug varchar(255) null,
  246. json_metadata text null,
  247. published tinyint(1) null,
  248. constraint idx_unique_slug
  249. unique (slug),
  250. constraint dashboards_ibfk_1
  251. foreign key (created_by_fk) references superset.ab_user (id),
  252. constraint dashboards_ibfk_2
  253. foreign key (changed_by_fk) references superset.ab_user (id)
  254. );
  255. create table if not exists superset.dashboard_email_schedules
  256. (
  257. created_on datetime null,
  258. changed_on datetime null,
  259. id int auto_increment
  260. primary key,
  261. active tinyint(1) null,
  262. crontab varchar(50) null,
  263. recipients text null,
  264. deliver_as_group tinyint(1) null,
  265. delivery_type enum('attachment', 'inline') null,
  266. dashboard_id int null,
  267. created_by_fk int null,
  268. changed_by_fk int null,
  269. user_id int null,
  270. constraint dashboard_email_schedules_ibfk_1
  271. foreign key (changed_by_fk) references superset.ab_user (id),
  272. constraint dashboard_email_schedules_ibfk_2
  273. foreign key (created_by_fk) references superset.ab_user (id),
  274. constraint dashboard_email_schedules_ibfk_3
  275. foreign key (dashboard_id) references superset.dashboards (id),
  276. constraint dashboard_email_schedules_ibfk_4
  277. foreign key (user_id) references superset.ab_user (id)
  278. );
  279. create index changed_by_fk
  280. on superset.dashboard_email_schedules (changed_by_fk);
  281. create index created_by_fk
  282. on superset.dashboard_email_schedules (created_by_fk);
  283. create index dashboard_id
  284. on superset.dashboard_email_schedules (dashboard_id);
  285. create index ix_dashboard_email_schedules_active
  286. on superset.dashboard_email_schedules (active);
  287. create index user_id
  288. on superset.dashboard_email_schedules (user_id);
  289. create table if not exists superset.dashboard_user
  290. (
  291. id int auto_increment
  292. primary key,
  293. user_id int null,
  294. dashboard_id int null,
  295. constraint dashboard_user_ibfk_1
  296. foreign key (dashboard_id) references superset.dashboards (id),
  297. constraint dashboard_user_ibfk_2
  298. foreign key (user_id) references superset.ab_user (id)
  299. );
  300. create index dashboard_id
  301. on superset.dashboard_user (dashboard_id);
  302. create index user_id
  303. on superset.dashboard_user (user_id);
  304. create index changed_by_fk
  305. on superset.dashboards (changed_by_fk);
  306. create index created_by_fk
  307. on superset.dashboards (created_by_fk);
  308. create table if not exists superset.datasources
  309. (
  310. created_on datetime null,
  311. changed_on datetime null,
  312. id int auto_increment
  313. primary key,
  314. datasource_name varchar(255) not null,
  315. is_featured tinyint(1) null,
  316. is_hidden tinyint(1) null,
  317. description text null,
  318. default_endpoint text null,
  319. created_by_fk int null,
  320. changed_by_fk int null,
  321. offset int null,
  322. cache_timeout int null,
  323. perm varchar(1000) null,
  324. filter_select_enabled tinyint(1) null,
  325. params varchar(1000) null,
  326. fetch_values_from varchar(100) null,
  327. schema_perm varchar(1000) null,
  328. cluster_id int not null,
  329. constraint uq_datasources_cluster_id
  330. unique (cluster_id, datasource_name),
  331. constraint datasources_ibfk_3
  332. foreign key (created_by_fk) references superset.ab_user (id),
  333. constraint datasources_ibfk_4
  334. foreign key (changed_by_fk) references superset.ab_user (id),
  335. constraint fk_datasources_cluster_id_clusters
  336. foreign key (cluster_id) references superset.clusters (id)
  337. );
  338. create table if not exists superset.columns
  339. (
  340. created_on datetime null,
  341. changed_on datetime null,
  342. id int auto_increment
  343. primary key,
  344. column_name varchar(255) not null,
  345. is_active tinyint(1) null,
  346. type varchar(32) null,
  347. groupby tinyint(1) null,
  348. filterable tinyint(1) null,
  349. description text null,
  350. created_by_fk int null,
  351. changed_by_fk int null,
  352. dimension_spec_json text null,
  353. verbose_name varchar(1024) null,
  354. datasource_id int null,
  355. constraint uq_columns_column_name
  356. unique (column_name, datasource_id),
  357. constraint columns_ibfk_1
  358. foreign key (created_by_fk) references superset.ab_user (id),
  359. constraint columns_ibfk_2
  360. foreign key (changed_by_fk) references superset.ab_user (id),
  361. constraint fk_columns_datasource_id_datasources
  362. foreign key (datasource_id) references superset.datasources (id)
  363. );
  364. create index changed_by_fk
  365. on superset.columns (changed_by_fk);
  366. create index created_by_fk
  367. on superset.columns (created_by_fk);
  368. create index changed_by_fk
  369. on superset.datasources (changed_by_fk);
  370. create index created_by_fk
  371. on superset.datasources (created_by_fk);
  372. create table if not exists superset.dbs
  373. (
  374. created_on datetime null,
  375. changed_on datetime null,
  376. id int auto_increment
  377. primary key,
  378. database_name varchar(250) not null,
  379. sqlalchemy_uri varchar(1024) not null,
  380. created_by_fk int null,
  381. changed_by_fk int null,
  382. password blob null,
  383. cache_timeout int null,
  384. extra text null,
  385. select_as_create_table_as tinyint(1) null,
  386. allow_ctas tinyint(1) null,
  387. expose_in_sqllab tinyint(1) null,
  388. force_ctas_schema varchar(250) null,
  389. allow_run_async tinyint(1) null,
  390. allow_dml tinyint(1) null,
  391. perm varchar(1000) null,
  392. verbose_name varchar(250) null,
  393. impersonate_user tinyint(1) null,
  394. allow_multi_schema_metadata_fetch tinyint(1) null,
  395. allow_csv_upload tinyint(1) default 1 not null,
  396. encrypted_extra blob null,
  397. server_cert blob null,
  398. constraint database_name
  399. unique (database_name),
  400. constraint verbose_name
  401. unique (verbose_name),
  402. constraint dbs_ibfk_1
  403. foreign key (created_by_fk) references superset.ab_user (id),
  404. constraint dbs_ibfk_2
  405. foreign key (changed_by_fk) references superset.ab_user (id)
  406. );
  407. create index changed_by_fk
  408. on superset.dbs (changed_by_fk);
  409. create index created_by_fk
  410. on superset.dbs (created_by_fk);
  411. create table if not exists superset.druiddatasource_user
  412. (
  413. id int auto_increment
  414. primary key,
  415. user_id int null,
  416. datasource_id int null,
  417. constraint druiddatasource_user_ibfk_1
  418. foreign key (datasource_id) references superset.datasources (id),
  419. constraint druiddatasource_user_ibfk_2
  420. foreign key (user_id) references superset.ab_user (id)
  421. );
  422. create index datasource_id
  423. on superset.druiddatasource_user (datasource_id);
  424. create index user_id
  425. on superset.druiddatasource_user (user_id);
  426. create table if not exists superset.energy_usage
  427. (
  428. source varchar(255) null,
  429. target varchar(255) null,
  430. value float null
  431. );
  432. create table if not exists superset.favstar
  433. (
  434. id int auto_increment
  435. primary key,
  436. user_id int null,
  437. class_name varchar(50) null,
  438. obj_id int null,
  439. dttm datetime null,
  440. constraint favstar_ibfk_1
  441. foreign key (user_id) references superset.ab_user (id)
  442. );
  443. create index user_id
  444. on superset.favstar (user_id);
  445. create table if not exists superset.keyvalue
  446. (
  447. id int auto_increment
  448. primary key,
  449. value text not null
  450. );
  451. create table if not exists superset.logs
  452. (
  453. id int auto_increment
  454. primary key,
  455. action varchar(512) null,
  456. user_id int null,
  457. json text null,
  458. dttm datetime null,
  459. dashboard_id int null,
  460. slice_id int null,
  461. duration_ms int null,
  462. referrer varchar(1024) null,
  463. constraint logs_ibfk_1
  464. foreign key (user_id) references superset.ab_user (id)
  465. );
  466. create index user_id
  467. on superset.logs (user_id);
  468. create table if not exists superset.metrics
  469. (
  470. id int auto_increment
  471. primary key,
  472. metric_name varchar(255) not null,
  473. verbose_name varchar(1024) null,
  474. metric_type varchar(32) null,
  475. json text not null,
  476. description text null,
  477. changed_by_fk int null,
  478. changed_on datetime null,
  479. created_by_fk int null,
  480. created_on datetime null,
  481. d3format varchar(128) null,
  482. warning_text text null,
  483. datasource_id int null,
  484. constraint uq_metrics_metric_name
  485. unique (metric_name, datasource_id),
  486. constraint fk_metrics_datasource_id_datasources
  487. foreign key (datasource_id) references superset.datasources (id),
  488. constraint metrics_ibfk_3
  489. foreign key (changed_by_fk) references superset.ab_user (id),
  490. constraint metrics_ibfk_4
  491. foreign key (created_by_fk) references superset.ab_user (id)
  492. );
  493. create index changed_by_fk
  494. on superset.metrics (changed_by_fk);
  495. create index created_by_fk
  496. on superset.metrics (created_by_fk);
  497. create table if not exists superset.query
  498. (
  499. id int auto_increment
  500. primary key,
  501. client_id varchar(11) not null,
  502. database_id int not null,
  503. tmp_table_name varchar(256) null,
  504. tab_name varchar(256) null,
  505. sql_editor_id varchar(256) null,
  506. user_id int null,
  507. status varchar(16) null,
  508. `schema` varchar(256) null,
  509. `sql` longtext null,
  510. select_sql longtext null,
  511. executed_sql longtext null,
  512. `limit` int null,
  513. select_as_cta tinyint(1) null,
  514. select_as_cta_used tinyint(1) null,
  515. progress int null,
  516. rows int null,
  517. error_message text null,
  518. start_time decimal(20,6) null,
  519. changed_on datetime null,
  520. end_time decimal(20,6) null,
  521. results_key varchar(64) null,
  522. start_running_time decimal(20,6) null,
  523. end_result_backend_time decimal(20,6) null,
  524. tracking_url text null,
  525. extra_json text null,
  526. tmp_schema_name varchar(256) null,
  527. constraint client_id
  528. unique (client_id),
  529. constraint query_ibfk_1
  530. foreign key (database_id) references superset.dbs (id),
  531. constraint query_ibfk_2
  532. foreign key (user_id) references superset.ab_user (id)
  533. );
  534. create index database_id
  535. on superset.query (database_id);
  536. create index ix_query_results_key
  537. on superset.query (results_key);
  538. create index ti_user_id_changed_on
  539. on superset.query (user_id, changed_on);
  540. create table if not exists superset.saved_query
  541. (
  542. created_on datetime null,
  543. changed_on datetime null,
  544. id int auto_increment
  545. primary key,
  546. user_id int null,
  547. db_id int null,
  548. label varchar(256) null,
  549. `schema` varchar(128) null,
  550. `sql` text null,
  551. description text null,
  552. changed_by_fk int null,
  553. created_by_fk int null,
  554. extra_json text null,
  555. constraint saved_query_ibfk_1
  556. foreign key (changed_by_fk) references superset.ab_user (id),
  557. constraint saved_query_ibfk_2
  558. foreign key (created_by_fk) references superset.ab_user (id),
  559. constraint saved_query_ibfk_3
  560. foreign key (user_id) references superset.ab_user (id),
  561. constraint saved_query_ibfk_4
  562. foreign key (db_id) references superset.dbs (id)
  563. );
  564. create index changed_by_fk
  565. on superset.saved_query (changed_by_fk);
  566. create index created_by_fk
  567. on superset.saved_query (created_by_fk);
  568. create index db_id
  569. on superset.saved_query (db_id);
  570. create index user_id
  571. on superset.saved_query (user_id);
  572. create table if not exists superset.tab_state
  573. (
  574. created_on datetime null,
  575. changed_on datetime null,
  576. extra_json text null,
  577. id int auto_increment,
  578. user_id int null,
  579. label varchar(256) null,
  580. active tinyint(1) null,
  581. database_id int null,
  582. `schema` varchar(256) null,
  583. `sql` text null,
  584. query_limit int null,
  585. latest_query_id varchar(11) null,
  586. autorun tinyint(1) not null,
  587. template_params text null,
  588. created_by_fk int null,
  589. changed_by_fk int null,
  590. constraint ix_tab_state_id
  591. unique (id),
  592. constraint tab_state_ibfk_1
  593. foreign key (changed_by_fk) references superset.ab_user (id),
  594. constraint tab_state_ibfk_2
  595. foreign key (created_by_fk) references superset.ab_user (id),
  596. constraint tab_state_ibfk_3
  597. foreign key (database_id) references superset.dbs (id),
  598. constraint tab_state_ibfk_4
  599. foreign key (latest_query_id) references superset.query (client_id),
  600. constraint tab_state_ibfk_5
  601. foreign key (user_id) references superset.ab_user (id)
  602. );
  603. create index changed_by_fk
  604. on superset.tab_state (changed_by_fk);
  605. create index created_by_fk
  606. on superset.tab_state (created_by_fk);
  607. create index database_id
  608. on superset.tab_state (database_id);
  609. create index latest_query_id
  610. on superset.tab_state (latest_query_id);
  611. create index user_id
  612. on superset.tab_state (user_id);
  613. alter table superset.tab_state
  614. add primary key (id);
  615. create table if not exists superset.table_schema
  616. (
  617. created_on datetime null,
  618. changed_on datetime null,
  619. extra_json text null,
  620. id int auto_increment,
  621. tab_state_id int null,
  622. database_id int not null,
  623. `schema` varchar(256) null,
  624. `table` varchar(256) null,
  625. description longtext null,
  626. expanded tinyint(1) null,
  627. created_by_fk int null,
  628. changed_by_fk int null,
  629. constraint ix_table_schema_id
  630. unique (id),
  631. constraint table_schema_ibfk_1
  632. foreign key (changed_by_fk) references superset.ab_user (id),
  633. constraint table_schema_ibfk_2
  634. foreign key (created_by_fk) references superset.ab_user (id),
  635. constraint table_schema_ibfk_3
  636. foreign key (database_id) references superset.dbs (id),
  637. constraint table_schema_ibfk_4
  638. foreign key (tab_state_id) references superset.tab_state (id)
  639. on delete cascade
  640. );
  641. create index changed_by_fk
  642. on superset.table_schema (changed_by_fk);
  643. create index created_by_fk
  644. on superset.table_schema (created_by_fk);
  645. create index database_id
  646. on superset.table_schema (database_id);
  647. create index tab_state_id
  648. on superset.table_schema (tab_state_id);
  649. alter table superset.table_schema
  650. add primary key (id);
  651. create table if not exists superset.tables
  652. (
  653. created_on datetime null,
  654. changed_on datetime null,
  655. id int auto_increment
  656. primary key,
  657. table_name varchar(250) not null,
  658. main_dttm_col varchar(250) null,
  659. default_endpoint text null,
  660. database_id int not null,
  661. created_by_fk int null,
  662. changed_by_fk int null,
  663. offset int null,
  664. description text null,
  665. is_featured tinyint(1) null,
  666. cache_timeout int null,
  667. `schema` varchar(255) null,
  668. `sql` text null,
  669. params text null,
  670. perm varchar(1000) null,
  671. filter_select_enabled tinyint(1) null,
  672. fetch_values_predicate varchar(1000) null,
  673. is_sqllab_view tinyint(1) default 0 null,
  674. template_params text null,
  675. schema_perm varchar(1000) null,
  676. constraint table_name
  677. unique (table_name),
  678. constraint tables_ibfk_1
  679. foreign key (database_id) references superset.dbs (id),
  680. constraint tables_ibfk_2
  681. foreign key (created_by_fk) references superset.ab_user (id),
  682. constraint tables_ibfk_3
  683. foreign key (changed_by_fk) references superset.ab_user (id)
  684. );
  685. create table if not exists superset.row_level_security_filters
  686. (
  687. created_on datetime null,
  688. changed_on datetime null,
  689. id int auto_increment
  690. primary key,
  691. table_id int not null,
  692. clause text not null,
  693. created_by_fk int null,
  694. changed_by_fk int null,
  695. constraint row_level_security_filters_ibfk_1
  696. foreign key (changed_by_fk) references superset.ab_user (id),
  697. constraint row_level_security_filters_ibfk_2
  698. foreign key (created_by_fk) references superset.ab_user (id),
  699. constraint row_level_security_filters_ibfk_3
  700. foreign key (table_id) references superset.tables (id)
  701. );
  702. create table if not exists superset.rls_filter_roles
  703. (
  704. id int auto_increment
  705. primary key,
  706. role_id int not null,
  707. rls_filter_id int null,
  708. constraint rls_filter_roles_ibfk_1
  709. foreign key (rls_filter_id) references superset.row_level_security_filters (id),
  710. constraint rls_filter_roles_ibfk_2
  711. foreign key (role_id) references superset.ab_role (id)
  712. );
  713. create index rls_filter_id
  714. on superset.rls_filter_roles (rls_filter_id);
  715. create index role_id
  716. on superset.rls_filter_roles (role_id);
  717. create index changed_by_fk
  718. on superset.row_level_security_filters (changed_by_fk);
  719. create index created_by_fk
  720. on superset.row_level_security_filters (created_by_fk);
  721. create index table_id
  722. on superset.row_level_security_filters (table_id);
  723. create table if not exists superset.slices
  724. (
  725. created_on datetime null,
  726. changed_on datetime null,
  727. id int auto_increment
  728. primary key,
  729. slice_name varchar(250) null,
  730. druid_datasource_id int null,
  731. table_id int null,
  732. datasource_type varchar(200) null,
  733. datasource_name varchar(2000) null,
  734. viz_type varchar(250) null,
  735. params text null,
  736. created_by_fk int null,
  737. changed_by_fk int null,
  738. description text null,
  739. cache_timeout int null,
  740. perm varchar(2000) null,
  741. datasource_id int null,
  742. schema_perm varchar(1000) null,
  743. constraint slices_ibfk_1
  744. foreign key (druid_datasource_id) references superset.datasources (id),
  745. constraint slices_ibfk_2
  746. foreign key (table_id) references superset.tables (id),
  747. constraint slices_ibfk_3
  748. foreign key (created_by_fk) references superset.ab_user (id),
  749. constraint slices_ibfk_4
  750. foreign key (changed_by_fk) references superset.ab_user (id)
  751. );
  752. create table if not exists superset.dashboard_slices
  753. (
  754. id int auto_increment
  755. primary key,
  756. dashboard_id int null,
  757. slice_id int null,
  758. constraint uq_dashboard_slice
  759. unique (dashboard_id, slice_id),
  760. constraint dashboard_slices_ibfk_1
  761. foreign key (dashboard_id) references superset.dashboards (id),
  762. constraint dashboard_slices_ibfk_2
  763. foreign key (slice_id) references superset.slices (id)
  764. );
  765. create index slice_id
  766. on superset.dashboard_slices (slice_id);
  767. create table if not exists superset.slice_email_schedules
  768. (
  769. created_on datetime null,
  770. changed_on datetime null,
  771. id int auto_increment
  772. primary key,
  773. active tinyint(1) null,
  774. crontab varchar(50) null,
  775. recipients text null,
  776. deliver_as_group tinyint(1) null,
  777. delivery_type enum('attachment', 'inline') null,
  778. slice_id int null,
  779. email_format enum('visualization', 'data') null,
  780. created_by_fk int null,
  781. changed_by_fk int null,
  782. user_id int null,
  783. constraint slice_email_schedules_ibfk_1
  784. foreign key (changed_by_fk) references superset.ab_user (id),
  785. constraint slice_email_schedules_ibfk_2
  786. foreign key (created_by_fk) references superset.ab_user (id),
  787. constraint slice_email_schedules_ibfk_3
  788. foreign key (slice_id) references superset.slices (id),
  789. constraint slice_email_schedules_ibfk_4
  790. foreign key (user_id) references superset.ab_user (id)
  791. );
  792. create index changed_by_fk
  793. on superset.slice_email_schedules (changed_by_fk);
  794. create index created_by_fk
  795. on superset.slice_email_schedules (created_by_fk);
  796. create index ix_slice_email_schedules_active
  797. on superset.slice_email_schedules (active);
  798. create index slice_id
  799. on superset.slice_email_schedules (slice_id);
  800. create index user_id
  801. on superset.slice_email_schedules (user_id);
  802. create table if not exists superset.slice_user
  803. (
  804. id int auto_increment
  805. primary key,
  806. user_id int null,
  807. slice_id int null,
  808. constraint slice_user_ibfk_1
  809. foreign key (slice_id) references superset.slices (id),
  810. constraint slice_user_ibfk_2
  811. foreign key (user_id) references superset.ab_user (id)
  812. );
  813. create index slice_id
  814. on superset.slice_user (slice_id);
  815. create index user_id
  816. on superset.slice_user (user_id);
  817. create index changed_by_fk
  818. on superset.slices (changed_by_fk);
  819. create index created_by_fk
  820. on superset.slices (created_by_fk);
  821. create index druid_datasource_id
  822. on superset.slices (druid_datasource_id);
  823. create index table_id
  824. on superset.slices (table_id);
  825. create table if not exists superset.sql_metrics
  826. (
  827. created_on datetime null,
  828. changed_on datetime null,
  829. id int auto_increment
  830. primary key,
  831. metric_name varchar(255) not null,
  832. verbose_name varchar(1024) null,
  833. metric_type varchar(32) null,
  834. table_id int null,
  835. expression text not null,
  836. description text null,
  837. created_by_fk int null,
  838. changed_by_fk int null,
  839. d3format varchar(128) null,
  840. warning_text text null,
  841. constraint uq_sql_metrics_metric_name
  842. unique (metric_name, table_id),
  843. constraint sql_metrics_ibfk_1
  844. foreign key (table_id) references superset.tables (id),
  845. constraint sql_metrics_ibfk_2
  846. foreign key (created_by_fk) references superset.ab_user (id),
  847. constraint sql_metrics_ibfk_3
  848. foreign key (changed_by_fk) references superset.ab_user (id)
  849. );
  850. create index changed_by_fk
  851. on superset.sql_metrics (changed_by_fk);
  852. create index created_by_fk
  853. on superset.sql_metrics (created_by_fk);
  854. create index table_id
  855. on superset.sql_metrics (table_id);
  856. create table if not exists superset.sqlatable_user
  857. (
  858. id int auto_increment
  859. primary key,
  860. user_id int null,
  861. table_id int null,
  862. constraint sqlatable_user_ibfk_1
  863. foreign key (table_id) references superset.tables (id),
  864. constraint sqlatable_user_ibfk_2
  865. foreign key (user_id) references superset.ab_user (id)
  866. );
  867. create index table_id
  868. on superset.sqlatable_user (table_id);
  869. create index user_id
  870. on superset.sqlatable_user (user_id);
  871. create table if not exists superset.table_columns
  872. (
  873. created_on datetime null,
  874. changed_on datetime null,
  875. id int auto_increment
  876. primary key,
  877. table_id int null,
  878. column_name varchar(255) not null,
  879. is_dttm tinyint(1) null,
  880. is_active tinyint(1) null,
  881. type varchar(32) null,
  882. groupby tinyint(1) null,
  883. filterable tinyint(1) null,
  884. description text null,
  885. created_by_fk int null,
  886. changed_by_fk int null,
  887. expression text null,
  888. verbose_name varchar(1024) null,
  889. python_date_format varchar(255) null,
  890. constraint uq_table_columns_column_name
  891. unique (column_name, table_id),
  892. constraint table_columns_ibfk_1
  893. foreign key (table_id) references superset.tables (id),
  894. constraint table_columns_ibfk_2
  895. foreign key (created_by_fk) references superset.ab_user (id),
  896. constraint table_columns_ibfk_3
  897. foreign key (changed_by_fk) references superset.ab_user (id)
  898. );
  899. create index changed_by_fk
  900. on superset.table_columns (changed_by_fk);
  901. create index created_by_fk
  902. on superset.table_columns (created_by_fk);
  903. create index table_id
  904. on superset.table_columns (table_id);
  905. create index changed_by_fk
  906. on superset.tables (changed_by_fk);
  907. create index created_by_fk
  908. on superset.tables (created_by_fk);
  909. create index database_id
  910. on superset.tables (database_id);
  911. create table if not exists superset.tag
  912. (
  913. created_on datetime null,
  914. changed_on datetime null,
  915. id int auto_increment
  916. primary key,
  917. name varchar(250) null,
  918. type enum('custom', 'type', 'owner', 'favorited_by') null,
  919. created_by_fk int null,
  920. changed_by_fk int null,
  921. constraint name
  922. unique (name),
  923. constraint tag_ibfk_1
  924. foreign key (created_by_fk) references superset.ab_user (id),
  925. constraint tag_ibfk_2
  926. foreign key (changed_by_fk) references superset.ab_user (id)
  927. );
  928. create index changed_by_fk
  929. on superset.tag (changed_by_fk);
  930. create index created_by_fk
  931. on superset.tag (created_by_fk);
  932. create table if not exists superset.tagged_object
  933. (
  934. created_on datetime null,
  935. changed_on datetime null,
  936. id int auto_increment
  937. primary key,
  938. tag_id int null,
  939. object_id int null,
  940. object_type enum('query', 'chart', 'dashboard') null,
  941. created_by_fk int null,
  942. changed_by_fk int null,
  943. constraint tagged_object_ibfk_1
  944. foreign key (tag_id) references superset.tag (id),
  945. constraint tagged_object_ibfk_2
  946. foreign key (created_by_fk) references superset.ab_user (id),
  947. constraint tagged_object_ibfk_3
  948. foreign key (changed_by_fk) references superset.ab_user (id)
  949. );
  950. create index changed_by_fk
  951. on superset.tagged_object (changed_by_fk);
  952. create index created_by_fk
  953. on superset.tagged_object (created_by_fk);
  954. create index ix_tagged_object_object_id
  955. on superset.tagged_object (object_id);
  956. create index tag_id
  957. on superset.tagged_object (tag_id);
  958. create table if not exists superset.url
  959. (
  960. created_on datetime null,
  961. changed_on datetime null,
  962. id int auto_increment
  963. primary key,
  964. url text null,
  965. created_by_fk int null,
  966. changed_by_fk int null,
  967. constraint url_ibfk_1
  968. foreign key (changed_by_fk) references superset.ab_user (id),
  969. constraint url_ibfk_2
  970. foreign key (created_by_fk) references superset.ab_user (id)
  971. );
  972. create index changed_by_fk
  973. on superset.url (changed_by_fk);
  974. create index created_by_fk
  975. on superset.url (created_by_fk);
  976. create table if not exists superset.user_attribute
  977. (
  978. created_on datetime null,
  979. changed_on datetime null,
  980. id int auto_increment
  981. primary key,
  982. user_id int null,
  983. welcome_dashboard_id int null,
  984. created_by_fk int null,
  985. changed_by_fk int null,
  986. constraint user_attribute_ibfk_1
  987. foreign key (changed_by_fk) references superset.ab_user (id),
  988. constraint user_attribute_ibfk_2
  989. foreign key (created_by_fk) references superset.ab_user (id),
  990. constraint user_attribute_ibfk_3
  991. foreign key (user_id) references superset.ab_user (id),
  992. constraint user_attribute_ibfk_4
  993. foreign key (welcome_dashboard_id) references superset.dashboards (id)
  994. );
  995. create index changed_by_fk
  996. on superset.user_attribute (changed_by_fk);
  997. create index created_by_fk
  998. on superset.user_attribute (created_by_fk);
  999. create index user_id
  1000. on superset.user_attribute (user_id);
  1001. create index welcome_dashboard_id
  1002. on superset.user_attribute (welcome_dashboard_id);

参考