Original statement: This article is original by the author (Magic good), which can be used as learning reference reprint, but the source should be indicated. It is forbidden to use it in commercial and other ways without permission, otherwise you will bear the consequences!
Preface overview
With the increasing complexity of development scenarios, there are more and more database tables that store data and are constantly updated. Sometimes development teams need to cooperate to develop business. Generally, they need to sort out the latest database design documents. However, the time cost of manually maintaining documents may be very high and prone to errors. Once an error occurs, it will bury many holes in the follow-up, and the consequences are unimaginable. If you can generate the latest database documents at any time through tools, you can greatly save work efficiency.
In order to solve the above problems, this paper will recommend a domestic database design document design plug-in tool - screen.
SCREW
brief introduction
Screen (screw) is an open source, concise and easy-to-use database table structure document generation tool, developed by Chinese people and suitable for Chinese business scenarios.
The meaning of the name "screw" is taken from Lei Feng's Diary: although it is a small screw, it is a small pinion. However, if it is missing, the whole machine will not be able to run. If it is missing, even if a small screw is not tightened and a small gear is slightly damaged, the operation of the machine will fail.
Project open source address: https://github.com/pingfangushi/screw
characteristic
Screen has the following features:
- Compared with the heavyweight of powerdesigner, screen is more concise, lightweight and well designed.
- It supports a variety of databases. At present, it supports common databases in the market: MySQL, Oracle, SqlServer, PostgreSQL, etc.
- It supports documents in various formats. At present, it supports the generation of documents in word, html and markdown formats.
- It supports flexible expansion, and can use the pojo generation function to directly generate the corresponding java pojo objects according to the database.
- Supports user-defined templates, and can configure user-defined template styles through simple attributes.
Generate documents using sketch
Environmental preparation
- Install database: MySQL 5.7 and create business table
- Build a simple Maven project
Operation steps
Database table
Prepare the tables that need to generate the database, except sys_config generates documents for all others.
Introduce dependent components
<!--screw assembly--> <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>
Write code
public class DataToDocument { @Test public void dataDocMaker() { // Configure data source HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver"); hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/crawler?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8"); hikariConfig.setUsername("root"); hikariConfig.setPassword("root"); // Get the comment information of the fields in the table hikariConfig.addDataSourceProperty("useInformationSchema", "true"); hikariConfig.setMinimumIdle(2); hikariConfig.setMaximumPoolSize(5); DataSource dataSource = new HikariDataSource(hikariConfig); // Configuration needs to ignore tables that do not generate documents ArrayList<String> ignoreTableName = new ArrayList<>(); ignoreTableName.add("sys_config"); // Configuration needs to ignore tables with the following prefixes ArrayList<String> ignorePrefix = new ArrayList<>(); ignorePrefix.add("sys_"); // Configuration needs to ignore tables with the following suffixes ArrayList<String> ignoreSuffix = new ArrayList<>(); ignoreSuffix.add("_config"); // Configure ignore rule into process ProcessConfig processConfig = ProcessConfig.builder() .ignoreTableName(ignoreTableName) .ignoreTablePrefix(ignorePrefix) .ignoreTableSuffix(ignoreSuffix).build(); // Document property generation configuration EngineConfig engineConfig = EngineConfig.builder() // Document generation path .fileOutputDir("src/main/resources/temp") // Automatically open directory after document generation .openOutputDir(true) // file type .fileType(EngineFileType.WORD) // Generate template implementation .produceType(EngineTemplateType.freemarker).build(); // Document information configuration Configuration config = Configuration.builder() // Set document version .version("1.0.0") // Setting description .description("Database design document description") // set up data sources .dataSource(dataSource) .produceConfig(processConfig) .engineConfig(engineConfig).build(); // Finally, execute the build new DocumentationExecute(config).execute(); } }
Generate results
After the document is generated successfully, the document directory will be opened automatically.
After opening the document, you can see the complete display of each field and its related attributes in the database.
summary
If you often need to use database design documents in your work, you can use the screen tool to improve work efficiency and reduce the time cost of maintaining documents.
The overall experience of screen is very convenient and quick to start. Interested students can try it.