Basic Knowledge For Using Flyway
source link: https://blog.knoldus.com/basic-knowledge-for-using-flyway/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
In this blog I’m going to talk about integrating Flyway in your Spring Boot application. It is a migrating library that automates and keeps track of database changes, it’s basically version control for your database.
[1]
How Flyway works
In order to use Flyway you need to add the dependency to your pom.xml or build.gradle file. For maven use the following dependency.
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.0.1</version>
</dependency>
For Gradle use the following dependency.
compile group: 'org.flywaydb', name: 'flyway-core', version: '7.0.1'
You then need to create a directory called db and another directory called migration which is the default location for migration script files. Create sql files with names following the format of a capital V followed by the version number followed by two underscores followed by the file name.
[2]
Finally you need to add the following lines to your application.properties file. Make sure not to modify you sql files. If you need to modify them add a new version or if you really want to modify the files drop the database and recreate it.
spring.jpa.hibernate.ddl-auto = validate
spring.datasource.validationQuery= SELECT 1
spring.flyway.baseline-on-migrate=true
spring.flyway.locations=classpath:db/migration
[3]
Conclusion
By leveraging a database migration library such as Flyway, you can effectively streamline the software upgrade process and get rid of manual database upgrade steps from the implementation.
You also won’t need to precede each creates a table statement with a drop table statement to ensure that the database structure is recreated each time you start your application as this is not optimal.
References
[2] https://www.stackoverflow.com/questions/22819493/flyway-db-migration-folder
[3] https://www.dzone.com/articles/flyway-21-released-automatic
Happy blogging!
Recommend
-
21
本文大纲 flyway是什么 能帮助我们解决什么问题 springboot环境下使用flyway flyway的工...
-
19
分享一个最近在整Flyway时候碰到的一个问题,以及对应的一些解决方案。如果您还不知道Flyway,建议可以先看一下这篇文章 Spring Boot中使用Flyway来管理数据库版本
-
38
在项目迭代开发中,难免会有更新数据库 Schema 的情况,比如添加新表、在表中增加字段或者删除字段等,那么当我对数据库进行一系列操作后,如何快速地在其他同事的电脑上同步?如何在测试/生产服务器上快速同步?
-
12
Introduction In this article, I’m going to explain how Flyway works and how you can use it to run automated database schema migrations using incremental SQL migration script...
-
8
Flyway 是一款开源的数据库版本管理工具,它更倾向于规约优于配置的方式。Flyway 可以独立于应用实现管理并跟踪数据库变更,支持数据库版本自动升级,并且有一套默认的规约,不需要复杂的配置,Migrations 可以写成 SQL 脚本,也可以写在 Java 代码中,不仅支持...
-
7
Flyway 助力数据库脚本自动化管理攻略 发表于 2019-10-21 | 数据存储 | MySQL ...
-
10
Flyway 执行报错: 'user_variables_by_thread' 表没有SELECT权限问题 ...
-
4
7 Comments
-
7
In this guide, you will learn how toCreate a Spring Boot application with jOOQ supportGenerate jOOQ code using Testcontainers, Flyway and Maven PluginImplement basic database operation...
-
4
way0utwest/FlywayNorthwind Repository files navigation
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK