数据库迁移、版本控制管理工具-Flyway

随着项目不断的增大,数据库也需要不断的扩充,加表加字段,(每一次的增加称作一次DB的迁移migration)你是否还在用着最原始的方式, 用文件管理每次的SQL升级脚本,加了哪些字段,加了那些表,现在可以用数据库版本控制工具搞定了。

整合步骤:

1.添加依赖https://flywaydb.org

2.编写java类

public static void main(String[] args) {
        // Create the Flyway instance
        Flyway flyway = new Flyway();

        // Point it to the database
        flyway.setDataSource("jdbc:h2:file:./target/foobar", "sa", null);

        // Start the migration
        flyway.migrate();
    }
3.创建 迁移目录src/main/resources/db/migration.

编写sql src/main/resources/db/migration/V1__Create_person_table.sql:

create table PERSON (
    ID int not null,
    NAME varchar(100) not null
);
4.运行java类

猜你喜欢

转载自blog.csdn.net/yangyang2183/article/details/51783089