我目前最喜欢的项目是一个独立于语言的数据库迁移库( Google Code上的Wizardby)。它的灵感很大程度上来自ActiveRecord迁移,但也有一些细微之处。例如,执行一些基本的“类型推断”,因此您不必指定FK列的类型。它也足够智能,可以生成只给出“升级”序列的“降级”脚本。尽管迁移是用特殊的领域特定语言编写的,但该工具主要针对.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我知道有其他的迁移库,但是,嘿,它是一个宠儿项目!
问题是:一般情况下,您期望数据库迁移工具包具有哪些功能,对于这只特殊的小狗,您能从语法上说些什么?
发布于 2009-03-09 17:39:33
从它的外观来看,我不得不说它很容易遵循,总体上结构看起来相当干净。
我在这类东西中寻找的最大的特性如下。
上一版本出现故障
关于键、索引等的移动,我还有其他要求,但看起来你已经处理好了。对我来说,它真正关注的是围绕实际执行的控制,以及快速、可靠的回退计划!
发布于 2009-03-09 22:23:16
我喜欢这个语法。在您的示例中,您将重点放在了更改结构上。但是数据操作呢?
在迁移过程中,我经常需要修改数据(例如,添加一些字典数据)。
发布于 2010-02-18 12:10:25
我希望能够验证每个修订版是否已应用于数据库。例如,版本3添加了表'Media‘。从那时起,版本4和版本5被添加到数据库中,但在“Johnny Q Expert”的某处删除了表“Media”。现在到了版本6,它需要更改'Media‘表(不再存在)--一个验证函数可能很有用,它可以确保在版本1到版本5中所做的所有更改都出现在数据库中,以便可以正确地应用下一个版本。
https://stackoverflow.com/questions/565426
复制相似问题