Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute FluentMigrator migrations from code [closed]

Tags:

Are there any tutorials or example code for executing FluentMigrator migrations from within code? Some "Getting Started..." tutorial would be just awesome. All I was able to find was FluentMigrator.Tests (unit tests), inside FluentMigrator source, which are not as helpful as "Getting Started..." would be.

I just want to add few classes to the project and run the migrations from that project, with no external tools. Is it possible in Fluent Migrator? Something like

FluentMigrator.Migrate("database path", typeof(Migration024)); 

which I would call from Program.Main()?

like image 392
Paya Avatar asked May 01 '10 20:05

Paya


Video Answer


2 Answers

One of the original authors of FluentMigrator just wrote this "Getting started" blogpost.

like image 72
Christian Specht Avatar answered Sep 22 '22 05:09

Christian Specht


I cribbed this from their source code...

using (IAnnouncer announcer = new TextWriterAnnouncer(Console.Out)) {    IRunnerContext migrationContext = new RunnerContext(announcer)     {        Connection = "Data Source=test.db;Version=3",        Database = "sqlite",        Target = "migrations"     };     TaskExecutor executor = new TaskExecutor(migrationContext);    executor.Execute(); } 

I use code similar to this in a custom action class in WiX. Target is the name of the assembly you want to execute. In your case, it would be whatever assembly is produced by your migration project. There are other options on the IRunnerContext you can set. Like Namespace, PreviewOnly, etc. Unfortunately, it isn't documented so you'll have to dig into the code to figure it out. The project that generates the Migrate.exe assembly is where I found most of this.

like image 36
Justin Rudd Avatar answered Sep 20 '22 05:09

Justin Rudd