我当前的宠物项目是一个与语言无关的数据库迁移库(威奇比 在谷歌代码上)。它很大程度上受到 ActiveRecord Migrations 的启发,但有一些细节。例如,执行一些基本的“类型推断”,这样您就不必指定 FK 列的类型。它也足够智能,可以在仅给出“升级”序列的情况下生成“降级”脚本。尽管迁移是用特殊的 DSL 编写的,但该工具主要针对 .NET 项目。它还独立于数据库平台。

下面是语法的快速浏览:

  migration "Blog" revision => 1:
    type-aliases:
      type-alias N type => String, length => 200, nullable => false, default => ""

    defaults:
      default-primary-key ID type => Int32, nullable => false, identity => true

    version 1:
      add table Author:
        FirstName type => N
        LastName type => N
        EmailAddress type => N, unique => true
        Login type => N, unique => true
        Password type => Binary, length => 64, nullable => true

      add table Tag:
        Name type => N

      add table Blog:
        Name type => N
        Description type => String, nullable => false

      add table BlogPost:
        Title type => N
        Slug type => N
        BlogID references => Blog
        AuthorID references => Author

      add table BlogPostTagJunction primary-key => false:
        BlogPostID references => BlogPost
        TagID references => Tag

    version 2:
      add table BlogPostComment:
        BlogPostID references => BlogPost
        AuthorEmailAddress type => N
        Content type => String, nullable => false

    version 3:
      add table Media:
        TypeID type => Int32
        Name type => N
        MimeType type => N
        Length type => Int32
        BlogPostID nullable => true, references => BlogPost
        BlogPostCommentID nullable => true, references => BlogPostComment

      add table User:
        Login type => String, length => 200, nullable => false
        Password type => Binary, length => 64, nullable => false

        index IX_Login columns => [ID, [Login, desc]], unique => true

    version 4:
        add table Forum:
          Name type => String, length => 200, nullable => false
        add column ModeratorUserID nullable => false, references => User

    version 5:
        remove index IX_Login table => User

    version 6:
        add index IX_Login table => User, columns => [ID, [Login, desc]], unique => true

    version 7:
        BlogAuthorJunction primary-key => false:
            BlogID references => Blog
            AuthorID references => Author

        execute native-sql upgrade-resource => InsertSeedData, downgrade-resource => DeleteSeedData

我知道还有其他迁移库,但是嘿,这是一个宠物项目!

问题是:您对数据库迁移工具包总体期望有哪些功能?您对这个特定的小狗语法有何看法?

有帮助吗?

解决方案

从它的外观来看,我不得不说它非常容易理解,而且整体结构看起来非常干净。

我正在寻找的最大功能如下。

  1. 能够在事务中进行更改以在出现问题时回滚。(数据完整性或其他)
  2. 如果需要,能够查看实际生成的 SQL 脚本
  3. 如果上一个版本出现故障,自动回滚

我还有关于移动键、索引等的其他要求,但看起来您已经处理了。对我来说,它真正关注的是实际执行的控制,以及快速、可靠的撤销计划!

其他提示

我喜欢这个语法。在您的样品,你焦点集中于改变结构。但是,我们的数据操作?

这是非常经常当在迁移我要修改的数据(例如添加一些字典数据)。

我想看到以验证每个修订已经被应用到数据库的能力。所以说,例如,第3版增加了表“媒体”。从那时起,4和5的版本已经被添加到数据库,但某处沿线“约翰尼Q专家”删除表“媒体”。现在到6版本,它需要改变“媒体”表(不再存在) - 校验功能可能是有用的保证的版本所做的所有更改的高潮1直通5存在于数据库中,以便在下一个版本可以正确应用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top