还在手动整理数据库文档?试试这个工具

运维 数据库运维
在企业级开发中、我们经常会有编写数据库表结构文档的时间付出,从业以来,待过几家企业,关于数据库表结构文档状态:要么没有、要么有、但都是手写、后期运维开发,需要手动进行维护到文档中,很是繁琐。

 [[335513]]

 

简介

在企业级开发中、我们经常会有编写数据库表结构文档的时间付出,从业以来,待过几家企业,关于数据库表结构文档状态:要么没有、要么有、但都是手写、后期运维开发,需要手动进行维护到文档中,很是繁琐、如果忘记一次维护、就会给以后工作造成很多困扰、无形中制造了很多坑留给自己和后人,于是需要一个插件工具screw[1]来维护。

screw 特点

  • 简洁、轻量、设计良好。不需要 powerdesigner 这种重量的建模工具
  • 多数据库支持 。支持市面常见的数据库类型 MySQL、Oracle、SqlServer
  • 多种格式文档。支持 MD、HTML、WORD 格式
  • 灵活扩展。支持用户自定义模板和展示样式

支持数据库类型

  • [✔️] MySQL
  • [✔️] MariaDB
  • [✔️] TIDB
  • [✔️] Oracle
  • [✔️] SqlServer
  • [✔️] PostgreSQL
  • [✔️] Cache DB

依赖

这里以 mysql8 数据库为例子

  1. <!--数据库文档核心依赖--> 
  2.  <dependency> 
  3.      <groupId>cn.smallbun.screw</groupId> 
  4.      <artifactId>screw-core</artifactId> 
  5.      <version>1.0.2</version> 
  6.  </dependency> 
  7.  <!-- HikariCP --> 
  8.  <dependency> 
  9.      <groupId>com.zaxxer</groupId> 
  10.      <artifactId>HikariCP</artifactId> 
  11.      <version>3.4.5</version> 
  12.  </dependency> 
  13.  <!--mysql driver--> 
  14.  <dependency> 
  15.      <groupId>mysql</groupId> 
  16.      <artifactId>mysql-connector-java</artifactId> 
  17.      <version>8.0.20</version> 
  18.  </dependency> 

1. 通过自定义代码配置文档生成

 

  1. @Test 
  2. public void shouldAnswerWithTrue() { 
  3.     //数据源 
  4.     HikariConfig hikariConfig = new HikariConfig(); 
  5.     hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver"); 
  6.     hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test"); 
  7.     hikariConfig.setUsername("root"); 
  8.     hikariConfig.setPassword("root"); 
  9.     //设置可以获取tables remarks信息 
  10.     hikariConfig.addDataSourceProperty("useInformationSchema""true"); 
  11.     hikariConfig.setMinimumIdle(2); 
  12.     hikariConfig.setMaximumPoolSize(5); 
  13.     DataSource dataSource = new HikariDataSource(hikariConfig); 
  14.     //生成配置 
  15.     EngineConfig engineConfig = EngineConfig.builder() 
  16.             //生成文件路径 
  17.             .fileOutputDir("/Users/lengleng"
  18.             //打开目录 
  19.             .openOutputDir(true
  20.             //文件类型 
  21.             .fileType(EngineFileType.HTML) 
  22.             //生成模板实现 
  23.             .produceType(EngineTemplateType.freemarker).build(); 
  24.  
  25.     //忽略表 
  26.     ArrayList<String> ignoreTableName = new ArrayList<>(); 
  27.     ignoreTableName.add("test_user"); 
  28.     ignoreTableName.add("test_group"); 
  29.     //忽略表前缀 
  30.     ArrayList<String> ignorePrefix = new ArrayList<>(); 
  31.     ignorePrefix.add("test_"); 
  32.     //忽略表后缀 
  33.     ArrayList<String> ignoreSuffix = new ArrayList<>(); 
  34.     ignoreSuffix.add("_test"); 
  35.     ProcessConfig processConfig = ProcessConfig.builder() 
  36.             //忽略表名 
  37.             .ignoreTableName(ignoreTableName) 
  38.             //忽略表前缀 
  39.             .ignoreTablePrefix(ignorePrefix) 
  40.             //忽略表后缀 
  41.             .ignoreTableSuffix(ignoreSuffix).build(); 
  42.     //配置 
  43.     Configuration config = Configuration.builder() 
  44.             //版本 
  45.             .version("1.0.0"
  46.             //描述 
  47.             .description("数据库设计文档生成"
  48.             //数据源 
  49.             .dataSource(dataSource) 
  50.             //生成配置 
  51.             .engineConfig(engineConfig) 
  52.             //生成配置 
  53.             .produceConfig(processConfig).build(); 
  54.     //执行生成 
  55.     new DocumentationExecute(config).execute(); 

2. 通过插件的形式生成文档

  1. <build> 
  2.     <plugins> 
  3.         <plugin> 
  4.             <groupId>cn.smallbun.screw</groupId> 
  5.             <artifactId>screw-maven-plugin</artifactId> 
  6.             <version>1.0.2</version> 
  7.             <dependencies> 
  8.                 <!-- HikariCP --> 
  9.                 <dependency> 
  10.                     <groupId>com.zaxxer</groupId> 
  11.                     <artifactId>HikariCP</artifactId> 
  12.                     <version>3.4.5</version> 
  13.                 </dependency> 
  14.                 <!--mysql driver--> 
  15.                 <dependency> 
  16.                     <groupId>mysql</groupId> 
  17.                     <artifactId>mysql-connector-java</artifactId> 
  18.                     <version>8.0.20</version> 
  19.                 </dependency> 
  20.             </dependencies> 
  21.             <configuration> 
  22.                 <!--username--> 
  23.                 <username>root</username> 
  24.                 <!--password--> 
  25.                 <password>root</password
  26.                 <!--driver--> 
  27.                 <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName> 
  28.                 <!--jdbc url--> 
  29.                 <jdbcUrl>jdbc:mysql://127.0.0.1:3306/test</jdbcUrl> 
  30.                 <!--生成文件类型--> 
  31.                 <fileType>HTML</fileType> 
  32.                 <!--文件输出目录--> 
  33.                 <fileOutputDir>/Users/lengleng</fileOutputDir> 
  34.                 <!--打开文件输出目录--> 
  35.                 <openOutputDir>false</openOutputDir> 
  36.                 <!--生成模板--> 
  37.                 <produceType>freemarker</produceType> 
  38.                 <!--描述--> 
  39.                 <description>数据库文档生成</description> 
  40.                 <!--版本--> 
  41.                 <version>${project.version}</version> 
  42.                 <!--标题--> 
  43.                 <title>数据库文档</title> 
  44.             </configuration> 
  45.             <executions> 
  46.                 <execution> 
  47.                     <phase>compile</phase> 
  48.                     <goals> 
  49.                         <goal>run</goal> 
  50.                     </goals> 
  51.                 </execution> 
  52.             </executions> 
  53.         </plugin> 
  54.     </plugins> 
  55. </build> 

 

责任编辑:华轩 来源: JAVA架构日记
相关推荐

2020-12-21 09:40:16

数据库工具技术

2023-04-18 18:22:31

开源工具数据库

2023-12-10 13:58:17

2020-12-24 10:20:43

文档工具语言

2019-07-12 08:37:22

DockerNginx程序员

2011-03-07 17:02:07

2019-04-08 14:58:36

数据库SQL数据类型

2023-03-29 07:02:46

开源项目工具

2022-01-26 07:18:57

工具GoGo 项目

2022-02-09 07:44:30

Go源码工具

2011-05-19 13:25:12

Oracle数据库碎片

2019-12-19 16:10:36

前端开发刷新页面自动刷新

2011-05-13 13:54:02

数据库文档数据库

2019-11-06 14:13:55

开发者技能工具

2021-06-24 16:18:03

Cube.js数据分析开源

2023-02-01 10:40:01

2011-08-22 16:08:46

IOS开发数据库

2011-03-28 15:44:45

惠普数据库Oracle数据库

2010-09-30 10:59:32

卸载DB2数据库

2010-05-04 14:20:47

Oracle创建数据库
点赞
收藏

51CTO技术栈公众号