【问题标题】:.NET database migration toolkit.NET 数据库迁移工具包
【发布时间】:2010-10-08 14:28:00
【问题描述】:

我目前的宠物项目是一个独立于语言的数据库迁移库(Google Code 上的Wizardby)。它非常受 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

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

问题是:您一般期望从数据库迁移工具包中获得哪些功能?您对这种特殊的小狗语法有何看法?

【问题讨论】:

    标签: .net database-migration


    【解决方案1】:

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

    我在这样的东西中寻找的最大功能如下。

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

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

    【讨论】:

      【解决方案2】:

      我喜欢这种语法。在您的示例中,您专注于改变结构。但是数据操作呢?

      在迁移过程中,我经常需要修改数据(例如添加一些字典数据)。

      【讨论】:

        【解决方案3】:

        我希望能够验证每个修订版是否已应用于数据库。例如,例如版本 3 添加了“媒体”表。从那时起,第 4 版和第 5 版已添加到数据库中,但在“Johnny Q Expert”这一行的某处删除了“Media”表。现在是第 6 版,它需要更改“媒体”表(不再存在) - 验证功能可能很有用,可确保数据库中存在第 1 版至第 5 版中所做的所有更改的高潮,因此下一个版本可以正确应用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-07-22
          • 2021-11-06
          • 1970-01-01
          • 1970-01-01
          • 2021-08-08
          • 2020-10-02
          • 2012-11-26
          • 2015-07-10
          相关资源
          最近更新 更多