Skip to content

Commit

Permalink
Modify SQL file and README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Zzm0809 <934230207@qq.com>
  • Loading branch information
Zzm0809 committed May 20, 2024
1 parent f9f8e47 commit c05f730
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 35 deletions.
33 changes: 32 additions & 1 deletion dinky-admin/src/main/resources/db/migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
- V{版本号}__{描述}.sql 中间是**两个下划线**,固定规则,不符合规则将无法执行
- 每个版本只能有一个 V{版本号}__{描述}.sql 文件,否则将无法执行, 不管是 DDL 还是 DML 统一放在一个文件中



**升级脚本注意事项:**
- 如果你需要对某一个表添加字段,请不要使用`alter table add column`语句,使用如下语句:
- MySQL: `CALL add_column_if_not_exists('tableName', 'columnName', 'dataType', 'defaultValue', 'comment');`
- eg: `CALL add_column_if_not_exists('user', 'age', 'int', '0', 'age');`
- PostgresSQL: `SELECT add_column_if_not_exists('model_name', 'table_name', 'column_name', 'data_type', 'default_value', 'comment');`
- eg: `SELECT add_column_if_not_exists('public', 'user', 'age', 'int', '0', 'age');`


**其他注意事项:**
- 在你贡献代码时,如若涉及到了变更表结构,请添加回滚脚本,虽然 FlyWay 会有事务回滚操作,回滚脚本不会被 FlyWay 自动自行,但是为了本地调试测试时能方便进行回滚,所以添加回滚脚本
- 由于数据库类型不同,可能存在差异,请根据实际需求进行迭代增加脚本内容
- H2 数据库脚本需要按照规范进行正常的版本迭代(方便版本管理),但是 H2 数据库脚本不需要添加回滚脚本,因为 H2 数据库是内存数据库(默认程序启动时配置为内存模式,未持久化),每次启动都会重新创建,所以不需要回滚脚本

---

# English

## Pre requirements
Expand All @@ -37,4 +54,18 @@

**Attention:**
- V{version number}__{description}.SQL has two underscores in the middle, which are fixed rules. If they do not comply with the rules, they cannot be executed
- Each version can only have one V{version number}__{description}.sql file, otherwise it will not be executed, whether it is DDL or DML, it will be placed in one file
- Each version can only have one V{version number}__{description}.sql file, otherwise it will not be executed, whether it is DDL or DML, it will be placed in one file


**Upgrade script considerations:**
- If you need to add fields to a table, do not use the 'alter table add column' statement. Instead, use the following statement:
- MySQL: `CALL add_column_if_not_exists('tableName', 'columnName', 'dataType', 'defaultValue', 'comment');`
- eg: `CALL add_column_if_not_exists('user', 'age', 'int', '0', 'age');`
- PostgresSQL: `SELECT add_column_if_not_exists('model_name', 'table_name', 'column_name', 'data_type', 'default_value', 'comment');`
- eg: `SELECT add_column_if_not_exists('public', 'user', 'age', 'int', '0', 'age');`


**Other precautions:**
- When you contribute code, if it involves changing the table structure, please add a rollback script. Although FlyWay may have transaction rollback operations, the rollback script will not be automatically rolled back by FlyWay. However, in order to facilitate rollback during local debugging and testing, add a rollback script
- Due to different database types, there may be differences. Please iterate and add script content according to actual needs
- The H2 database script needs to perform normal version iteration according to the specifications (for easy version management), but the H2 database script does not need to add a rollback script because the H2 database is an in memory database (configured in memory mode by default when the program starts, not persistent), and will be recreated every time it starts, so there is no need to add a rollback script
32 changes: 0 additions & 32 deletions dinky-admin/src/main/resources/db/migration/h2/R1.1.0__release.sql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ ALTER TABLE dinky_history ALTER COLUMN statement SET DATA TYPE LONGVARCHAR ;
ALTER TABLE dinky_task ALTER COLUMN statement SET DATA TYPE LONGVARCHAR ;

ALTER TABLE dinky_task_version ALTER COLUMN statement SET DATA TYPE LONGVARCHAR ;

alter table dinky_udf_manage add column `language` VARCHAR(10) DEFAULT null comment 'udf language' ;
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ ALTER TABLE dinky_task_version CHANGE COLUMN `statement` `statement` longtext DE

# Delete the 1.1.0 record in the _dinky_flyway_schema_history table
DELETE FROM `_dinky_flyway_schema_history` WHERE version = '1.1.0';
ALTER TABLE dinky_udf_manage DROP COLUMN `language`;


SET FOREIGN_KEY_CHECKS = 1;
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ ALTER TABLE dinky_task CHANGE COLUMN `statement` `statement` mediumtext DEFAULT

ALTER TABLE dinky_task_version CHANGE COLUMN `statement` `statement` mediumtext DEFAULT NULL COMMENT 'flink sql statement';

alter table dinky_udf_manage add column `language` VARCHAR(10) DEFAULT null comment 'udf language' after class_name;

CALL add_column_if_not_exists('dinky_udf_manage', 'language', 'varchar(10)', 'NULL', 'udf language');

SET FOREIGN_KEY_CHECKS = 1;
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ ALTER TABLE public.dinky_task DROP COLUMN "second_level_owners";


-- Delete the 1.1.0 record in the _dinky_flyway_schema_history table
DELETE FROM public."_dinky_flyway_schema_history" WHERE version = '1.1.0';
DELETE FROM public."_dinky_flyway_schema_history" WHERE version = '1.1.0';

-- 删除 SELECT add_column_if_not_exists('public','dinky_udf_manage', 'language', 'varchar(10)', 'null', 'udf language');
alter table public.dinky_udf_manage drop column "language";
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,19 @@ SELECT add_column_if_not_exists('public','dinky_task', 'second_level_owners', 'v

update public.dinky_task set "first_level_owner" = "creator";

UPDATE public.dinky_user SET "password" = 'f4b3a484ee745b98d64cd69c429b2aa2' WHERE "id" =1 and "password"= '21232f297a57a5a743894a0e4a801fc3';
UPDATE public.dinky_user SET "password" = 'f4b3a484ee745b98d64cd69c429b2aa2' WHERE "id" =1 and "password"= '21232f297a57a5a743894a0e4a801fc3';

SELECT add_column_if_not_exists('public','dinky_udf_manage', 'language', 'varchar(10)', 'null', 'udf language');

UPDATE
dinky_udf_manage duml
SET
"language" =
CASE
WHEN r.file_name LIKE '%.zip' OR r.file_name LIKE '%.py' THEN 'python'
WHEN r.file_name LIKE '%.jar' THEN 'java'
ELSE 'unknown'
END
FROM dinky_resources r
WHERE
duml.resources_id = r.id;

0 comments on commit c05f730

Please sign in to comment.