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()
?
One of the original authors of FluentMigrator just wrote this "Getting started" blogpost.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With