开发者

MitratorDotNet (Migrator.Net) - Can I use with just bare SQL up/down migration files?

Could I use migrator.net bare migration framework and just have a set of SQ开发者_JAVA技巧L files to do the upgrade/downgrade? i.e. just use the framework to check database version and which scripts to run etc?

thanks


Yes. I have a mixture of sql and code migrations. My migration which uses sql files looks something like:

using System.Data;
using Migrator.Framework;
using System.IO;
using System.Reflection;

namespace MyDBMigration
{
    [Migration(2)]
    public class CreateStructures_002 : Migration
    {

        public override void Up()
        {
            Assembly asm = Assembly.GetAssembly(typeof(CreateStructures_002));
            Stream s = asm.GetManifestResourceStream("MyDBMigration.SqlScripts.createbaredb.sql");
            StreamReader sr = new StreamReader(s);
            string sql = sr.ReadToEnd();
            Database.ExecuteNonQuery(sql);
        }

        public override void Down()
        {
            Assembly asm = Assembly.GetAssembly(typeof(CreateStructures_002));
            Stream s = asm.GetManifestResourceStream("MyDBMigration.SqlScripts.dropbaredb.sql");
            StreamReader sr = new StreamReader(s);
            string sql = sr.ReadToEnd();
            Database.ExecuteNonQuery(sql);
        }
    }
}

Where I have two files 'createbaredb.sql' and 'dropbaredb.sql' in a directory (SqlScripts) and set as 'Embedded Resource' in the file property pane.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜