Use of flyway

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.