public static string CreateScriptFromMigration()
 {
     var migrationConfig = new Configuration();
     var migrator = new DbMigrator(migrationConfig);
     var scriptor = new MigratorScriptingDecorator(migrator);
     return scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
 }
Пример #2
0
        public string Run(string from, string to)
        {
            var configuration = new Configuration();

            //Can set the Target Database to be in another Server or Environment
            //configuration.TargetDatabase =
            //    new DbConnectionInfo("Server=.;Database=Investment;Trusted_Connection=True;",
            //        "System.Data.SqlClient");

            //var context = (InvestmentContext)Activator.CreateInstance(configuration.ContextType);
            var runUpdate = false;

            var migrator = new DbMigrator(configuration);

            var scriptor = new MigratorScriptingDecorator(migrator);
            var sql = scriptor.ScriptUpdate("", "");
            //var sql = scriptor.ScriptUpdate("Name-Of-Source-Migration", "Name-Of-Target-Migration");
            //configuration.RunSeedProcess(context);

            if (runUpdate)
            {
                //Can run the update from here
                migrator.Update(); //Could add a "TargetMigration"
            }

            return sql;
        }
Пример #3
0
 public static void GenerateSqlUsingDbMigrator()
 {
     using (var context = new AdventureWorksContext())
     {
         var configuration = new Configuration
             {
                 ContextType = typeof(AdventureWorksContext),
                 TargetDatabase =
                     new DbConnectionInfo(context.Database.Connection.ConnectionString, "System.Data.SqlClient")
             };
         var migrator = new DbMigrator(configuration);
         var migrations = migrator.GetDatabaseMigrations();
         if (migrations.Any())
         {
             var scriptor = new MigratorScriptingDecorator(migrator);
             string script = scriptor.ScriptUpdate(null, migrations.Last());
             if (!String.IsNullOrEmpty(script))
             {
                 Console.WriteLine(script);
                 //context.Database.ExecuteSqlCommand(script);
             }
         }                
         
         Console.ReadKey();
     }
 }
Пример #4
0
        public void MigrateIdentity()
        {
            var migrateConifg = new  Resume.IdentityMigrations.Configuration();
            var migrator = new DbMigrator(migrateConifg);
            var script = new MigratorScriptingDecorator(migrator);

            script.ScriptUpdate(DbMigrator.InitialDatabase, null);
        }
Пример #5
0
		public void ScriptMigration(string from, string to, string output)
		{
			var config = FindDbMigrationsConfiguration();
			var migrator = new DbMigrator(config);
			var scriptingDecorator = new MigratorScriptingDecorator(migrator);
			var script = scriptingDecorator.ScriptUpdate(from ?? "0", to);
			File.WriteAllText(output, script);
			Console.WriteLine($"Scripted migration as SQL to file '{output}'.");
		}
        public void ScriptUpdate_should_throw_on_arbitrary_down()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();
            var scriptingDecorator = new MigratorScriptingDecorator(migrator);

            Assert.Equal(Strings.DownScriptWindowsNotSupported, Assert.Throws<MigrationsException>(() => scriptingDecorator.ScriptUpdate("000000000000001_Second", "000000000000000_First")).Message);
        }
        public void ScriptUpdate_should_prepend_batch_separator()
        {
            ResetDatabase();

            var migrator = new MigratorScriptingDecorator(CreateMigrator<ShopContext_v1>());

            var script = migrator.ScriptUpdate(null, null);

            Assert.True(script.Contains("GO\r\n\r\nCREATE PROCEDURE"));
        }
        public void ScriptUpdate_should_return_valid_script()
        {
            ResetDatabase();

            var migrator = new MigratorScriptingDecorator(CreateMigrator<ShopContext_v1>());

            var script = migrator.ScriptUpdate(null, null);

            Assert.True(script.Length > 6000);
        }
Пример #9
0
        public void ScriptUpdate_should_return_valid_script()
        {
            ResetDatabase();

            var migrator = new MigratorScriptingDecorator(CreateMigrator <ShopContext_v1>());

            var script = migrator.ScriptUpdate(null, null);

            Assert.True(script.Length > 6000);
        }
Пример #10
0
        public void ScriptUpdate_should_prepend_batch_separator()
        {
            ResetDatabase();

            var migrator = new MigratorScriptingDecorator(CreateMigrator <ShopContext_v1>());

            var script = migrator.ScriptUpdate(null, null);

            Assert.True(script.Contains("GO\r\n\r\nCREATE PROCEDURE"));
        }
Пример #11
0
 static void Main(string[] args)
 {
     Database.DefaultConnectionFactory = new SqlConnectionFactory(args[0]);
     var assembly = Assembly.LoadFrom(args[1]);
     var contextType = assembly.GetExportedTypes().Single(x => typeof (DbContext).IsAssignableFrom(x));
     var configuration = (DbMigrationsConfiguration)Activator.CreateInstance(typeof (DbMigrationsConfiguration<>).MakeGenericType(contextType));
     configuration.AutomaticMigrationsEnabled = true;
     var migrator = new DbMigrator(configuration);
     var scripter = new MigratorScriptingDecorator(migrator);
     Console.WriteLine(scripter.ScriptUpdate(null, null));
 }
        public void ScriptUpdate_should_not_create_database()
        {
            var migrator
                = new MigratorScriptingDecorator(
                    CreateMigrator<ShopContext_v1>(targetDatabase: "NoSuchDatabase"));

            DropDatabase();

            migrator.ScriptUpdate(null, null);

            Assert.False(DatabaseExists());
        }
        public void ScriptUpdate_should_throw_on_automatic_target()
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();
            migrator.Update();

            var automaticMigration = migrator.GetDatabaseMigrations().Single();
            var scriptingDecorator = new MigratorScriptingDecorator(migrator);

            Assert.Equal(Strings.AutoNotValidForScriptWindows(automaticMigration), Assert.Throws<MigrationsException>(() => scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, automaticMigration)).Message);
        }
        public void Can_script_windows(bool whenDatabaseExists)
        {
            ResetDatabase();

            var migrator1 = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version1");

            CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1).Update();

            var migrator2 = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: version1);

            var version2 = new MigrationScaffolder(migrator2.Configuration).Scaffold("Version2");

            CreateMigrator<ShopContext_v2>(scaffoldedMigrations: new[] { version1, version2 }).Update();

            var migrator3 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: new[] { version1, version2 });
            var version3 = new MigrationScaffolder(migrator3.Configuration).Scaffold("Version3");

            var migrator4 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: new[] { version1, version2, version3 });
            var scriptingDecorator = new MigratorScriptingDecorator(migrator4);

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            // All
            var script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, null);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.True(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));

            // 1
            script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version1.MigrationId);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.False(script.Contains("Version2"));
            Assert.False(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));

            // 1 & 2
            script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version2.MigrationId);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.False(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));
        }
Пример #15
0
        public void ScriptUpdate_should_not_create_database()
        {
            var migrator
                = new MigratorScriptingDecorator(
                      CreateMigrator <ShopContext_v1>(targetDatabase: "NoSuchDatabase"));

            DropDatabase();

            migrator.ScriptUpdate(null, null);

            Assert.False(DatabaseExists());
        }
Пример #16
0
        public void ScriptUpdate_should_throw_on_arbitrary_down()
        {
            ResetDatabase();

            var migrator           = CreateMigrator <ShopContext_v1>();
            var scriptingDecorator = new MigratorScriptingDecorator(migrator);

            Assert.Equal(
                Strings.DownScriptWindowsNotSupported,
                Assert.Throws <MigrationsException>(() => scriptingDecorator.ScriptUpdate("000000000000001_Second", "000000000000000_First"))
                .Message);
        }
Пример #17
0
 public static void GenerateSQLScript()
 {
     #if DEBUG
     var migrator = new DbMigrator(new Configuration());
     var scriptor = new MigratorScriptingDecorator(migrator);
     var migration = migrator.GetLocalMigrations().LastOrDefault();
     var sql = scriptor.ScriptUpdate("0", migration);
     string info = $"-- ========================================== --\r\n-- Current Migration: {migration}\r\n-- ========================================== --\r\n\r\n";
     string fileName = "OpenNos.sql";
     File.WriteAllText(Path.Combine((@"../../../OpenNos.DAL.EF/DB/"), fileName), info + sql);
     #endif
 }
 public static void GenerateScript()
 {
     DbMigrator efMigrator = new DbMigrator(new DbMigrationsConfiguration());
     var pendingMigrations = efMigrator.GetLocalMigrations().ToList();
     pendingMigrations.Insert(0, "0");
     foreach (var migration in pendingMigrations.Zip(pendingMigrations.Skip(1), Tuple.Create))
     {
         var sql = new MigratorScriptingDecorator(efMigrator).ScriptUpdate(migration.Item1, migration.Item2); // <-- problem here, the efMigrator is reused several times
         Console.WriteLine("Migration from " + (migration.Item1 ?? "<null> ") + " to " + (migration.Item2 ?? "<null> "));
         Console.WriteLine(sql);
         Console.WriteLine("-------------------------------------");
     }
 }
Пример #19
0
        public void ScriptUpdate_should_throw_on_automatic_source()
        {
            ResetDatabase();

            var migrator = CreateMigrator <ShopContext_v1>();

            migrator.Update();

            var automaticMigration = migrator.GetDatabaseMigrations().Single();
            var scriptingDecorator = new MigratorScriptingDecorator(migrator);

            Assert.Equal(
                Strings.AutoNotValidForScriptWindows(automaticMigration),
                Assert.Throws <MigrationsException>(() => scriptingDecorator.ScriptUpdate(automaticMigration, null)).Message);
        }
        public void Can_use_custom_operations()
        {
            var configuration = new DbMigrationsConfiguration<EmptyModel>
                {
                    MigrationsAssembly = typeof(CustomOperationMigration).Assembly(),
                    MigrationsNamespace = typeof(CustomOperationMigration).Namespace
                };
            configuration.SetSqlGenerator("System.Data.SqlClient", new CustomSqlGenerator());

            var migrator = new DbMigrator(configuration);
            var scriptor = new MigratorScriptingDecorator(migrator);

            var sql = scriptor.ScriptUpdate(DbMigrator.InitialDatabase, null);

            Assert.Contains("-- This is a test.", sql);
        }
Пример #21
0
        public void ApplyDatabaseMigrations()
        {
            //Configuration is the class created by Enable-Migrations
            DbMigrationsConfiguration dbMgConfig = new Configuration()
            {
                //DbContext subclass generated by EF power tools
                ContextType = typeof(FrameworkContext)
            };
            using (var databaseContext = new FrameworkContext())
            {
                try
                {
                    var database = databaseContext.Database;
                    var isExistsDatabase = database.Exists();

                    var migrationConfiguration = dbMgConfig;

                    migrationConfiguration.TargetDatabase =
                        new DbConnectionInfo(database.Connection.ConnectionString, "System.Data.SqlClient");
                    var migrator = new DbMigrator(migrationConfiguration);

                    // update or create database
                    migrator.Update();

                    // if database is first initial, then initial data for it
                    if (isExistsDatabase)
                    {
                        return;
                    }

                    InitialData(databaseContext);
                }
                catch (AutomaticDataLossException adle)
                {
                    dbMgConfig.AutomaticMigrationDataLossAllowed = true;
                    var mg = new DbMigrator(dbMgConfig);
                    var scriptor = new MigratorScriptingDecorator(mg);
                    string script = scriptor.ScriptUpdate(null, null);
                    throw new Exception(adle.Message + " : " + script);
                }
            }
        }
        public static void Configure()
        {
            var configuration = new Configuration
            {
                AutomaticMigrationsEnabled = true,
                AutomaticMigrationDataLossAllowed = true,
                ContextType = typeof(MembershipDB),
                TargetDatabase = new DbConnectionInfo("MembershipDB")
            };

            var migratorScriptingDecorator = new MigratorScriptingDecorator(new DbMigrator(configuration));

            var pendingMigrations = migratorScriptingDecorator.GetPendingMigrations();
            var dbMigrator = new DbMigrator(configuration);

            foreach (var pendingMigration in pendingMigrations)
            {
                dbMigrator.Update(pendingMigration);
            }
        }
Пример #23
0
        public void Can_script_pending_migrations()
        {
            ResetDatabase();

            var migrator1 = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version1");

            CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1).Update();

            var migrator2 = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: version1);

            var version2 = new MigrationScaffolder(migrator2.Configuration).Scaffold("Version2");

            var migrator3 = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: new[] { version1, version2 });
            var scriptingDecorator = new MigratorScriptingDecorator(migrator3);

            var script = scriptingDecorator.ScriptUpdate(null, null);

            Assert.False(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.False(script.Contains("AutomaticMigration"));
        }
Пример #24
0
        private void ScriptMigrations(MigratorBase migrator)
        {
            var scriptingMigrator = new MigratorScriptingDecorator(migrator);

            string start;
            string target;
            if (migrator.GetDatabaseMigrations().Any(s => IsMigration(s, TargetMigration)))
            {
                // Down migration, start is null, target is the target
                start = null;
                target = migrator.GetDatabaseMigrations().Single(s => IsMigration(s, TargetMigration));
            }
            else
            {
                // Up migration, go from start to target.
                start = migrator.GetDatabaseMigrations().FirstOrDefault();
                target = migrator.GetLocalMigrations().Single(s => IsMigration(s, TargetMigration));
            }

            string startName = start ?? migrator.GetDatabaseMigrations().FirstOrDefault();
            string scriptFileName = String.Format("{0}-{1}.sql", startName, target);
            if(File.Exists(scriptFileName)) {
                Log.Error("File already exists: {0}", scriptFileName);
                return;
            }

            // Generate script
            Log.Info("Scripting migration from {0} to {1}", startName, target);
            if (!WhatIf)
            {
                string script = scriptingMigrator.ScriptUpdate(start, target);

                // Write the script
                File.WriteAllText(scriptFileName, script);
            }
            Log.Info("Wrote script to {0}", scriptFileName);
        }
Пример #25
0
        private void Can_script_windows(bool whenDatabaseExists)
        {
            ResetDatabase();

            var migrator1 = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version1");

            CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1).Update();

            var migrator2 = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: version1);

            var version2 = new MigrationScaffolder(migrator2.Configuration).Scaffold("Version2");

            CreateMigrator<ShopContext_v2>(scaffoldedMigrations: new[] { version1, version2 }).Update();

            var migrator3 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: new[] { version1, version2 });
            var version3 = new MigrationScaffolder(migrator3.Configuration).Scaffold("Version3");

            var migrator4 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: new[] { version1, version2, version3 });
            var scriptingDecorator = new MigratorScriptingDecorator(migrator4);

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            // All
            var script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, null);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.True(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));

            if (!whenDatabaseExists
                || DatabaseProvider == DatabaseProvider.SqlClient)
            {
                using (var connection = ProviderFactory.CreateConnection())
                {
                    connection.ConnectionString = ConnectionString;

                    using (var command = connection.CreateCommand())
                    {
                        connection.Open();
                        
                        foreach (var batch in script.Split(new[] { "GO\r\n" }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            command.CommandText = batch;
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
            
            // 1
            script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version1.MigrationId);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.False(script.Contains("Version2"));
            Assert.False(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));

            // 1 & 2
            script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version2.MigrationId);

            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("Version1"));
            Assert.True(script.Contains("Version2"));
            Assert.False(script.Contains("Version3"));
            Assert.False(script.Contains("AutomaticMigration"));
        }
Пример #26
0
        public void Can_script_downs()
        {
            ResetDatabase();

            var version1 = new MigrationScaffolder(CreateMigrator<ShopContext_v1>().Configuration).Scaffold("Version1");
            var migrator = CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1);

            migrator.Update();

            var scriptingDecorator = new MigratorScriptingDecorator(migrator);

            var script = scriptingDecorator.ScriptUpdate(null, DbMigrator.InitialDatabase);

            Assert.True(script.Contains(DropMetadataStatement));
            Assert.False(script.Contains("Version1"));
        }
Пример #27
0
        private void Can_script_trailing_automatic_migration(bool whenDatabaseExists)
        {
            ResetDatabase();

            var migrator1 = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version1");

            var migrator2 = CreateMigrator<ShopContext_v2>(automaticDataLossEnabled: true, scaffoldedMigrations: version1);

            migrator2.Update();

            var scriptingDecorator = new MigratorScriptingDecorator(migrator2);

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            // Act
            var script = scriptingDecorator.ScriptUpdate(version1.MigrationId, null);

            // Assert
            Assert.False(script.Contains(CreateMetadataStatement));
            Assert.False(script.Contains("Version1"));
            Assert.True(script.Contains("AutomaticMigration"));
        }
Пример #28
0
        private void Can_script_first_migration_with_leading_automatic_migration(bool whenDatabaseExists)
        {
            ResetDatabase();

            CreateMigrator<ShopContext_v2>().Update();

            var migrator1 = CreateMigrator<ShopContext_v3>();
            var version2 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version2");

            var migrator2 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: version2);

            migrator2.Update();

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            var scriptingDecorator
                = new MigratorScriptingDecorator(CreateMigrator<ShopContext_v3>(scaffoldedMigrations: version2));

            // Act
            var script = scriptingDecorator.ScriptUpdate(DbMigrator.InitialDatabase, version2.MigrationId);

            // Assert
            Assert.True(script.Contains(CreateMetadataStatement));
            Assert.True(script.Contains("AutomaticMigration"));
            Assert.True(script.Contains("Version2"));
        }
Пример #29
0
		private static string GenetateSqlUpdate(DbContext context, int version, bool isUpdate)
		{
			var dbMigrator = CreateDbMigrator(context);
			MigratorScriptingDecorator msd = new MigratorScriptingDecorator(dbMigrator);

			var versionCurrentName = version > 1 ? GetVersionName(version) : null;
			var versionPreviousName = version > 1 ? GetVersionName(version - 1) : GetVersionName(version);

			if (isUpdate)
				return msd.ScriptUpdate(versionPreviousName, versionCurrentName);
			else
				return msd.ScriptUpdate(versionPreviousName, null);
		}
Пример #30
0
 public static string MigrationScript(string CurrentMigration, string TargetMigration)
 {
     var migrator = GetMigrator();
     var scriptor = new MigratorScriptingDecorator(migrator);
     return scriptor.ScriptUpdate(CurrentMigration, TargetMigration);
 }
Пример #31
0
        private void Can_script_using_migration_names(bool whenDatabaseExists)
        {
            ResetDatabase();

            var migrator = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator.Configuration).Scaffold("Banana");

            CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1).Update();

            migrator = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: version1);
            var version2 = new MigrationScaffolder(migrator.Configuration).Scaffold("Apple");

            migrator = CreateMigrator<ShopContext_v2>(scaffoldedMigrations: new[] { version1, version2 });
            migrator.Update();

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            var scriptingDecorator
                = new MigratorScriptingDecorator(
                    CreateMigrator<ShopContext_v2>(scaffoldedMigrations: new[] { version1, version2 }));

            var script = scriptingDecorator.ScriptUpdate("Banana", "Apple");

            Assert.False(script.Contains(CreateMetadataStatement));
            Assert.False(script.Contains("Banana"));
            Assert.True(script.Contains("Apple"));
            Assert.False(script.Contains("AutomaticMigration"));
        }
Пример #32
0
        /// <summary>
        /// Получить список столбцов которые будут удалены
        /// </summary>
        /// <param name="configuration">Конфигурация миграций</param>
        /// <returns>Список столбцов которые будут удалены</returns>
        private IEnumerable<ColumnInfo> GetDroppingColumnFromMigrationsConfiguration(DbMigrationsConfiguration configuration)
        {
            var droppingColumn = new List<ColumnInfo>();

            if (configuration != null)
            {
                var migrator = new DbMigrator(configuration);

                var pendingMigrations = migrator.GetPendingMigrations();
                if (pendingMigrations.Any())
                {
                    var targetMigration = pendingMigrations.Last();

                    var scriptor = new MigratorScriptingDecorator(migrator);
                    string script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: targetMigration);
                    var parts = script.Split(new[] {"\r\n\r\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries).ToList();//разбиваем скрипт по миграциям
                    parts.RemoveAll(p => p.StartsWith("INSERT [dbo].[__MigrationHistory]") || p.StartsWith("VALUES"));//удаляем вставки в MigrationHistory

                    var dropColumnParts = parts.Where(p => p.Contains("DROP COLUMN"));//находим DROP COLUMN
                    foreach (var dropColumnPart in dropColumnParts)
                    {
                        Regex regex = new Regex("ALTER TABLE (?<schemaWithTable>.*) DROP COLUMN (?<column>.*)");
                        Match match = regex.Match(dropColumnPart);
                        string[] schemaWithTable = match.Groups["schemaWithTable"].Value.Split(new[] { '.', '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        string schema = schemaWithTable.First();
                        string table = schemaWithTable.Last();
                        string column = match.Groups["column"].Value.Trim(new[] { '[', ']' });

                        droppingColumn.Add(new ColumnInfo(new TableInfo(schema, table), column));
                    }
                }
            }
            return droppingColumn;
        }
Пример #33
0
 internal override void ExecuteStatements(
     IEnumerable <MigrationStatement> migrationStatements)
 {
     MigratorScriptingDecorator.BuildSqlScript(migrationStatements, this._sqlBuilder);
 }
Пример #34
0
            protected override void RunCore()
            {
                var migrator = GetMigrator();

                var script
                    = new MigratorScriptingDecorator(migrator)
                        .ScriptUpdate(SourceMigration, TargetMigration);

                AppDomain.CurrentDomain.SetData("result", script);
            }
        public void Can_script_middle_migration_with_leading_automatic_migration(bool whenDatabaseExists)
        {
            ResetDatabase();

            var migrator1 = CreateMigrator<ShopContext_v1>();
            var version1 = new MigrationScaffolder(migrator1.Configuration).Scaffold("Version1");

            CreateMigrator<ShopContext_v1>(scaffoldedMigrations: version1).Update();

            CreateMigrator<ShopContext_v2>(automaticDataLossEnabled: true, scaffoldedMigrations: version1).Update();

            var migrator2 = CreateMigrator<ShopContext_v3>(scaffoldedMigrations: version1);
            var version3 = new MigrationScaffolder(migrator2.Configuration).Scaffold("Version3");

            var migrator3 = CreateMigrator<ShopContext_v3>(
                automaticDataLossEnabled: true, scaffoldedMigrations: new[] { version1, version3 });

            migrator3.Update();

            var scriptingDecorator = new MigratorScriptingDecorator(migrator3);

            if (!whenDatabaseExists)
            {
                ResetDatabase();
            }

            // Act
            var script = scriptingDecorator.ScriptUpdate(version1.MigrationId, version3.MigrationId);

            // Assert
            Assert.False(script.Contains(CreateMetadataStatement));
            Assert.False(script.Contains("Version1"));
            Assert.True(script.Contains("AutomaticMigration"));
            Assert.True(script.Contains("Version3"));
        }
Пример #36
-1
 public virtual String ScriptMigration(
     String fromMigrationName,
     String toMigrationName,
     bool idempotent,
     String contextTypeName)
 {
     if (idempotent)
     {
         throw new NotImplementedException();
     }
     
     var contextType = GetContextType(contextTypeName);
     var configurationType = GetConfigurationType(contextType);
     
     var configuration = CreateConfiguration(configurationType);
     var migrator = new DbMigrator(configuration);
     
     var scripting = new MigratorScriptingDecorator(migrator);
     
     var script = scripting.ScriptUpdate(fromMigrationName, toMigrationName);
     
     return script;
 }