Running migration from within application #314

Closed
dealproc opened this Issue Oct 9, 2012 · 12 comments

Comments

Projects
None yet
4 participants
Contributor

dealproc commented Oct 9, 2012

Can we obtain a wiki page for how to run migrations from within an application? Would like to also know if there's a way of issuing a backup/restore process through FluentMigrator as well... I seem to be having need for these features/functionality.
...
If we could get this to trigger within a Web Deployment package for web projects, that would work, but I still need it for thick client applications.

Contributor

daniellee commented May 16, 2013

It really isn't that hard to run MigrationRunner from within an application so I'll document that in the wiki. The backup/restore part of this issue might now be possible due to the new Transaction Mode feature. It would be done using the Execute.Sql expression so there is no explicit support. This would be a nice addition to FluentMigrator if it works.

Contributor

dealproc commented May 16, 2013

I wound up getting it to work. I'll see what I can do to pop code over to you... was just hard to find the bits I needed to automate this. the only crappy thing I'm facing now is SQLite not being as good of a migration based db as Postgres or Ms SQL Server is.

Contributor

dealproc commented May 22, 2013

Wondering if we can extend Fluent Migrator to either expose an event for a progress indicator, or extend the Announcer to provide step nnn of {total nnn} for the migrations... would be cool to have that UI ability as well.

Hi

I wasn't able to find the wiki page where you documented how to run MigrationRunner from within an application. Could you please point me to the page?

Thanks, Mike Hachen

Contributor

dealproc commented Apr 19, 2014

This may help:

    public static class MigrationManager {
        public static bool Migrate() {
            var ctx = new FluentMigrator.Runner.Initialization.RunnerContext(new FluentMigrator.Runner.Announcers.NullAnnouncer()) {
                ApplicationContext = string.Empty,
                Database = "sqlite", // the database type as you would configure in msbuild.
                Connection = Constants.CONNECTION_STRING,
                Target = "Demo.Core" // the assembly name that contains your migrations.
            };

            try {
                var executor = new TaskExecutor(ctx);
                executor.Execute();
            } catch (Exception ex) {
                return false;
            }

            return true;
        }
    }

Again, it would be grand if we could get some better feedback, like we have nnn of xxx migrations to run, or some sort of percentage complete event for UI updates when in this context.

Hi dealproc

Perfect! Just what I was looking for:)

Thanks, Mike

Contributor

dealproc commented Apr 22, 2014

Sure, no worries.
Again, it would be great if someone in the core team could contribute the know-how to get an event from TaskExecutor, etc. to get some sort of feedback that we can use to integrate into the app's UI for migrations.

karaaie commented Jan 9, 2015

+1, I have a similar usecase

Contributor

dealproc commented Jan 9, 2015

I'm also using this now with Octopus Deploy, and am running migrations on sql servers during deployments of new versions of our website(s).

If I haven't posted the bits, let me know how i can create a project for this (like if we can establish a "group" in github) and I'll put the bits in place so others can use it.

karaaie commented Jan 9, 2015

I'd be very keen on seeing what you have pieced together. Perhaps you can make a simple project in your own account and link it here? Perhaps even send a PR to @schambers with a notice on the readme with the link to your sample? :)

Contributor

dealproc commented Jan 9, 2015

nupackage with a 1-line powershell script that runs the console runner was about all it was.

Contributor

dealproc commented Mar 2, 2015

This is about all it took to make it happen:
https://gist.github.com/dealproc/0077c04de71627d8929f

The idea is to do the following:

  • Include OctoPack into your migration library
  • Add the Deploy.ps1 and project nuspec files into your project
  • Have your CI Server build and publish the nupkg file
  • Have one of your tentacles be responsible for deploying this package

dealproc closed this Mar 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment