mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 18:49:06 +08:00 
			
		
		
		
	Merge branch 'feature/db' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into master-jdk17
This commit is contained in:
		
							
								
								
									
										4723
									
								
								sql/kingbase/ruoyi-vue-pro.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4723
									
								
								sql/kingbase/ruoyi-vue-pro.sql
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -48,7 +48,7 @@ docker compose exec sqlserver bash /tmp/create_schema.sh | ||||
|  | ||||
| ```Bash | ||||
| docker load -i dm8_20230808_rev197096_x86_rh6_64_single.tar | ||||
| ```` | ||||
| ``` | ||||
|  | ||||
| ③ 在项目 `sql/tools` 目录下运行: | ||||
|  | ||||
| @ -63,6 +63,29 @@ exit | ||||
|  | ||||
| 暂不支持 MacBook Apple Silicon,因为 达梦 官方没有提供 Apple Silicon 版本的 Docker 镜像。 | ||||
|  | ||||
| ### 1.6 KingbaseES 人大金仓 | ||||
|  | ||||
| ① 下载人大金仓 Docker 镜像: | ||||
|  | ||||
| > x86_64版本: https://kingbase.oss-cn-beijing.aliyuncs.com/KESV8R3/V009R001C001B0025-安装包-docker/x86_64/kdb_x86_64_V009R001C001B0025.tar  | ||||
| > aarch64版本:https://kingbase.oss-cn-beijing.aliyuncs.com/KESV8R3/V009R001C001B0025-安装包-docker/aarch64/kdb_aarch64_V009R001C001B0025.tar | ||||
|  | ||||
| ② 加载镜像文件,在镜像 tar 文件所在目录运行: | ||||
|  | ||||
| ```Bash | ||||
| docker load -i x86_64/kdb_x86_64_V009R001C001B0025.tar | ||||
| ``` | ||||
|  | ||||
| ③ 在项目 `sql/tools` 目录下运行: | ||||
|  | ||||
| ```Bash | ||||
| docker compose up -d kingbase | ||||
| # 注意:启动完 dm 后,需要手动再执行如下命令,因为 dm 不支持初始化脚本 | ||||
| docker compose exec kingbase bash -c "exec ksql -Uroot -d test -f /tmp/schema.sql" | ||||
| ``` | ||||
|  | ||||
| **注意**: MyBatis, MyBatis Plus 目前不兼容人大金仓,推荐直接使用PostgreSQL JDBC 驱动,已经 url 配置方式连接数据库。 | ||||
|  | ||||
| ## 1.X 容器的销毁重建 | ||||
|  | ||||
| 开发测试过程中,有时候需要创建全新干净的数据库。由于测试数据 Docker 容器采用数据卷 Volume 挂载数据库实例的数据目录,因此销毁数据需要停止容器后,删除数据卷,然后再重新创建容器。 | ||||
| @ -78,7 +101,7 @@ docker volume rm ruoyi-vue-pro_postgres | ||||
|  | ||||
| ### 2.1 实现原理 | ||||
|  | ||||
| 通过读取 MySQL 的 `sql/mysql/ruoyi-vue-pro.sql` 数据库文件,转换成 Oracle、PostgreSQL、SQL Server 等数据库的脚本。 | ||||
| 通过读取 MySQL 的 `sql/mysql/ruoyi-vue-pro.sql` 数据库文件,转换成 Oracle、PostgreSQL、SQL Server、达梦、人大金仓 等数据库的脚本。 | ||||
|  | ||||
| ### 2.2 使用方法 | ||||
|  | ||||
| @ -89,7 +112,7 @@ pip install simple-ddl-parser | ||||
| # pip3 install simple-ddl-parser | ||||
| ``` | ||||
|  | ||||
| ② 执行如下命令打印生成 postgres 的脚本内容,其他可选参数有:`oracle`、`sqlserver`、`dm8`: | ||||
| ② 执行如下命令打印生成 postgres 的脚本内容,其他可选参数有:`oracle`、`sqlserver`、`dm8`、`kingbase`: | ||||
|  | ||||
| ```Bash | ||||
| python3 convertor.py postgres | ||||
|  | ||||
| @ -768,13 +768,49 @@ SET IDENTITY_INSERT {table_name.lower()} OFF; | ||||
|         return script | ||||
|  | ||||
|  | ||||
| class KingbaseConvertor(PostgreSQLConvertor): | ||||
|     def __init__(self, src): | ||||
|         super().__init__(src) | ||||
|         self.db_type = "Kingbase" | ||||
|  | ||||
|     def gen_create(self, ddl: Dict) -> str: | ||||
|         """生成 create""" | ||||
|  | ||||
|         def _generate_column(col): | ||||
|             name = col["name"].lower() | ||||
|             if name == "deleted": | ||||
|                 return "deleted int2 NOT NULL DEFAULT 0" | ||||
|  | ||||
|             type = col["type"].lower() | ||||
|             full_type = self.translate_type(type, col["size"]) | ||||
|             nullable = "NULL" if col["nullable"] else "NOT NULL" | ||||
|             default = f"DEFAULT {col['default']}" if col["default"] is not None else "" | ||||
|             return f"{name} {full_type} {nullable} {default}" | ||||
|  | ||||
|         table_name = ddl["table_name"].lower() | ||||
|         columns = [f"{_generate_column(col).strip()}" for col in ddl["columns"]] | ||||
|         filed_def_list = ",\n  ".join(columns) | ||||
|         script = f"""-- ---------------------------- | ||||
| -- Table structure for {table_name} | ||||
| -- ---------------------------- | ||||
| DROP TABLE IF EXISTS {table_name}; | ||||
| CREATE TABLE {table_name} ( | ||||
|     {filed_def_list} | ||||
| );""" | ||||
|  | ||||
|         # Kingbase INSERT '' 不能通过 NOT NULL 校验 | ||||
|         script = script.replace("NOT NULL DEFAULT ''", "NULL DEFAULT ''") | ||||
|  | ||||
|         return script | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     parser = argparse.ArgumentParser(description="芋道系统数据库转换工具") | ||||
|     parser.add_argument( | ||||
|         "type", | ||||
|         type=str, | ||||
|         help="目标数据库类型", | ||||
|         choices=["postgres", "oracle", "sqlserver", "dm8"], | ||||
|         choices=["postgres", "oracle", "sqlserver", "dm8", "kingbase"], | ||||
|     ) | ||||
|     args = parser.parse_args() | ||||
|  | ||||
| @ -788,6 +824,8 @@ def main(): | ||||
|         convertor = SQLServerConvertor(sql_file) | ||||
|     elif args.type == "dm8": | ||||
|         convertor = DM8Convertor(sql_file) | ||||
|     elif args.type == "kingbase": | ||||
|         convertor = KingbaseConvertor(sql_file) | ||||
|     else: | ||||
|         raise NotImplementedError(f"不支持目标数据库类型: {args.type}") | ||||
|  | ||||
|  | ||||
| @ -5,6 +5,7 @@ volumes: | ||||
|     postgres: { } | ||||
|     sqlserver: { } | ||||
|     dm8: { } | ||||
|     kingbase: { } | ||||
|  | ||||
| services: | ||||
|     mysql: | ||||
| @ -92,3 +93,19 @@ services: | ||||
|             - dm8:/opt/dmdbms/data | ||||
|             - ../dm/ruoyi-vue-pro-dm8.sql:/tmp/schema.sql:ro | ||||
|             # docker compose exec dm8 bash -c "exec /opt/dmdbms/bin/disql SYSDBA/SYSDBA001 \`/tmp/schema.sql" | ||||
|  | ||||
|     kingbase: | ||||
|         # x86_64: https://kingbase.oss-cn-beijing.aliyuncs.com/KESV8R3/V009R001C001B0025-安装包-docker/x86_64/kdb_x86_64_V009R001C001B0025.tar | ||||
|         # aarch64: https://kingbase.oss-cn-beijing.aliyuncs.com/KESV8R3/V009R001C001B0025-安装包-docker/aarch64/kdb_aarch64_V009R001C001B0025.tar | ||||
|         # docker load -i kdb_x86_64_V009R001C001B0025.tar | ||||
|         image: kingbase_v009r001c001b0025_single_x86:v1 | ||||
|         restart: unless-stopped | ||||
|         environment: | ||||
|             DB_USER: root | ||||
|             DB_PASSWORD: 123456 | ||||
|         ports: | ||||
|             - "54321:54321" | ||||
|         volumes: | ||||
|             - kingbase:/home/kingbase/userdata/ | ||||
|             - ../kingbase/ruoyi-vue-pro.sql:/tmp/schema.sql:ro | ||||
|             # docker compose exec kingbase bash -c "exec ksql -Uroot -d test -f /tmp/schema.sql" | ||||
| @ -52,6 +52,7 @@ spring: | ||||
|           #          url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 | ||||
|           #          url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true;useUnicode=true;characterEncoding=utf-8 # SQLServer 连接的示例 | ||||
|           #          url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 | ||||
|           #          url: jdbc:postgresql://127.0.0.1:54321/test  # KingbaseES 人大金仓 连接的示例, MyBatis不兼容官方驱动 | ||||
|           username: root | ||||
|           password: 123456 | ||||
|         #          username: sa # SQL Server 连接的示例 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV