gpt4 book ai didi

.NET 数据库迁移工具包

转载 作者:行者123 更新时间:2023-12-01 08:20:54 25 4
gpt4 key购买 nike

我目前的宠物项目是一个独立于语言的数据库迁移库(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 数据库迁移工具包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/565426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com