Example #1
0
        public void StartMigration()
        {
            var consoleAnnouncer = new TextWriterAnnouncer(System.Console.Out)
                                        {
                                            ShowElapsedTime = true,
                                            ShowSql = true
                                        };
             var runnerContext = new RunnerContext(consoleAnnouncer)
             {

                 Database= DataBaseType,
                 Connection=connStr,
                 Target=assemblyPath,
                 PreviewOnly= false,
                 Namespace=string.Empty,
                 Task=string.Empty,
                 Version=0,
                 Steps=1,
                 WorkingDirectory = currentPath,
                 Profile=string.Empty,
                 Timeout=0,
                 ConnectionStringConfigPath=string.Empty
             };
             TaskExecutor tskMigration = new TaskExecutor(runnerContext);
             tskMigration.Execute();
        }
Example #2
0
        /// <summary>
        /// Migrates the specified file name and path.
        /// <remarks>This method is called directly when performing integration tests.</remarks>
        /// </summary>
        /// <param name="fileNameAndPath">The file name and path.</param>
        /// <param name="withBackup">if set to <c>true</c> [with backup].</param>
        /// <param name="withAnnouncer">if set to <c>true</c> [with announcer].</param>
        public static void Migrate(string fileNameAndPath, bool withBackup = false, bool withAnnouncer = false)
        {
            var currentDb = new FileInfo(fileNameAndPath);
            var backupDb = string.Empty;

            if (withBackup) { Backup(currentDb); }

            var emptyAnnouncers = new Announcer[] { };
            var consoleAnnouncer = new Announcer[] { new ConsoleAnnouncer() };
            var announcerToProvide = new CompositeAnnouncer(withAnnouncer ? consoleAnnouncer : emptyAnnouncers);

            var ctx = new RunnerContext(announcerToProvide)
            {
                ApplicationContext = string.Empty,
                Database = "sqlite",
                Connection = string.Format(CONNECTION_STRING_FORMAT, fileNameAndPath).NormalizePathSeparator(),
                Targets = new[] { "Drey.Configuration" }
            };

            try
            {
                var executor = new TaskExecutor(ctx);
                executor.Execute();
            }
            catch (Exception)
            {
                if (withBackup)
                {
                    currentDb.Delete();
                    if (!string.IsNullOrWhiteSpace(backupDb)) { File.Copy(backupDb, currentDb.FullName); }
                }

                throw;
            }
        }
Example #3
0
        public static void MigrateToLatestVersion(string connectionString)
        {
            var migrationContext = new RunnerContext(new Log4NetAnnouncer())
            {
                Connection = connectionString,
                Database = DefaultProvider,
                Target = typeof(Migrate).Assembly.GetName().Name
            };

            var executor = new TaskExecutor(migrationContext);
            executor.Execute();
        }
        private void Execute(string task)
        {
            tbAnnouncer.Clear();

            var version = (int)numVersion.Value;
            var steps = (int)numSteps.Value;
            var tags = new List<string>();
            var profile = tbProfile.Text;
            foreach (var item in lbTags.SelectedItems)
            {
                tags.Add(item.ToString());
            }

            var announcer = new TextWriterAnnouncer(new TextBoxStreamWriter(tbAnnouncer));
            announcer.Heading("Migrate database");

            var runnerContext = new RunnerContext(announcer)
            {
                Database = "SqlServer2008",
                Connection = ConfigurationManager.ConnectionStrings["FluentMigrator"].ConnectionString,

                Target = "DatabaseProject.dll",
                PreviewOnly = false,
                Namespace = "DatabaseProject",
                NestedNamespaces = true,
                Task = task,
                Version = version,
                Steps = steps,
                Tags = tags,
                //WorkingDirectory = "C:\\temp",
                Profile = profile,
                Timeout = 30,
                TransactionPerSession = true
            };

            var executor = new TaskExecutor(runnerContext);


            try
            {
                executor.Execute();
            }
            catch (Exception ex)
            {
                tbAnnouncer.AppendText("Exception: " + ex.Message);
            }

        }
Example #5
0
        private void Execute()
        {
            var runnerContext = new RunnerContext(GetAnnouncer())
            {
                Database = database,
                Task = task,
                Connection = connectionString,
                Target = migrationAssembly.CodeBase.Replace("file:///", string.Empty),
                Version = version
            };

            Trace.TraceInformation("#\n# Executing migration task {0}...\n#\n", task);
            var localTask = new TaskExecutor(runnerContext);
            localTask.Execute();
            Trace.TraceInformation("\n#\n# Task {0} complete!\n#", task);
        }
        private void Execute()
        {
            var announcer = new TextWriterAnnouncer(Console.Out) {ShowElapsedTime = true, ShowSql = true};
            var runnerContext = new RunnerContext(announcer)
            {
                Database = _database,
                Task = _task,
                Connection = _connectionString,
                Target = _migrationAssembly.CodeBase.Replace("file:///", ""),
                Version = _version
            };

            Trace.TraceInformation("#\n# Executing migration task {0}...\n#\n", _task);
            var task = new TaskExecutor(runnerContext);
            task.Execute();
            Trace.TraceInformation("\n#\n# Task {0} complete!\n#", _task);
        }
 public virtual void Migrate(string connectionString, Assembly assembly = null)
 {
     if (_databaseType == "sqlite")
     {
         CopyInteropAssemblyByPlatform();
     }
     assembly = assembly ?? Assembly.GetExecutingAssembly();
     var announcer = new TextWriterAnnouncer(Console.Out) {ShowSql = true, ShowElapsedTime = false};
     var context = new RunnerContext(announcer)
     {
         Connection = connectionString,
         Database = _databaseType,
         Target = assembly.FullName,
         Profile = "linger",
     };
     var executor = new TaskExecutor(context);
     executor.Execute();
 }
Example #8
0
        public static string Run()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["Main"].ConnectionString;

            var migrationLog = new StringBuilder();
            var announcer = new TextWriterAnnouncer(s => migrationLog.Append(s));
            var runnerContext = new RunnerContext(announcer)
            {
                Database = "sqlserver",
                Connection = connectionString,
                Target = typeof(MigrationsRunner).Assembly.FullName,
            };

            var taskExecutor = new TaskExecutor(runnerContext);
            taskExecutor.Execute();

            return migrationLog.ToString();
        }
Example #9
0
 public void MigrateToVersion(string databaseType, string connectionString, long version, string profile = null, Assembly assembly = null, bool trace = false)
 {
     if (databaseType == "sqlite")
     {
         CopyInteropAssemblyByPlatform();
     }
     assembly = assembly ?? Assembly.GetExecutingAssembly();
     var announcer = trace ? new TextWriterAnnouncer(Console.Out) : (IAnnouncer)new NullAnnouncer();
     var context = new RunnerContext(announcer)
     {
         Connection = connectionString,
         Database = databaseType,
         Target = assembly.FullName,
         Version = version,
         Profile = profile
     };
     var executor = new TaskExecutor(context);
     executor.Execute();
 }
Example #10
0
        public void RunMigrations()
        {
            using (var announcer = new TextWriterAnnouncer(Console.Out)
                {
                    ShowElapsedTime = true,
                    ShowSql = true
                })
            {
                var assembly = typeof(MigrationRunner).Assembly.GetName().Name;

                var migrationContext = new RunnerContext(announcer)
                    {
                        Connection = ConfigurationManager.ConnectionStrings[0].ConnectionString,
                        Database = "SqlServer2008",
                        Target = assembly
                    };

                var executor = new TaskExecutor(migrationContext);
                executor.Execute();
            }
        }