Automatically Generate Comprehensive Database Docs with Screw
This article introduces the Screw plugin, a lightweight tool that automates database table structure documentation across multiple databases, supports various output formats, and can be configured via custom Java code or a Maven plugin to streamline enterprise development workflows.
Introduction
In enterprise development, documenting database table structures is often time‑consuming. Many projects either lack documentation or maintain it manually, leading to errors and maintenance headaches. The Screw plugin helps automate this process.
Features of Screw
Lightweight, well‑designed, no need for heavyweight tools like PowerDesigner.
Supports multiple databases: MySQL, Oracle, SQL Server, and more.
Outputs documentation in MD, HTML, WORD formats.
Extensible with custom templates and styles.
Supported Database Types
MySQL
MariaDB
TIDB
Oracle
SQL Server
PostgreSQL
Cache DB
Dependencies
Example for MySQL 8:
<code><!--数据库文档核心依赖-->
<dependency>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-core</artifactId>
<version>1.0.2</version>
</dependency>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!-- mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</code>1. Generate Documentation via Custom Code Configuration
<code>@Test
public void shouldAnswerWithTrue() {
// Data source
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test");
hikariConfig.setUsername("root");
hikariConfig.setPassword("root");
// Enable table remarks
hikariConfig.addDataSourceProperty("useInformationSchema", "true");
hikariConfig.setMinimumIdle(2);
hikariConfig.setMaximumPoolSize(5);
DataSource dataSource = new HikariDataSource(hikariConfig);
// Engine config
EngineConfig engineConfig = EngineConfig.builder()
.fileOutputDir("/Users/lengleng")
.openOutputDir(true)
.fileType(EngineFileType.HTML)
.produceType(EngineTemplateType.freemarker).build();
// Ignore tables
ArrayList<String> ignoreTableName = new ArrayList<>();
ignoreTableName.add("test_user");
ignoreTableName.add("test_group");
// Prefix and suffix
ArrayList<String> ignorePrefix = new ArrayList<>();
ignorePrefix.add("test_");
ArrayList<String> ignoreSuffix = new ArrayList<>();
ignoreSuffix.add("_test");
ProcessConfig processConfig = ProcessConfig.builder()
.ignoreTableName(ignoreTableName)
.ignoreTablePrefix(ignorePrefix)
.ignoreTableSuffix(ignoreSuffix).build();
// Overall config
Configuration config = Configuration.builder()
.version("1.0.0")
.description("Database design documentation")
.dataSource(dataSource)
.engineConfig(engineConfig)
.produceConfig(processConfig).build();
// Execute
new DocumentationExecute(config).execute();
}
</code>2. Generate Documentation Using Maven Plugin
<code><build>
<plugins>
<plugin>
<groupId>cn.smallbun.screw</groupId>
<artifactId>screw-maven-plugin</artifactId>
<version>1.0.2</version>
<dependencies>
<!-- HikariCP -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
<!-- mysql driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
</dependencies>
<configuration>
<username>root</username>
<password>root</password>
<driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
<jdbcUrl>jdbc:mysql://127.0.0.1:3306/test</jdbcUrl>
<fileType>HTML</fileType>
<fileOutputDir>/Users/lengleng</fileOutputDir>
<openOutputDir>false</openOutputDir>
<produceType>freemarker</produceType>
<description>数据库文档生成</description>
<version>${project.version}</version>
<title>数据库文档</title>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</code>Reference
screw: https://gitee.com/leshalv/screw
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.