2009-02-19 106 views
3

我目前的寵物項目是獨立於語言的數據庫遷移庫(Google Code上的Wizardby)。它非常受ActiveRecord Migrations的啓發,但有一些細微之處。例如,做一些基本的「類型推斷」,所以你不必指定FK列的類型。它也足夠智能,只需「升級」序列即可生成「降級」腳本。儘管遷移是用特殊的DSL編寫的,但該工具主要針對.NET項目。它也是數據庫平臺無關的。.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 

我知道其他遷移庫在那裏,但嘿,這是一個寵物項目!

現在的問題是:你對數據庫遷移工具包有什麼特點,你可以說這個特定的小狗語法明智嗎?

回答

2

從外觀來看,我不得不說它很容易遵循,整體結構看起來很乾淨。

我正在尋找像這樣的最大功能如下。

  1. 能夠使交易的變化來回滾應該有一個問題。 (數據完整性或以其他方式)
  2. 能夠看到實際生成的SQL腳本,在需要時
  3. 自動回滾,如果發生在最後一個版本出現故障

我有一個關於鑰匙的移動其他要求,索引等等,但看起來你已經處理了。對我而言,它確實專注於實際執行的控制,以及快速,穩固的退出計劃!

6

我喜歡這種語法。在你的樣本中,你專注於改變結構。但是數據操作呢?

在遷移過程中,我經常需要修改數據(例如添加一些字典數據)。

3

我想看看能否驗證每個修訂版已應用於數據庫。所以說例如版本3添加了表格'媒體'。從那時起,版本4 & 5已被添加到數據庫中,但沿着'Johnny Q Expert'這一行刪除了'Media'表。現在版本6需要改變'媒體'表(不再存在) - 驗證功能可能是有用的,這可以確保數據庫中存在1到5版本所做的所有更改的高潮,因此下一個版本可以是正確應用。