In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how SpringBoot integrates liquibase and liquibase to generate initialization scripts. It is very detailed and has a certain reference value. Interested friends must read it!
one。 SpringBoot integrated liquibase
Project integration liquibase role
Version control of database table fields
Initialize database tables and data when the project is initialized and deployed
1. Import pom dependencies
Org.liquibase liquibase-core
two。 Configure application.yml file, specify master.xml
Spring: liquibase: change-log: classpath:liquibase/master.xml # specifies the location of the master.xml file
Different spring versions are configured differently.
For more information, see the configuration in the source code LiquibaseProperties
3. The new master.xml file is used to specify the location of the database initialization script in the
4. Put the database table initial script init_table.xml and the data initial script init_data.xml into the project directory
Scripts can be generated automatically either by hand or by liquibase
The startup project will create tables and data in the database if it is run for the first time
Later, if there are new tables or fields in the script to start the project, the build will also be created automatically.
two。 Liquibase generates initialization scripts for database tables and data
Liquibase has two ways to generate initialization scripts
Method 1: download the liquibase package on the official website and use the native command line instructions to generate
Download the liquibase package, extract it, and copy a copy of the mysql connection jar package to this directory
Go to the decompression directory and execute the following
Generate table structure files according to database
/ liquibase-- driver=com.mysql.cj.jdbc.Driver-- classpath=mysql-connector-java-8.0.17.jar-- changeLogFile=./init-data.xml-- url= "jdbc:mysql://192.168.0.162:3306/hello_world"-- username=root-- password=123456-- diffTypes=data generateChangeLog
Generate initial data files based on the database
. / liquibase-driver=com.mysql.cj.jdbc.Driver-classpath=mysql-connector-java-8.0.17.jar-changeLogFile=./init-table.xml-url= "jdbc:mysql://192.168.0.162:3306/hello_world"-username=root-password=123456 generateChangeLog
Database driver depends on database
-driver=com.mysql.cj.jdbc.Driver
Mysql connection
-classpath=mysql-connector-java-8.0.17.jar
Custom generated initialization script file name
-changeLogFile=./init-data.xml
Database connection address
-url= "jdbc:mysql://192.168.0.162:3306/hello_world"
Database username and password
-username=root
-password=123456
This configuration is required for generating initialization table data, but not for generating table structure.
-diffTypes=data
Method 2: use the Maven plug-in
Org.liquibase liquibase-maven-plugin 3.4.2 ${basedir} / src/main/resources/liquibase/change_log/changelog.xml ${basedir} / src/main/resources/liquibase/change_log/changelog.xml com.mysql.jdbc.Driver jdbc:mysql:// 192.168.0.30:3306/school qj 123456 UTF-8 true false tables Views, columns, indexs,foreignkeys, primarykeys, uniqueconstraints, data
If you are just generating a database table script, annotate the above diffTypes or remove the data from it
If you just generate a data script, only data is left.
If you want to generate datasheet scripts and data scripts into one file, keep all the difftypes contents above
After installing the maven plug-in, you can see the instructions in the maven plug-in as shown below. Click to generate a script file.
The generation script is as follows
The above is all the content of the article "how SpringBoot integrates liquibase and liquibase generation initialization script". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.