• Flyway数据表迁移框架的使用


    1. 概述

    Flyway是一个根据表结构快速生成数据表的工具,类似于Hibernate的自动生成表的特性。

    官网: https://flywaydb.org

    2. Maven配置

    直接贴出配置

    <build>
        <finalName>adminTemplate</finalName>
        <plugins>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>5.2.4</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.39</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <user>developer</user>
                    <password>developer</password>
                    <url>jdbc:mysql://localhost:3306/demo?useSSL=true</url>
                    <locations>filesystem:src/main/sql</locations>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    其中locations配置项的值是存放sql文件的目录。

    3. SQL文件规范

    文件名由以下部分组成:

    前缀:V用于版本化(可配置), U用于撤消(可配置)和R用于可重复迁移(可配置)
    版本:带点或下划线的版本可以根据需要分开多个部分(不适用于可重复的迁移)
    分隔符 : __ (两个下划线)(可配置)
    描述:下划线或空格分隔单词
    后缀:.sql(配置)

    例如: V1__admin_info.sql

    use demo;
    
    drop table if exists admin_info;
    create table admin_info (
      id  bigint not null auto_increment comment '主键',
      name varchar(100) not null comment '姓名',
      primary key (id)
    ) engine=innodb charset=utf8mb4 comment='管理员';
    

    4. 命令

    常用的命令有三个:

    1. mvn flyway:clean 清空库(删除库中的所有表)
    2. mvn flyway:info 打印出库的表
    3. mvn flyway:migrate 将SQL文件生成(迁移)成表

    5. 总结

    flyway是一个非常好用的表结构管理工具,配合MyBatisGenerator使用很方便。

  • 相关阅读:
    网络操作系统(WebOS)网站
    各种邀请码:Evernote 3.0,wallop,qolin等等
    urlrewrite 的使用方法
    一次事故处理情况(mysql 相关)
    开始使用ubuntu办公
    Q邻:网络桌面
    数据库表字段命名规范
    计算机专业导学
    详解GCC的下载和安装
    三层的解释
  • 原文地址:https://www.cnblogs.com/wuqinglong/p/10560657.html
Copyright © 2020-2023  润新知