public void Initialize() { try { Catfish.Tests.Migrations.Configuration config = new Catfish.Tests.Migrations.Configuration(); var migrator = new DbMigrator(config); foreach (string migName in migrator.GetPendingMigrations()) { Type migration = config.MigrationsAssembly.GetType(string.Format("{0}.{1}", config.MigrationsNamespace, migName.Substring(16))); DbMigration m = (DbMigration)Activator.CreateInstance(migration); m.Up(); var prop = m.GetType().GetProperty("Operations", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (prop != null) { IEnumerable <MigrationOperation> operations = prop.GetValue(m) as IEnumerable <MigrationOperation>; var generator = config.GetSqlGenerator("System.Data.SQLite"); var statements = generator.Generate(operations, "2008"); foreach (MigrationStatement item in statements) { Db.Database.ExecuteSqlCommand(item.Sql); } } } } catch (Exception ex) { throw ex; } }
public void Initialize(MockConnection solrConnection) { //if (SolrService.IsInitialized) //{ // //TODO: Inject the new connection into this current solr thread. //} //else //{ // SolrService.ForceInit(solrConnection); //} SolrService.ForceInit(solrConnection); try { Catfish.Tests.Migrations.Configuration config = new Catfish.Tests.Migrations.Configuration(); var migrator = new DbMigrator(config); foreach (string migName in migrator.GetLocalMigrations()) { Type migration = config.MigrationsAssembly.GetType(string.Format("{0}.{1}", config.MigrationsNamespace, migName.Substring(16))); DbMigration m = (DbMigration)Activator.CreateInstance(migration); m.Up(); var prop = m.GetType().GetProperty("Operations", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); if (prop != null) { IEnumerable <MigrationOperation> operations = prop.GetValue(m) as IEnumerable <MigrationOperation>; var generator = config.GetSqlGenerator("System.Data.SQLite"); var statements = generator.Generate(operations, "2008"); foreach (MigrationStatement item in statements) { Db.Database.ExecuteSqlCommand(item.Sql); } } } } catch (Exception ex) { throw ex; } }
internal override void ApplyMigration(DbMigration migration, DbMigration lastMigration) { DebugCheck.NotNull(migration); var migrationMetadata = (IMigrationMetadata)migration; var lastModel = GetLastModel(lastMigration, migrationMetadata.Id); var sourceModel = migration.GetSourceModel(); var targetModel = migration.GetTargetModel(); if (sourceModel != null && IsModelOutOfDate(sourceModel.Model, lastMigration)) { base.AutoMigrate( migrationMetadata.Id.ToAutomaticMigrationId(), lastModel, sourceModel, downgrading: false); lastModel = sourceModel; } var migrationSchema = GetDefaultSchema(migration); var historyModel = GetHistoryModel(migrationSchema); var systemOperations = Enumerable.Empty<MigrationOperation>(); if (ReferenceEquals(lastModel.Model, _emptyModel.Value) && !base.HistoryExists()) { systemOperations = _modelDiffer.Diff(_emptyModel.Value, historyModel); } else { var lastMigrationSchema = GetLastDefaultSchema(migrationMetadata.Id); if (!string.Equals(lastMigrationSchema, migrationSchema, StringComparison.Ordinal)) { var lastHistoryModel = GetHistoryModel(lastMigrationSchema); systemOperations = _modelDiffer.Diff(lastHistoryModel, historyModel); } } migration.Up(); ExecuteOperations(migrationMetadata.Id, targetModel, migration.Operations, systemOperations, false); }
internal override void ApplyMigration(DbMigration migration, DbMigration lastMigration) { var migrationMetadata = (IMigrationMetadata)migration; var compressor = new ModelCompressor(); var lastModel = GetLastModel(lastMigration, migrationMetadata.Id); var targetModel = compressor.Decompress(Convert.FromBase64String(migrationMetadata.Target)); if (migrationMetadata.Source != null) { var sourceModel = compressor.Decompress(Convert.FromBase64String(migrationMetadata.Source)); if (IsModelOutOfDate(sourceModel, lastMigration)) { base.AutoMigrate( migrationMetadata.Id.ToAutomaticMigrationId(), lastModel, sourceModel, downgrading: false); lastModel = sourceModel; } } bool? includeSystemOps = null; if (ReferenceEquals(lastModel, _emptyModel.Value)) { includeSystemOps = true; if (!targetModel.HasSystemOperations()) { // upgrade scenario, inject the history model _historyRepository .AppendHistoryModel( targetModel, new DbProviderInfo(_usersContextInfo.ConnectionProviderName, _providerManifestToken)); } } var systemOperations = _modelDiffer.Diff(lastModel, targetModel, includeSystemOps) .Where(o => o.IsSystem); migration.Up(); ExecuteOperations(migrationMetadata.Id, targetModel, migration.Operations.Concat(systemOperations), false); }
internal override void ApplyMigration(DbMigration migration, DbMigration lastMigration) { var migrationMetadata = (IMigrationMetadata)migration; var compressor = new ModelCompressor(); if (migrationMetadata.Source != null) { var sourceModel = compressor.Decompress(Convert.FromBase64String(migrationMetadata.Source)); if (IsModelOutOfDate(sourceModel, lastMigration)) { base.AutoMigrate( migrationMetadata.Id + "_" + Strings.AutomaticMigration, GetLastModel(lastMigration, migrationMetadata.Id), sourceModel, downgrading: false); } } migration.Up(); var targetModel = compressor.Decompress(Convert.FromBase64String(migrationMetadata.Target)); ExecuteOperations(migrationMetadata.Id, targetModel, migration.Operations.ToList(), false); }