In frequent engineering practices, server programs and databases are constantly updated. If the server and database deployment are inconsistent, frequent problems may occur. To solve this problem, one feasible solution is to update the database with the server version, and flyway is a solution. 1. Manage database updates. 2. The method is directly in ja
In frequent engineering practices, server programs and databases are constantly updated. If the server and database deployment are inconsistent, frequent problems may occur. To solve this problem, one feasible solution is to update the database with the server version, and flyway is a solution. 1. Manage database updates. 2. The method is directly in ja
In frequent engineering practices, server programs and databases are constantly updated. If the server and database deployment are inconsistent, frequent problems may occur. To solve this problem, one feasible solution is to update the database with the server version, and flyway is a solution.
I. Purpose
Manage database updates.
Ii. Method
Embed SQL scripts directly in the java project. When the project is re-deployed, the database is automatically updated to ensure that the database and code are synchronized, avoiding the disadvantages of manual database updates.
Iii. Principles
A table schema_version is created in the database. The last record of the table is the current database version.
Step 4:
1. Add the following to the pom file:
Org. flywaydb
Flyway-core
3.2.1
2. Add in dispatcher-servlet.xml
At the same time, let other database operation beans rely on the flyway bean to avoid database operations before the database is upgraded.
Class = "org. springframework. orm. hibernate4.LocalSessionFactoryBean" depends-on = "flyway">
3. Create a database script upgrade directory under resources. Note the script naming method.
5. Note
1. flyway does not support rollback. if you add a field and delete it again, you can only write a script for V2_6_0_1 _ Delete_new_like_Column. SQL.
2. Once flyway is used, do not manually modify the database, and do not delete data in schema_version.