DataGear 变更部署数据库为SQL Server填坑指南(含转写后的SQL server代码及SQL server配置文件)

1. 引言

DataGear默认使用Derby数据库作为系统的元数据库,至于待分析的业务库则支持MySQL、SQL Server等。
Derby数据库足以支持系统的数据集、图表、看板等对象的管理,且不需要安装数据库服务,但由于目前DataGear不支持单点登录集成,因此项目上为了便于用户认证信息的统一管理,以及DataGear数据库的备份等,将Derby变更为SQL Server,与待分析的业务数据库一致。
在变更操作过程中,参考了DataGear官方说明,操作时遇到一些坑,记录下来分享与大家。
不少内容是引用官方文档的,直接抄来了。

datagear架构图


gitee地址:
https://gitee.com/datagear/datagear

2. 配置数据库链接

在config/application.properties添加datasource.driverClassName、datasource.url、datasource.username、datasource.password配置项,配置新数据库连接。

MySQL

datasource.driverClassName=com.mysql.cj.jdbc.Driver datasource.url=jdbc:mysql://localhost:3306/datagear datasource.username=datagear datasource.password=datagear

SQL Server

datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver datasource.url=jdbc:sqlserver://192.168.1.30:1433;SelectMethod=cursor;DatabaseName=datagear datasource.username=datagear datasource.password=datagear 3. 引入数据库驱动

在根目录下新建lib包,将JDBC驱动(sqljdbc4-4.0.jar)放入。
修改startup.bat为

java -Xbootclasspath/a:lib/sqljdbc4-4.0.jar -jar datagear-2.4.0.jar 4. 手动初始化数据库

此时运行startup,datagear将会按照配置的链接访问数据库,如果数据库配置以及驱动无误,则会进入下一步。
接着datagear检测到没有数据库,此时会自动创建数据库,使用的SQL是打包在jar文件中的,源码库路径为datagear-management/src/main/resources/org/datagear/management/ddl/datagear.sql。此SQL为Derby数据库,因此将执行失败。
扩展:可以用SQL server等数据库脚本替换了源码sql并打包,分发到项目上,项目上直接执行即可创建数据库,类似于Activity等的部署。
接着需要先改写Derby建库脚本为SQL server,改写后执行SQL,然后设置版本号,然后运行startup.bat即可。
坑:如果是新环境,DATAGEAR_VERSION(版本)表中的记录为空,此时按照官方说明执行SQL设置版本号将不起效。

UPDATE DATAGEAR_VERSION SET VERSION_VALUE='当前版本号'

或许Derby支持数据不存在则insert的update骚操作,对于SQL server需要insert下。
此坑造成的效果时,启动时dategear查询到当前已有数据库,但版本为null,因此需要升级,且从头升级,于是执行打包的SQL。

5. 改写SQL

DataGear的(升级)SQL脚本非常漂亮,每个版本不论是否有SQL更新,都写有注释,供手工和自动执行时参考。

----------------------------------------- --version[1.6.1], DO NOT EDIT THIS LINE! -----------------------------------------

如果是新环境,则需要从头执行到尾,如果是升级,则找到起始版本执行后边的SQL即可。

以下列举Derby转SQL server的几个常见操作。

TIMESTAMP,巨坑,SQL server也有该数据类型,但意义不一样,改为datetime

CURRENT_TIMESTAMP,当前时间,修改为(getdate()),获取当前时间

函数按照SQLserver语法改写,变量填写@即可。函数实现Derby不支持的replace、取余操作,datagear采用了java扩展,SQL server直接用系统函数、操作符即可,不需要.net扩展

DATAGEAR_REPLACEREGEX,按官方说明,不必理睬即可,该正则表达式替换新版本中已废弃

RENAME COLUMN ,重命名列,按照SQL server语法替换

RENAME TABLE ,重命名表,按照SQL server语法替换

表中加字段,ADD COLUMN 去掉column

ALTER COLUMN DS_TYPE SET NOT NULL;,修改列非空,SQL server需要找到原来的类型,一并修改。

VARCHAR(10000),SQL server支持到8K,修改为VARCHAR(8000)

修改后的SQL Server版SQL为:

----------------------------------------- --version[1.0.0], DO NOT EDIT THIS LINE! ----------------------------------------- if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_VERSION ( VERSION_MAJOR VARCHAR(50), VERSION_MINOR VARCHAR(50), VERSION_REVISION VARCHAR(50), VERSION_BUILD VARCHAR(50) ); go if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_USER ( USER_ID VARCHAR(50) NOT NULL, USER_NAME VARCHAR(50) NOT NULL, USER_PASSWORD VARCHAR(200) NOT NULL, USER_REAL_NAME VARCHAR(100), USER_EMAIL VARCHAR(200), USER_IS_ADMIN VARCHAR(20), USER_CREATE_TIME DATETIME, PRIMARY KEY (USER_ID), UNIQUE (USER_NAME) ); go --alter table DATAGEAR_USER alter column USER_CREATE_TIME datetime; --无法更改列 'USER_CREATE_TIME',因为它是 'timestamp'。 --alter table DATAGEAR_USER drop column USER_CREATE_TIME; --alter table DATAGEAR_USER add USER_CREATE_TIME DATETIME; --the password is 'admin' INSERT INTO DATAGEAR_USER VALUES('admin', 'admin', '4c6d8d058a4db956660f0ee51fcb515f93471a086fc676bfb71ba2ceece5bf4702c61cefab3fa54b', '', '', 'true', default); if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_SCHEMA ( SCHEMA_ID VARCHAR(50) NOT NULL, SCHEMA_TITLE VARCHAR(100) NOT NULL, SCHEMA_URL VARCHAR(200) NOT NULL, SCHEMA_USER VARCHAR(200), SCHEMA_PASSWORD VARCHAR(200), SCHEMA_CREATE_USER_ID VARCHAR(50), SCHEMA_CREATE_TIME DATETIME, SCHEMA_SHARED VARCHAR(20), DRIVER_ENTITY_ID VARCHAR(100), PRIMARY KEY (SCHEMA_ID) ); --alter table DATAGEAR_SCHEMA drop column SCHEMA_CREATE_TIME; --alter table DATAGEAR_SCHEMA add SCHEMA_CREATE_TIME DATETIME; ----------------------------------------- --version[1.1.0], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.1.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.2.0], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.3.0], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.4.0], DO NOT EDIT THIS LINE! ----------------------------------------- if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_ROLE ( ROLE_ID VARCHAR(50) NOT NULL, ROLE_NAME VARCHAR(100) NOT NULL, ROLE_DESCRIPTION VARCHAR(200), ROLE_ENABLED VARCHAR(10) NOT NULL, ROLE_CREATE_TIME DATETIME, PRIMARY KEY (ROLE_ID) ); --alter table DATAGEAR_ROLE drop column ROLE_CREATE_TIME; --alter table DATAGEAR_ROLE add ROLE_CREATE_TIME DATETIME; if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_ROLE_USER ( RU_ID VARCHAR(50) NOT NULL, RU_ROLE_ID VARCHAR(50) NOT NULL, RU_USER_ID VARCHAR(50) NOT NULL, PRIMARY KEY (RU_ID) ); ALTER TABLE DATAGEAR_ROLE_USER ADD FOREIGN KEY (RU_ROLE_ID) REFERENCES DATAGEAR_ROLE (ROLE_ID) ON DELETE CASCADE; ALTER TABLE DATAGEAR_ROLE_USER ADD FOREIGN KEY (RU_USER_ID) REFERENCES DATAGEAR_USER (USER_ID) ON DELETE CASCADE; ALTER TABLE DATAGEAR_ROLE_USER ADD CONSTRAINT UK_RU_ROLE_USER_ID UNIQUE (RU_ROLE_ID, RU_USER_ID); if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_AUTHORIZATION ( AUTH_ID VARCHAR(50) NOT NULL, AUTH_RESOURCE VARCHAR(200) NOT NULL, AUTH_RESOURCE_TYPE VARCHAR(50) NOT NULL, AUTH_PRINCIPAL VARCHAR(200) NOT NULL, AUTH_PRINCIPAL_TYPE VARCHAR(50) NOT NULL, AUTH_PERMISSION SMALLINT NOT NULL, AUTH_ENABLED VARCHAR(10) NOT NULL, AUTH_CREATE_TIME DATETIME, AUTH_CREATE_USER_ID VARCHAR(50), PRIMARY KEY (AUTH_ID) ); --alter table DATAGEAR_AUTHORIZATION drop column AUTH_CREATE_TIME; --alter table DATAGEAR_AUTHORIZATION add AUTH_CREATE_TIME DATETIME; go --自定义REPLACE函数 --srcStr 原始字符串 --oldStr 要替换的旧子串 --newStr 要替换的新子串 CREATE FUNCTION DATAGEAR_REPLACE(@srcStr VARCHAR(500), @oldStr VARCHAR(100), @newStr VARCHAR(100)) RETURNS VARCHAR(500) as begin --PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management.util.DerbyFunctionSupport.replace'; return replace(@srcStr,@oldStr,@newStr); end; go if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_SQL_HISTORY ( SQLHIS_ID VARCHAR(50) NOT NULL, SQLHIS_SQL VARCHAR(5000) NOT NULL, SQLHIS_SCHEMA_ID VARCHAR(50) NOT NULL, SQLHIS_USER_ID VARCHAR(50) NOT NULL, SQLHIS_CREATE_TIME DATETIME DEFAULT GETDATE(), PRIMARY KEY (SQLHIS_ID) ); --alter table DATAGEAR_SQL_HISTORY drop column SQLHIS_CREATE_TIME; --alter table DATAGEAR_SQL_HISTORY add SQLHIS_CREATE_TIME DATETIME; ALTER TABLE DATAGEAR_SQL_HISTORY ADD FOREIGN KEY (SQLHIS_SCHEMA_ID) REFERENCES DATAGEAR_SCHEMA (SCHEMA_ID) ON DELETE CASCADE; ----------------------------------------- --version[1.5.0], DO NOT EDIT THIS LINE! ----------------------------------------- --SQL数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_SQL_DATA_SET ( DS_ID VARCHAR(50) NOT NULL, DS_NAME VARCHAR(100) NOT NULL, DS_SCHEMA_ID VARCHAR(50) NOT NULL, DS_SQL VARCHAR(1000) NOT NULL, DS_CREATE_USER_ID VARCHAR(50), DS_CREATE_TIME DATETIME, PRIMARY KEY (DS_ID) ); -- alter table DATAGEAR_DATA_SET drop column DS_CREATE_TIME; -- alter table DATAGEAR_DATA_SET add DS_CREATE_TIME DATETIME; --该字段后需要删除,约束将限制其删除 --ALTER TABLE DATAGEAR_SQL_DATA_SET ADD FOREIGN KEY (DS_SCHEMA_ID) REFERENCES DATAGEAR_SCHEMA (SCHEMA_ID); --数据集属性 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_PROP ( PROP_DS_ID VARCHAR(50) NOT NULL, PROP_NAME VARCHAR(100) NOT NULL, PROP_TYPE VARCHAR(50) NOT NULL, PROP_LABEL VARCHAR(100), PROP_ORDER INTEGER ); ALTER TABLE DATAGEAR_DATA_SET_PROP ADD FOREIGN KEY (PROP_DS_ID) REFERENCES DATAGEAR_SQL_DATA_SET (DS_ID) ON DELETE CASCADE; ALTER TABLE DATAGEAR_DATA_SET_PROP ADD CONSTRAINT UK_DS_PROP_DS_ID_NAME UNIQUE (PROP_DS_ID, PROP_NAME); --数据集参数 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_PAR ( PAR_DS_ID VARCHAR(50) NOT NULL, PAR_NAME VARCHAR(100) NOT NULL, PAR_TYPE VARCHAR(100) NOT NULL, PAR_REQUIRED VARCHAR(10), PAR_DEFAULT_VALUE VARCHAR(200), PAR_ORDER INTEGER ); ALTER TABLE DATAGEAR_DATA_SET_PAR ADD FOREIGN KEY (PAR_DS_ID) REFERENCES DATAGEAR_SQL_DATA_SET (DS_ID) ON DELETE CASCADE; ALTER TABLE DATAGEAR_DATA_SET_PAR ADD CONSTRAINT UK_DS_PAR_DS_ID_NAME UNIQUE (PAR_DS_ID, PAR_NAME); --数据集输出 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_EXPT ( EXPT_DS_ID VARCHAR(50) NOT NULL, EXPT_NAME VARCHAR(100) NOT NULL, EXPT_TYPE VARCHAR(50) NOT NULL, EXPT_ORDER INTEGER ); ALTER TABLE DATAGEAR_DATA_SET_EXPT ADD FOREIGN KEY (EXPT_DS_ID) REFERENCES DATAGEAR_SQL_DATA_SET (DS_ID) ON DELETE CASCADE; ALTER TABLE DATAGEAR_DATA_SET_EXPT ADD CONSTRAINT UK_DS_EXPT_DS_ID_NAME UNIQUE (EXPT_DS_ID, EXPT_NAME); --图表 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_HTML_CHART_WIDGET ( HCW_ID VARCHAR(50) NOT NULL, HCW_NAME VARCHAR(100) NOT NULL, HCW_PLUGIN_ID VARCHAR(100) NOT NULL, HCW_UPDATE_INTERVAL INTEGER, HCW_CREATE_USER_ID VARCHAR(50), HCW_CREATE_TIME DATETIME, PRIMARY KEY (HCW_ID) ); -- alter table DATAGEAR_HTML_CHART_WIDGET drop column HCW_CREATE_TIME; -- alter table DATAGEAR_HTML_CHART_WIDGET add HCW_CREATE_TIME DATETIME; --图表-数据集信息 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_HCW_DS ( HCW_ID VARCHAR(50) NOT NULL, DS_ID VARCHAR(50) NOT NULL, DS_PROPERTY_SIGNS VARCHAR(500), DS_ORDER INTEGER ); ALTER TABLE DATAGEAR_HCW_DS ADD FOREIGN KEY (HCW_ID) REFERENCES DATAGEAR_HTML_CHART_WIDGET (HCW_ID) ON DELETE CASCADE; ALTER TABLE DATAGEAR_HCW_DS ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_SQL_DATA_SET (DS_ID) ON DELETE CASCADE; --看板 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_HTML_DASHBOARD ( HD_ID VARCHAR(50) NOT NULL, HD_NAME VARCHAR(100) NOT NULL, HD_TEMPLATE VARCHAR(100) NOT NULL, HD_TEMPLATE_ENCODING VARCHAR(50), HD_CREATE_USER_ID VARCHAR(50), HD_CREATE_TIME DATETIME, PRIMARY KEY (HD_ID) ); -- alter table DATAGEAR_HTML_DASHBOARD drop column HD_CREATE_TIME; -- alter table DATAGEAR_HTML_DASHBOARD add HD_CREATE_TIME DATETIME; ----------------------------------------- --version[1.6.0], DO NOT EDIT THIS LINE! ----------------------------------------- --ALTER TABLE DATAGEAR_HTML_DASHBOARD ALTER COLUMN HD_TEMPLATE SET DATA TYPE VARCHAR(500); ----------------------------------------- --version[1.6.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.7.0], DO NOT EDIT THIS LINE! ----------------------------------------- --自定义正则REPLACE函数,目前仅用于下面修改数据标记 --srcStr 原始字符串 --oldStr 要替换的正则表达式 --newStr 要替换的新子串 --CREATE FUNCTION DATAGEAR_REPLACEREGEX(srcStr VARCHAR(500), oldStr VARCHAR(100), newStr VARCHAR(100)) RETURNS VARCHAR(500) --PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management.util.DerbyFunctionSupport.replaceRegex'; --扩充SQL字段 ALTER TABLE DATAGEAR_SQL_DATA_SET ALTER COLUMN DS_SQL VARCHAR(8000); ----------------------------------------- --version[1.8.0], DO NOT EDIT THIS LINE! ----------------------------------------- --默认值字段改为描述字段 --RENAME COLUMN DATAGEAR_DATA_SET_PAR.PAR_DEFAULT_VALUE TO PAR_DESC; exec sp_rename 'DATAGEAR_DATA_SET_PAR.PAR_DEFAULT_VALUE','PAR_DESC' --移除数据集输出项表 DROP TABLE DATAGEAR_DATA_SET_EXPT; --扩充图表数据集数据标记列 ALTER TABLE DATAGEAR_HCW_DS ALTER COLUMN DS_PROPERTY_SIGNS VARCHAR(1000); --添加图表数据集别名列 ALTER TABLE DATAGEAR_HCW_DS ADD DS_ALIAS VARCHAR(100); --添加图表数据集参数值列 ALTER TABLE DATAGEAR_HCW_DS ADD DS_PARAM_VALUES VARCHAR(1000); ----------------------------------------- --version[1.8.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.9.0], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.10.0], DO NOT EDIT THIS LINE! ----------------------------------------- --添加数据集参数输入框类型 ALTER TABLE DATAGEAR_DATA_SET_PAR ADD PAR_INPUT_TYPE VARCHAR(50); --添加数据集参数输入框载荷 ALTER TABLE DATAGEAR_DATA_SET_PAR ADD PAR_INPUT_PAYLOAD VARCHAR(1000); ----------------------------------------- --version[1.10.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.11.0], DO NOT EDIT THIS LINE! ----------------------------------------- --改为通用数据集 --RENAME TABLE DATAGEAR_SQL_DATA_SET TO DATAGEAR_DATA_SET; exec sp_rename 'DATAGEAR_SQL_DATA_SET','DATAGEAR_DATA_SET'; --新建SQL数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_SQL ( DS_ID VARCHAR(50) NOT NULL, DS_SCHEMA_ID VARCHAR(50) NOT NULL, DS_SQL VARCHAR(8000) NOT NULL, PRIMARY KEY (DS_ID) ); --迁移SQL数据集数据 INSERT INTO DATAGEAR_DATA_SET_SQL (DS_ID, DS_SCHEMA_ID, DS_SQL) SELECT DS_ID, DS_SCHEMA_ID, DS_SQL FROM DATAGEAR_DATA_SET; --添加约束 ALTER TABLE DATAGEAR_DATA_SET_SQL ADD FOREIGN KEY (DS_SCHEMA_ID) REFERENCES DATAGEAR_SCHEMA (SCHEMA_ID); --引入表 'DATAGEAR_DATA_SET_SQL' 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束 ALTER TABLE DATAGEAR_DATA_SET_SQL ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; --ALTER TABLE DATAGEAR_DATA_SET_SQL ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE NO ACTION; --移除通用数据集中的SQL数据集列 --需要先移除外键约束,然后删除列,Derby可能直接可以删除 --ALTER TABLE DATAGEAR_DATA_SET DROP CONSTRAINT [FK__DATAGEAR___DS_SC__04459E07]; ALTER TABLE DATAGEAR_DATA_SET DROP COLUMN DS_SCHEMA_ID; ALTER TABLE DATAGEAR_DATA_SET DROP COLUMN DS_SQL; --为通用数据集添加类型字段,并全部初始化为'SQL' ALTER TABLE DATAGEAR_DATA_SET ADD DS_TYPE VARCHAR(50); UPDATE DATAGEAR_DATA_SET SET DS_TYPE = 'SQL'; ALTER TABLE DATAGEAR_DATA_SET ALTER column DS_TYPE VARCHAR(50) NOT NULL; --2020-08-10 --JSON值数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_JSON_VALUE ( DS_ID VARCHAR(50) NOT NULL, DS_VALUE VARCHAR(8000) NOT NULL, PRIMARY KEY (DS_ID) ); ALTER TABLE DATAGEAR_DATA_SET_JSON_VALUE ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; --2020-08-12 --JSON文件数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_JSON_FILE ( DS_ID VARCHAR(50) NOT NULL, DS_FILE_NAME VARCHAR(100) NOT NULL, DS_DISPLAY_NAME VARCHAR(100) NOT NULL, PRIMARY KEY (DS_ID) ); ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; ----------------------------------------- --version[1.11.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[1.12.0], DO NOT EDIT THIS LINE! ----------------------------------------- --2020-08-28 --JSON文件数据集添加编码字段 ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD DS_FILE_ENCODING VARCHAR(50); --2020-08-28 --Excel文件数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_EXCEL ( DS_ID VARCHAR(50) NOT NULL, DS_FILE_NAME VARCHAR(100) NOT NULL, DS_DISPLAY_NAME VARCHAR(100) NOT NULL, DS_SHEET_INDEX INTEGER, DS_NAME_ROW INTEGER, DS_DATA_ROW_EXP VARCHAR(100), DS_DATA_COLUMN_EXP VARCHAR(100), DS_FORCE_XLS VARCHAR(10), PRIMARY KEY (DS_ID) ); ALTER TABLE DATAGEAR_DATA_SET_EXCEL ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; --2020-08-31 --CSV值数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_CSV_VALUE ( DS_ID VARCHAR(50) NOT NULL, DS_VALUE VARCHAR(8000) NOT NULL, DS_NAME_ROW INTEGER, PRIMARY KEY (DS_ID) ); ALTER TABLE DATAGEAR_DATA_SET_CSV_VALUE ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; --2020-08-31 --CSV文件数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_CSV_FILE ( DS_ID VARCHAR(50) NOT NULL, DS_FILE_NAME VARCHAR(100) NOT NULL, DS_DISPLAY_NAME VARCHAR(100) NOT NULL, DS_FILE_ENCODING VARCHAR(50), DS_NAME_ROW INTEGER, PRIMARY KEY (DS_ID) ); ALTER TABLE DATAGEAR_DATA_SET_CSV_FILE ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; --2020-09-03 --JSON文件数据集添加数据JSON路径字段 ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD DS_DATA_JSON_PATH VARCHAR(200); --2020-09-05 --HTTP数据集 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DATA_SET_HTTP ( DS_ID VARCHAR(50) NOT NULL, DS_URI VARCHAR(1000) NOT NULL, DS_HEADER_CONTENT VARCHAR(5000), DS_RQT_METHOD VARCHAR(50), DS_RQT_CONTENT_TYPE VARCHAR(100), DS_RQT_CONTENT_CHARSET VARCHAR(100), DS_RQT_CONTENT varchar(8000), DS_RPS_CONTENT_TYPE VARCHAR(100), DS_RPS_DATA_JSON_PATH VARCHAR(200), PRIMARY KEY (DS_ID) ); ALTER TABLE DATAGEAR_DATA_SET_HTTP ADD FOREIGN KEY (DS_ID) REFERENCES DATAGEAR_DATA_SET (DS_ID) ON DELETE CASCADE; ----------------------------------------- --version[1.13.0], DO NOT EDIT THIS LINE! ----------------------------------------- --2020-09-22 --数据分析项目 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_ANALYSIS_PROJECT ( AP_ID VARCHAR(50) NOT NULL, AP_NAME VARCHAR(100) NOT NULL, AP_DESC VARCHAR(500), AP_CREATE_USER_ID VARCHAR(50), AP_CREATE_TIME DATETIME, PRIMARY KEY (AP_ID) ); -- alter table DATAGEAR_ANALYSIS_PROJECT drop column AP_CREATE_TIME; -- alter table DATAGEAR_ANALYSIS_PROJECT add AP_CREATE_TIME DATETIME; ALTER TABLE DATAGEAR_DATA_SET ADD DS_AP_ID VARCHAR(50); ALTER TABLE DATAGEAR_HTML_CHART_WIDGET ADD HCW_AP_ID VARCHAR(50); ALTER TABLE DATAGEAR_HTML_DASHBOARD ADD HD_AP_ID VARCHAR(50); --2020-09-25 --添加外键 ALTER TABLE DATAGEAR_DATA_SET ADD FOREIGN KEY (DS_AP_ID) REFERENCES DATAGEAR_ANALYSIS_PROJECT (AP_ID); ALTER TABLE DATAGEAR_HTML_CHART_WIDGET ADD FOREIGN KEY (HCW_AP_ID) REFERENCES DATAGEAR_ANALYSIS_PROJECT (AP_ID); ALTER TABLE DATAGEAR_HTML_DASHBOARD ADD FOREIGN KEY (HD_AP_ID) REFERENCES DATAGEAR_ANALYSIS_PROJECT (AP_ID); --2020-09-25 --添加索引 CREATE INDEX DATAGEAR_DATA_SET_CREATE_USER_ID ON DATAGEAR_DATA_SET(DS_CREATE_USER_ID); CREATE INDEX DATAGEAR_HTML_CHART_WIDGET_CREATE_USER_ID ON DATAGEAR_HTML_CHART_WIDGET(HCW_CREATE_USER_ID); CREATE INDEX DATAGEAR_HTML_DASHBOARD_CREATE_USER_ID ON DATAGEAR_HTML_DASHBOARD(HD_CREATE_USER_ID); --2020-09-26 --数据集资源目录 if not exists (select * from sysobjects where and xtype='U') CREATE TABLE DATAGEAR_DSR_DIRECTORY ( DD_ID VARCHAR(50) NOT NULL, DD_DIRECTORY VARCHAR(250) NOT NULL, DD_DESC VARCHAR(500), DD_CREATE_USER_ID VARCHAR(50), DD_CREATE_TIME DATETIME, PRIMARY KEY (DD_ID) ); -- alter table DATAGEAR_DSR_DIRECTORY drop column DD_CREATE_TIME; -- alter table DATAGEAR_DSR_DIRECTORY add DD_CREATE_TIME DATETIME; --2020-09-26 --为文件类数据集添加服务端文件相关字段 ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD DS_FILE_SOURCE_TYPE VARCHAR(50); ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD DS_DSRD_ID VARCHAR(50); ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD DS_DSRD_FILE_NAME VARCHAR(500); ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ADD FOREIGN KEY (DS_DSRD_ID) REFERENCES DATAGEAR_DSR_DIRECTORY (DD_ID); --旧数据都应改为UPLOAD类型 UPDATE DATAGEAR_DATA_SET_JSON_FILE SET DS_FILE_SOURCE_TYPE = 'UPLOAD'; ALTER TABLE DATAGEAR_DATA_SET_JSON_FILE ALTER COLUMN DS_FILE_SOURCE_TYPE VARCHAR(50) NOT NULL; ALTER TABLE DATAGEAR_DATA_SET_EXCEL ADD DS_FILE_SOURCE_TYPE VARCHAR(50); ALTER TABLE DATAGEAR_DATA_SET_EXCEL ADD DS_DSRD_ID VARCHAR(50); ALTER TABLE DATAGEAR_DATA_SET_EXCEL ADD DS_DSRD_FILE_NAME VARCHAR(500); ALTER TABLE DATAGEAR_DATA_SET_EXCEL ADD FOREIGN KEY (DS_DSRD_ID) REFERENCES DATAGEAR_DSR_DIRECTORY (DD_ID); --旧数据都应改为UPLOAD类型 UPDATE DATAGEAR_DATA_SET_EXCEL SET DS_FILE_SOURCE_TYPE = 'UPLOAD'; ALTER TABLE DATAGEAR_DATA_SET_EXCEL ALTER column DS_FILE_SOURCE_TYPE VARCHAR(50) NOT NULL; ALTER TABLE DATAGEAR_DATA_SET_CSV_FILE ADD DS_FILE_SOURCE_TYPE VARCHAR(50); ALTER TABLE DATAGEAR_DATA_SET_CSV_FILE ADD DS_DSRD_ID VARCHAR(50); ALTER TABLE DATAGEAR_DATA_SET_CSV_FILE ADD DS_DSRD_FILE_NAME VARCHAR(500); ALTER TABLE DATAGEAR_DATA_SET_CSV_FILE ADD FOREIGN KEY (DS_DSRD_ID) REFERENCES DATAGEAR_DSR_DIRECTORY (DD_ID); --旧数据都应改为UPLOAD类型 UPDATE DATAGEAR_DATA_SET_CSV_FILE SET DS_FILE_SOURCE_TYPE = 'UPLOAD'; ALTER TABLE DATAGEAR_DATA_SET_CSV_FILE ALTER COLUMN DS_FILE_SOURCE_TYPE VARCHAR(50) NOT NULL; ----------------------------------------- --version[1.13.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[2.0.0], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[2.1.0], DO NOT EDIT THIS LINE! ----------------------------------------- --2020-12-04 --扩容列长度 ALTER TABLE DATAGEAR_SCHEMA ALTER column SCHEMA_URL VARCHAR(1000); --2020-12-09 --添加内置角色 INSERT INTO DATAGEAR_ROLE VALUES('ROLE_REGISTRY', '注册用户', '系统新添加和注册的用户都会自动添加至此角色', 'true', default); INSERT INTO DATAGEAR_ROLE VALUES('ROLE_DATA_ADMIN', '数据管理员', '可以管理数据源、数据集、图表、看板', 'true', default); INSERT INTO DATAGEAR_ROLE VALUES('ROLE_DATA_ANALYST', '数据分析员', '仅可查看数据源、数据集、图表、看板,展示图表和看板', 'true', default); --2020-12-10 --将全部已注册用户关联至[注册用户]角色 --此语句可多次执行,因为已排除了可能的重复项 INSERT INTO DATAGEAR_ROLE_USER SELECT 'RUREG' + USR.USER_ID, 'ROLE_REGISTRY', USR.USER_ID FROM DATAGEAR_USER USR WHERE USR.USER_ID NOT IN (SELECT RU_USER_ID FROM DATAGEAR_ROLE_USER WHERE RU_ROLE_ID = 'ROLE_REGISTRY'); --将全部已注册用户关联至[数据管理员]角色,这样才符合之前版本的设计概念 --此语句可多次执行,因为已排除了可能的重复项 INSERT INTO DATAGEAR_ROLE_USER SELECT 'RUDA' + USR.USER_ID, 'ROLE_DATA_ADMIN', USR.USER_ID FROM DATAGEAR_USER USR WHERE USR.USER_ID NOT IN (SELECT RU_USER_ID FROM DATAGEAR_ROLE_USER WHERE RU_ROLE_ID = 'ROLE_DATA_ADMIN'); ----------------------------------------- --version[2.1.1], DO NOT EDIT THIS LINE! ----------------------------------------- ----------------------------------------- --version[2.2.0], DO NOT EDIT THIS LINE! ----------------------------------------- --2021-01-17 --简化DATAGEAR_VERSION表结构 ALTER TABLE DATAGEAR_VERSION ADD VERSION_VALUE VARCHAR(100); go UPDATE DATAGEAR_VERSION SET VERSION_VALUE = (SELECT VERSION_MAJOR + '.' + VERSION_MINOR + '.' + VERSION_REVISION FROM DATAGEAR_VERSION); go ALTER TABLE DATAGEAR_VERSION DROP COLUMN VERSION_MAJOR; go ALTER TABLE DATAGEAR_VERSION DROP COLUMN VERSION_MINOR; go ALTER TABLE DATAGEAR_VERSION DROP COLUMN VERSION_REVISION; go ALTER TABLE DATAGEAR_VERSION DROP COLUMN VERSION_BUILD; go ----------------------------------------- --version[2.3.0], DO NOT EDIT THIS LINE! ----------------------------------------- --添加图表数据集附件列 ALTER TABLE DATAGEAR_HCW_DS ADD DS_ATTACHMENT VARCHAR(20); go --自定义整数取余数函数 --valueNum 数值 --divNum 除数 CREATE FUNCTION DATAGEAR_FUNC_MODINT(@valueNum INTEGER, @divNum INTEGER) RETURNS INTEGER as begin --PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management.util.DerbyFunctionSupport.modInt'; return @valueNum % @divNum; end; go --自定义字符串取长度函数 --valueStr 字符串 CREATE FUNCTION DATAGEAR_FUNC_LENGTH(@valueStr VARCHAR(1000)) RETURNS INTEGER as begin -- PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'org.datagear.management.util.DerbyFunctionSupport.lengthStr'; return len(@valueStr); end; go ----------------------------------------- --version[2.4.0], DO NOT EDIT THIS LINE! ----------------------------------------- --添加数据集属性默认值列 ALTER TABLE DATAGEAR_DATA_SET_PROP ADD PROP_DFT_VALUE VARCHAR(100); UPDATE DATAGEAR_VERSION SET VERSION_VALUE='2.4.0'; insert into DATAGEAR_VERSION(VERSION_VALUE)values('2.4.0'); --select 'DROP TABLE '+name + ';' from sysobjects where name like'DATAGEAR%' and xtype='U' --select * from DATAGEAR_VERSION; --select 'ALTER TABLE ' + b.name + ' NOCHECK CONSTRAINT ' + a.name +';' from sysobjects a ,sysobjects b where a.xtype ='f' and a.parent_obj = b.id and b.name like 'DATAGEAR%'; --select 'ALTER TABLE ' + b.name + ' CHECK CONSTRAINT ' + a.name +';' from sysobjects a ,sysobjects b where a.xtype ='f' and a.parent_obj = b.id and b.name like 'DATAGEAR%'; --select 'ALTER TABLE ' + b.name + ' DROP CONSTRAINT ' + a.name +';' from sysobjects a ,sysobjects b where a.xtype ='f' and a.parent_obj = b.id and b.name like 'DATAGEAR%'; --drop function dbo.DATAGEAR_FUNC_LENGTH; --drop function dbo.DATAGEAR_FUNC_MODINT; --drop function dbo.DATAGEAR_REPLACE; 6. 其他

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygxpf.html