Commit 65651fb1ede4731a15cc496e2ec7deb37647fae0
1 parent
77408250
feat: 创建虚拟dual表,达梦脚本优化
Showing
5 changed files
with
75 additions
and
5 deletions
sql/postgresql/ruoyi-vue-pro.sql
| ... | ... | @@ -5,11 +5,20 @@ |
| 5 | 5 | |
| 6 | 6 | Target Server Type : PostgreSQL |
| 7 | 7 | |
| 8 | - Date: 2024-05-01 23:25:45 | |
| 8 | + Date: 2024-05-03 23:36:19 | |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | -- ---------------------------- |
| 13 | +-- Table structure for dual | |
| 14 | +-- ---------------------------- | |
| 15 | +DROP TABLE IF EXISTS dual; | |
| 16 | +CREATE TABLE dual | |
| 17 | +( | |
| 18 | +); | |
| 19 | + | |
| 20 | + | |
| 21 | +-- ---------------------------- | |
| 13 | 22 | -- Table structure for infra_api_access_log |
| 14 | 23 | -- ---------------------------- |
| 15 | 24 | DROP TABLE IF EXISTS infra_api_access_log; |
| ... | ... | @@ -3866,7 +3875,6 @@ COMMENT ON COLUMN system_sms_code.updater IS '更新者'; |
| 3866 | 3875 | COMMENT ON COLUMN system_sms_code.update_time IS '更新时间'; |
| 3867 | 3876 | COMMENT ON COLUMN system_sms_code.deleted IS '是否删除'; |
| 3868 | 3877 | COMMENT ON COLUMN system_sms_code.tenant_id IS '租户编号'; |
| 3869 | -COMMENT ON COLUMN system_sms_code.idx_mobile IS '手机号'; | |
| 3870 | 3878 | COMMENT ON TABLE system_sms_code IS '手机验证码'; |
| 3871 | 3879 | |
| 3872 | 3880 | DROP SEQUENCE IF EXISTS system_sms_code_seq; |
| ... | ... | @@ -4703,3 +4711,4 @@ COMMIT; |
| 4703 | 4711 | DROP SEQUENCE IF EXISTS yudao_demo03_student_seq; |
| 4704 | 4712 | CREATE SEQUENCE yudao_demo03_student_seq |
| 4705 | 4713 | START 10; |
| 4714 | + | ... | ... |
sql/sqlserver/ruoyi-vue-pro.sql
| ... | ... | @@ -5,11 +5,30 @@ |
| 5 | 5 | |
| 6 | 6 | Target Server Type : Microsoft SQL Server |
| 7 | 7 | |
| 8 | - Date: 2024-05-02 15:29:31 | |
| 8 | + Date: 2024-05-03 23:36:38 | |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | -- ---------------------------- |
| 13 | +-- Table structure for dual | |
| 14 | +-- ---------------------------- | |
| 15 | +DROP TABLE IF EXISTS dual | |
| 16 | +GO | |
| 17 | + | |
| 18 | +CREATE TABLE dual | |
| 19 | +( | |
| 20 | + id int NULL | |
| 21 | +) | |
| 22 | +GO | |
| 23 | + | |
| 24 | +EXEC sp_addextendedproperty | |
| 25 | + 'MS_Description', N'数据库连接的表', | |
| 26 | + 'SCHEMA', N'dbo', | |
| 27 | + 'TABLE', N'dual' | |
| 28 | +GO | |
| 29 | + | |
| 30 | + | |
| 31 | +-- ---------------------------- | |
| 13 | 32 | -- Table structure for infra_api_access_log |
| 14 | 33 | -- ---------------------------- |
| 15 | 34 | DROP TABLE IF EXISTS infra_api_access_log; | ... | ... |
sql/tools/README.md
| ... | ... | @@ -54,7 +54,8 @@ docker load -i dm8_20230808_rev197096_x86_rh6_64_single.tar |
| 54 | 54 | ```Bash |
| 55 | 55 | docker compose up -d dm8 |
| 56 | 56 | # 注意:启动完 sqlserver 后,需要手动再执行如下命令,因为 SQL Server 不支持初始化脚本 |
| 57 | -docker compose exec -i dm8 /bin/bash -c "exec /opt/dmdbms/bin/disql SYSDBA/SYSDBA001 \`/tmp/schema.sql" | |
| 57 | +docker compose exec dm8 bash -c "exec /opt/dmdbms/bin/disql SYSDBA/SYSDBA001 \`/tmp/schema.sql" | |
| 58 | +exit | |
| 58 | 59 | ``` |
| 59 | 60 | |
| 60 | 61 | **注意**: `sql/dm/ruoyi-vue-pro-dm8.sql`文件编码必须为`GBK`或者`GBK`超集 | ... | ... |
sql/tools/convertor.py
| ... | ... | @@ -134,6 +134,14 @@ class Convertor(ABC): |
| 134 | 134 | """ |
| 135 | 135 | pass |
| 136 | 136 | |
| 137 | + def gen_dual(self) -> str: | |
| 138 | + """生成虚拟 dual 表 | |
| 139 | + | |
| 140 | + Returns: | |
| 141 | + str: 生成脚本, 默认返回空脚本, 表示当前数据库无需手工创建 | |
| 142 | + """ | |
| 143 | + return "" | |
| 144 | + | |
| 137 | 145 | @staticmethod |
| 138 | 146 | def inserts(table_name: str, script_content: str) -> Generator: |
| 139 | 147 | PREFIX = f"INSERT INTO `{table_name}`" |
| ... | ... | @@ -192,6 +200,17 @@ class Convertor(ABC): |
| 192 | 200 | ) |
| 193 | 201 | ) |
| 194 | 202 | |
| 203 | + dual = self.gen_dual() | |
| 204 | + if dual: | |
| 205 | + print( | |
| 206 | + f"""-- ---------------------------- | |
| 207 | +-- Table structure for dual | |
| 208 | +-- ---------------------------- | |
| 209 | +{dual} | |
| 210 | + | |
| 211 | +""" | |
| 212 | + ) | |
| 213 | + | |
| 195 | 214 | error_scripts = [] |
| 196 | 215 | for table_sql in self.table_script_list: |
| 197 | 216 | ddl = DDLParser(table_sql.replace("`", "")).run() |
| ... | ... | @@ -348,6 +367,12 @@ CREATE SEQUENCE {table_name}_seq |
| 348 | 367 | |
| 349 | 368 | return script |
| 350 | 369 | |
| 370 | + def gen_dual(self) -> str: | |
| 371 | + return """DROP TABLE IF EXISTS dual; | |
| 372 | +CREATE TABLE dual | |
| 373 | +( | |
| 374 | +);""" | |
| 375 | + | |
| 351 | 376 | |
| 352 | 377 | class OracleConvertor(Convertor): |
| 353 | 378 | def __init__(self, src): |
| ... | ... | @@ -605,6 +630,22 @@ GO |
| 605 | 630 | |
| 606 | 631 | return script |
| 607 | 632 | |
| 633 | + def gen_dual(self) -> str: | |
| 634 | + return """DROP TABLE IF EXISTS dual | |
| 635 | +GO | |
| 636 | + | |
| 637 | +CREATE TABLE dual | |
| 638 | +( | |
| 639 | + id int NULL | |
| 640 | +) | |
| 641 | +GO | |
| 642 | + | |
| 643 | +EXEC sp_addextendedproperty | |
| 644 | + 'MS_Description', N'数据库连接的表', | |
| 645 | + 'SCHEMA', N'dbo', | |
| 646 | + 'TABLE', N'dual' | |
| 647 | +GO""" | |
| 648 | + | |
| 608 | 649 | |
| 609 | 650 | class DM8Convertor(Convertor): |
| 610 | 651 | def __init__(self, src): | ... | ... |
sql/tools/docker-compose.yaml
| ... | ... | @@ -91,4 +91,4 @@ services: |
| 91 | 91 | volumes: |
| 92 | 92 | - dm8:/opt/dmdbms/data |
| 93 | 93 | - ../dm/ruoyi-vue-pro-dm8.sql:/tmp/schema.sql:ro |
| 94 | - # docker compose exec -i dm8 /bin/bash -c "exec /opt/dmdbms/bin/disql SYSDBA/SYSDBA001 \`/tmp/schema.sql" | |
| 94 | + # docker compose exec dm8 bash -c "exec /opt/dmdbms/bin/disql SYSDBA/SYSDBA001 \`/tmp/schema.sql" | ... | ... |