私の現在のお気に入りのプロジェクトは、言語に依存しないデータベース移行ライブラリ ( 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
他にも移行ライブラリがあることは知っていますが、それはペット プロジェクトです。
問題は、データベース移行ツールキットに一般的にどのような機能を期待しているのか、この特定の子犬について構文的に何を言えるのかということです。