鉴于我必须自己编写迁移脚本,因此Flyway可提供什么价值? [英] Given I have to write the migration scripts myself, what value does Flyway provide?

查看:141
本文介绍了鉴于我必须自己编写迁移脚本,因此Flyway可提供什么价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的情况下,我使用生成SQL语句的工具来包含所有数据库init / create语句。 Flyway如何提供超出我的工具所能提供的价值?为什么我要编写手工编码的迁移脚本以使用Flyway?

In my situation I use a tool that generates SQL statements to contain all database init/create statements. How does Flyway provide value beyond what my tool provides? Why should I care to write hand-coded migration scripts to use Flyway?

推荐答案

上面的问题混合了应该分开的两件事:将数据库创建的概念与迁移的概念混合在一起。

The question above mixes two things that should be separate: the concept of database creation mixed with the concept of migration.

数据库创建

给出一个完整的数据库和一个空数据库,您可以使用许多工具来生成重新创建没有内容的完整数据库所需的脚本。用Flyway术语来说,您只是创建基线。这根本不是迁移的概念。当然,在给定V2.0数据库的情况下,您可以看到任何V1.0数据库,将其删除并安装V2.0数据库,但是现在您丢失了数据。

Given a complete database and an empty database, you can use many tools to generate the scripts needed to recreate the complete database where nothing exists. In Flyway terms, you just creating a baseline. This isn't the concept of migration at all. Of course, given a V2.0 database, you could see any V1.0 database, blow it away, and install the V2.0 database, but now you've lost your data.

迁移

给出一个完整的数据库V2.0和一个较旧的V1.0数据库,而您想制作V1 .0数据库被升级到V2.0。在数据库世界中,这称为迁移,因为需要以在V2.0上可以使用的方式重新排列现有的1.0数据。现在,您需要一个不仅创建/更改表的脚本,还需要执行一些ETL的脚本(提取数据,转换数据以便能够加载到新表结构中,将旧数据库更改为新表结构,然后将数据加载到数据库中)。视情况而定,这可能不重要。您构建脚本即可执行此操作,Flyway将管理该脚本的执行。

Given a complete database V2.0 and a V1.0 older database, and you want to make the V1.0 database be "upgraded" to the V2.0. In the database world, this is called a migration because the existing 1.0 data needs to be re-arranged in a way that it works on V2.0. Now you need a script that not only creates/alters tables, you need a script that does some ETL (extract data, transform the data to be able to load into the new table structures, alter the old database to the new table structures, then load the data into the database). This may or may not be trivial, depending. You build the script to do it, Flyway will manage executing that script.

Flyway

Flyway启用以下功能:

Flyway enables the following:


  • 迁移脚本成为软件资产的一部分。它们经过版本控制,因此可以在源代码管理中维护基线/迁移脚本,从而使迁移成为可重复的功能,而不是一次性脚本工作。

  • Flyway维护一个元表在每个数据库中都可以使用它,因此它知道已应用了哪些脚本

  • Flyway可以完全自动化的方式应用迁移,从而消除了手动执行错误

  • Flyway允许在开发过程中创建迁移脚本(例如测试驱动开发使单元测试创​​建成为开发的组成部分),以便您以迁移脚本的形式捕获所有数据库开发(而不是根据需要构建迁移脚本)

  • 使用Flyway通过单个命令在几秒钟内更新任何以前版本的应用程序是很常见的。从数据库到新版本的过程不复存在,现在,数据库beco的发展我很容易且通常。

  • Migration scripts become part of the software asset. They are versioned so that baseline/migration scripts can be maintained in source control in a way that migration becomes a repeatable feature as opposed to "one off" scripting work.
  • Flyway maintains a meta table in each database it works with so it knows what scripts have been applied
  • Flyway can apply migration in a completely automated way that removes manual execution errors
  • Flyway enables the creation of migration scripts as part of development (like Test Driven Development makes unit test creation an integral part of development) so that all your database development is captured in the form of migration scripts (rather than building migration scripts as needed as part of "one off" migrations.
  • It's common when using Flyway to update any previous version of your application in seconds via a single command. It becomes so easy that the stress of migration from an old DB to a new version goes away and now, evolution of the DB becomes easy and usual.

要正确使用Flyway,需要更改工作流程:每次在开发人员数据库中进行更改时,将该更改转换为迁移脚本,以便您可以对世界上存在的所有较旧数据库版本执行这些更改。并将这些脚本检入到应用程序的源代码中,使迁移像其他任何功能一样,成为软件资产的头等公民。

To use Flyway well, it requires changing your workflow: every time develop a change in your developer DB, put the change into a migration script so you can execute those changes against all the older DB versions that exist in the world. And those scripts are checked into your application's source code making migration a first class citizen of your software asset just like any other functionality.

这篇关于鉴于我必须自己编写迁移脚本,因此Flyway可提供什么价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆