public IActionResult Migrate()
        {
            _output = new StringBuilder();
            _output.AppendLine(_migrator.Execute());

            return(Ok(_output.ToString()));
        }
예제 #2
0
        public void DatabaseMigrator_Execute_DryRunLogsActions()
        {
            DatabaseMigrator.Execute(Settings, MigrationsAssembly);

            Assert.That(Log.ToString(), Is.Not.Empty);
            Trace.WriteLine(Log.ToString());
            Console.WriteLine(Log.ToString());
        }
예제 #3
0
        protected override void ProcessRecord()
        {
            if (string.IsNullOrEmpty(Language))
            {
                Language = "CSharp";
            }

            if (string.IsNullOrEmpty(Provider))
            {
                Provider = "SqlServer";
            }

            try
            {
                var db = new DatabaseMigrator(new TaskLogger(this), DryRun, Provider, VersionTo, Trace);

                if (!string.IsNullOrEmpty(this.Directory))
                {
                    var engine = new ScriptEngine(this.Language, null);
                    db.Execute(engine.Compile(this.Directory));
                }

                if (this.MigrationsAssemblyPath != null)
                {
                    Assembly asm = Assembly.LoadFrom(this.MigrationsAssemblyPath);
                    if (Settings == null)
                    {
                        db.Execute(asm);
                    }
                    else
                    {
                        db.Execute(Settings.ToDictionary(), asm);
                    }
                }
            }
            catch (Exception e)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        e,
                        "Push-DatabaseMigrations",
                        ErrorCategory.NotSpecified,
                        this
                        )
                    );
            }
        }
예제 #4
0
        private void MigrateToVersion(long version, Assembly assembly)
        {
            var log    = new StringBuilder();
            var logger = new StringLogger(log);
            var db     = new DatabaseMigrator(logger, false, "SqlServer", version, true);

            db.Execute(Settings, assembly);
        }
예제 #5
0
        public void GeneratedVersionedEntityDoesntNeedUpdate()
        {
            var databaseMigrator = new DatabaseMigrator();
            var configuration    = new VersionedConfiguration();
            var answerProvider   = new Mock <IAnswerProvider>();

            databaseMigrator.Execute(configuration, connectionString, "System.Data.SqlClient", Enumerable.Empty <string>(), Enumerable.Empty <string>(), Enumerable.Empty <KeyValuePair <string, string> >(), answerProvider.Object);

            var scriptGenerator = new ScriptGenerator();
            var script          = scriptGenerator.Generate(configuration, connectionString, "System.Data.SqlClient", Enumerable.Empty <string>(), Enumerable.Empty <string>(), Enumerable.Empty <KeyValuePair <string, string> >(), answerProvider.Object);

            this.output.WriteLine(script);
            Assert.True(string.IsNullOrWhiteSpace(script));
        }
예제 #6
0
        public void SetUp()
        {
            string folder = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DatabaseMigratorTests)).CodeBase);

            MigrationsAssembly = Assembly.LoadFrom(new Uri(Path.Combine(folder, "SampleDbMigrations.dll")).LocalPath);
            Log      = new StringBuilder();
            Logger   = new StringLogger(Log);
            Settings = new Dictionary <string, string>()
            {
                { "Server", "." },
                { "Database", "TestDb" }
            };
            DatabaseMigrator = new DatabaseMigrator(Logger, false, "SqlServer", -1, true /*trace*/);
            DatabaseMigrator.Execute(Settings, MigrationsAssembly);
        }
예제 #7
0
        private static void ExecuteMigrate(CommandOption assemblyPath, CommandOption configurationType, CommandOption connectionString, CommandOption provider, CommandOption tablesToIgnore, CommandOption indexesToIgnore, CommandOption extraPluralizationWords)
        {
            var databaseMigrator = new DatabaseMigrator();

            databaseMigrator.Execute(
                AssemblyContext.LoadType <IConfiguration>(assemblyPath.Value(), configurationType.Value()),
                connectionString.Value(),
                provider.HasValue()
                    ? provider.Value()
                    : "System.Data.SqlClient",
                tablesToIgnore.Values,
                indexesToIgnore.Values,
                extraPluralizationWords.GetExtraPluralizationWords(),
                new ConsoleAnswerProvider());
        }
예제 #8
0
 static void initialize_app()
 {
     Log.Level = LogLevel.Debug;
     SessionFactory.Initialize("Data source=:memory:", new SqliteAdapter());
     Domain.Configure
     (
         Map.Entity <Person>()
         .Property(x => x.FirstName)
         .Property(x => x.LastName),
         Map.Entity <Forum>()
         .List(x => x.Posts)
         .Property(x => x.Name)
         .Property(x => x.TimeOfDayLastUpdated),
         Map.Entity <Post>()
         .ParentColumn("ForumId")
         .Property(x => x.Title)
         .Property(x => x.Body)
         .Property(x => x.DatePosted)
         .BelongsTo(x => x.Poster, "PosterId")
     );
     UnitOfWork.Start(); //NOTE: Normally unit-of work-would be more fine grained; however the in-memory database is created blank with each connection
     DatabaseMigrator.Execute();
 }