3

Could I use migrator.net bare migration framework and just have a set of SQL files to do the upgrade/downgrade? i.e. just use the framework to check database version and which scripts to run etc?

thanks

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

And what do you do on those scripts? Could you provide a little example please? Thanks
The scripts contain sql statements which can do whatever you like. The Down script should undo whatever the up script does. I created mine using SqlPubWiz and a preexisting database, as in my answer here: stackoverflow.com/questions/2321052/… and then separated the resulting script into things-which-create-things and things-which-destroy-things, and used them as up and down scripts respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.