MitratorDotNet (Migrator.Net) - Can I use only simple up / down SQL migration files?

Can I use migrator.net basic migration infrastructure and just have a set of SQL files to update / downgrade? for example, just use the framework to check the version of the database and scripts to run, etc.

thank

+3
source share
1 answer

Yes. I have a mixture of sql and code transitions. My migration using sql files looks something like this:

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 the directory (SqlScripts) and set to "Embedded Resource" in the file properties panel.

+2
source

Source: https://habr.com/ru/post/1734987/


All Articles