SpringBoot整合flyway,实现自动创建表

spring boot - v: 2.1.3.RELEASE

MySQL - v:5.7

JDK -v : 11

 

项目结构:

SpringBoot整合flyway,实现自动创建表_第1张图片

 

pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.3.RELEASE
         
    
    com.example
    demo-flywat
    0.0.1-SNAPSHOT
    demo-flywat
    Demo project for Spring Boot
    
        11
    
    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-data-jpa
        

        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.flywaydb
            flyway-core
            5.2.4
        

        
            mysql
            mysql-connector-java
            runtime
        

    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


application.yml

server:
    port: 1234
spring:
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: root
        url: jdbc:mysql://localhost:3306/demo?serverTimezone=UTC&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
        username: root
    flyway:
        baseline-on-migrate: true
        enabled: true
        locations: classpath:/db/migration

必须在resource下新建这个名称的文件夹,sql脚本的命名规则 : V${版本号}__${描述}.sql

启动后,不仅会把你脚本的表创建好,同时还会创建{flyway_schema_history}表,记录的就是操作日志,之后初始化执行一次

 如果启动过程中,报错 .idea中flyway-core.xml提示Message: 前言中不允许有内容,修改一下即可

SpringBoot整合flyway,实现自动创建表_第2张图片

你可能感兴趣的:(java,SpringBoot,mysql,springboot,mysql,flyway,flyway自动创建表)