JAVAJAVASpringBoot+screw 生成数据库文档,堪称数据库界的Swagger
Yc
前言
最近发现公司的数据库越来越庞大了,生产竟然有上千张表。但是每个业务库都没有相应的数据库文档,开始其实打算手写文档但是表实在太多了,包括后期的运维开发也需要手动进行文档维护。为了不进行重复的CV操作所以借助这个宝藏工具screw(螺丝钉)一键生成数据库文档。
至于工具为什么叫螺丝钉,引用作者的话来讲摘自雷锋日记:虽然是细小的螺丝钉,是个细微的小齿轮,然而如果缺了它,那整个的机器就无法运转了,即使是一枚小螺丝钉没拧紧,一个小齿轮略有破损,也可能会使机器的运转发生故障。
特点
- 简洁、轻量、设计良好
 
- 多数据库支持
 
- 多种格式文档
 
- 灵活扩展
 
- 支持自定义模板
 
数据库支持
生成文档格式支持
文档截图
- markdown


 
使用方式
1、普通方式
普通方式是编写执行代码调用工具类进行文档生成
添加依赖,检查是否最新版本,连接地址-> 最新版本
1 2 3 4 5 6 7
   | 
  <dependency>     <groupId>cn.smallbun.screw</groupId> 	<artifactId>screw-core</artifactId> 	<version>1.0.5</version> </dependency>
 
  | 
 
编写代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
   | package com.yc.utils;
  import cn.smallbun.screw.core.Configuration; import cn.smallbun.screw.core.engine.EngineConfig; import cn.smallbun.screw.core.engine.EngineFileType; import cn.smallbun.screw.core.engine.EngineTemplateType; import cn.smallbun.screw.core.execute.DocumentationExecute; import cn.smallbun.screw.core.process.ProcessConfig; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import org.springframework.boot.test.context.SpringBootTest;
  import javax.sql.DataSource; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @SpringBootTest public class GenerateDataDoc {     
 
      static void documentGeneration() {                  HikariConfig hikariConfig = new HikariConfig();         hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");         hikariConfig.setJdbcUrl("jdbc:mysql://localhost:3306/platform?characterEncoding=UTF-8");         hikariConfig.setUsername("root");         hikariConfig.setPassword("root");                  hikariConfig.addDataSourceProperty("useInformationSchema", "true");         hikariConfig.setMinimumIdle(2);         hikariConfig.setMaximumPoolSize(5);         DataSource dataSource = new HikariDataSource(hikariConfig);
                   EngineConfig engineConfig = EngineConfig.builder()                                  .fileOutputDir("D:\\dataBaseDoc\\")                                  .openOutputDir(true)                                  .fileType(EngineFileType.MD)                                  .produceType(EngineTemplateType.freemarker)                                  .fileName("AYN-platform").build();
                   ArrayList<String> ignoreTableName = new ArrayList<>();         ignoreTableName.add("test_user");         ignoreTableName.add("test_group");                  ArrayList<String> ignorePrefix = new ArrayList<>();         ignorePrefix.add("test_");                  ArrayList<String> ignoreSuffix = new ArrayList<>();         ignoreSuffix.add("_test");         ProcessConfig processConfig = ProcessConfig.builder()                                                   .designatedTableName(new ArrayList<>())                                  .designatedTablePrefix(new ArrayList<>())                                  .designatedTableSuffix(new ArrayList<>())                                  .ignoreTableName(ignoreTableName)                                  .ignoreTablePrefix(ignorePrefix)                                  .ignoreTableSuffix(ignoreSuffix).build();                  DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");         String nowDate = LocalDateTime.now().format(df);         Configuration config = Configuration.builder()                                  .version("1.0.0")                                  .description("platform数据库设计文档生成-" + nowDate)                                  .dataSource(dataSource)                                  .engineConfig(engineConfig)                                  .produceConfig(processConfig)                 .build();                  new DocumentationExecute(config).execute();     }
  }
 
   | 
 
2、Maven插件方式
使用Maven插件执行生成数据库文档
pom文件配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
   | <build>     <plugins>         <plugin>             <groupId>cn.smallbun.screw</groupId>             <artifactId>screw-maven-plugin</artifactId>             <version>${lastVersion}</version>             <dependencies>                                  <dependency>                     <groupId>com.zaxxer</groupId>                     <artifactId>HikariCP</artifactId>                     <version>3.4.5</version>                 </dependency>                                  <dependency>                     <groupId>mysql</groupId>                     <artifactId>mysql-connector-java</artifactId>                     <version>8.0.20</version>                 </dependency>             </dependencies>             <configuration>                                  <username>root</username>                                  <password>password</password>                                  <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>                                  <jdbcUrl>jdbc:mysql://127.0.0.1:3306/xxxx</jdbcUrl>                                  <fileType>HTML</fileType>                                  <openOutputDir>false</openOutputDir>                                  <produceType>freemarker</produceType>                                  <fileName>测试文档名称</fileName>                                  <description>数据库文档生成</description>                                  <version>${project.version}</version>                                  <title>数据库文档</title>             </configuration>             <executions>                 <execution>                     <phase>compile</phase>                     <goals>                         <goal>run</goal>                     </goals>                 </execution>             </executions>         </plugin>     </plugins> </build>
   | 
 
配置完成后在 maven project->screw双击执行

连接
文档工具 screw https://github.com/pingfangushi/screw