zoukankan      html  css  js  c++  java
  • 开源DataBase组件:FluentMigrator

          今天将介绍一款开源组件FluentMigrator,其提供了jQuery式链式编程方式,和3.0后的表达式语法使其语义清晰。主要提供我们队数据库结构的维护,版本控制回滚和新增。适用于 敏捷和TDD实践中我们的需求功能的递增,数据结构增加,可持续化集成,应用场景感觉如其名Fluent(流畅)。

    一:我们先利用NuGet安装FluentMigrator:

    1:在vs在打开Package Manager Console:

    image

    2:安装FluentMigrator:

    image

    3:如果你希望控制台提交,可以安装其tools:

    image

    二:下面我面做一个简单的实例订单Order(这里仅列出其部分字段,不会考虑实际业务):

    DO:

    using System; 

    namespace FluentMigratorTest 

        public  class  Orders 
        { 
            public int ID { getset; } 

            public string CustomerID { getset; } 

            public decimal DisCount { getset; } 

            public DateTime OrderDate { getset; } 
        } 
    }

     

     表结构块:

    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using FluentMigrator; 

    namespace FluentMigratorTest 

        [Migration(0)] 
        public class OrderMigration:Migration 
        { 
            public override void Up() 
            {                      
                Create.Table("Orders_test")                
                    .WithColumn("ID").AsInt32().Identity().PrimaryKey("id_pk").Indexed("Orders_Pk_ID"
                    .WithColumn("CustomerID").AsString().ForeignKey("Customers""CustomerID").NotNullable() 
                    .WithColumn("DisCount").AsDecimal().WithDefaultValue(0
                    .WithColumn("OrderDate").AsDateTime().WithDefault(SystemMethods.CurrentDateTime); 
            } 

            public override void Down() 
            {   
                Delete.Table("Orders_test"); 
            } 
        } 
    }

     

    其提供了Up版本递增和Down回滚。语法是不是很流畅?其不仅这些功能还提供了:

     

    image

    image

    对表结构的新增,修改,删除,执行sql方法。

    利用其提供的tools,更新在数据库

    image

    支持数据库:

  • sqlserver2000
  • sqlserver2005
  • sqlserver2008
  • sqlserverce
  • sqlserver
  • mysql
  • postgres
  • oracle
  • sqlite
  • jet

    并支持Profile,部署开发和测试不通的数据库。

    更多其它信息请参加:https://github.com/schambers/fluentmigrator/wiki

查看全文
  • 相关阅读:
    linux环境开机自启动nginx
    linux下启动weblogic
    oracle 数据库服务名怎么查
    关于 CSS3 backface-visiable 与 overflow 属性的冲突
    iframe 通信之坑
    npm i --save & npm i --save-dev
    window.blur/focus & document.hasFocus()
    mac zip 命令行 终端压缩加密文件
    audio之autoplay
    JAVA 重写&重载/多态/抽象类/封装/接口/包
  • 原文地址:https://www.cnblogs.com/whitewolf/p/2520422.html
  • Copyright © 2011-2022 走看看