本文整理汇总了C#中Migrator类的典型用法代码示例。如果您正苦于以下问题:C# Migrator类的具体用法?C# Migrator怎么用?C# Migrator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Migrator类属于命名空间,在下文中一共展示了Migrator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUpCurrentVersion
void SetUpCurrentVersion(long version, List<long> appliedVersions, bool assertRollbackIsCalled, bool includeBad)
{
var providerMock = new DynamicMock(typeof (ITransformationProvider));
providerMock.SetReturnValue("get_MaxVersion", version);
providerMock.SetReturnValue("get_AppliedMigrations", appliedVersions);
providerMock.SetReturnValue("get_Logger", new Logger(false));
if (assertRollbackIsCalled)
providerMock.Expect("Rollback");
else
providerMock.ExpectNoCall("Rollback");
_migrator = new Migrator((ITransformationProvider) providerMock.MockInstance, Assembly.GetExecutingAssembly(), false);
// Enlève toutes les migrations trouvée automatiquement
_migrator.MigrationsTypes.Clear();
_upCalled.Clear();
_downCalled.Clear();
_migrator.MigrationsTypes.Add(typeof (FirstMigration));
_migrator.MigrationsTypes.Add(typeof (SecondMigration));
_migrator.MigrationsTypes.Add(typeof (ThirdMigration));
_migrator.MigrationsTypes.Add(typeof (FourthMigration));
_migrator.MigrationsTypes.Add(typeof (SixthMigration));
if (includeBad)
_migrator.MigrationsTypes.Add(typeof (BadMigration));
}
示例2: Execute
public override bool Execute()
{
using (var store = new DocumentStore())
{
store.ConfigureUsingConnectionString(ConnectionString);
store.Initialize();
var migrator = new Migrator();
foreach (var item in Migrations)
{
var assembly = Assembly.LoadFrom(item.GetMetadata("FullPath"));
migrator.Migrate(store, assembly, ToVersion);
}
}
if (ToVersion > 0)
{
Log.LogMessage("Migrated to version " + ToVersion + ".");
}
else
{
Log.LogMessage("Migrated to maximum version.");
}
return true;
}
示例3: Migrate
public bool Migrate(string connectionString, string providerName, IEnumerable<Type> entities, Action<MigratorResult, Type> callbackOnChanges)
{
var bResult = false;
var provider = ProviderFactory.GetProvider(connectionString, providerName);
foreach (var entity in entities)
{
var batch = new BatchQuery(provider);
var m = new Migrator(Assembly.GetExecutingAssembly());
var commands = m.MigrateFromModel(entity, provider);
bResult |= commands.Length > 0;
try
{
foreach (var s in commands)
batch.QueueForTransaction(new QueryCommand(PrepareCommand(s), provider));
batch.ExecuteTransaction();
}
catch(Exception ex)
{
var sb = new StringBuilder(ex.Message);
sb.Append(": ");
foreach (var command in commands)
sb.Append(command);
throw new Exception(sb.ToString(), ex);
}
if (callbackOnChanges == null) continue;
callbackOnChanges(commands.Length > 0 ? MigratorResult.ChangesMadeToEntity : MigratorResult.NoChanges,
entity);
}
if (callbackOnChanges != null)
callbackOnChanges(MigratorResult.ChangesMadeToAllEntities, null);
return bResult;
}
示例4: Get
public ActionResult Get(string id)
{
var migrator = new Migrator(RavenSessionManager.DocumentStore, typeof(MigrationClass).Assembly);
var status = migrator.GetMigrationStatus();
return View(status);
}
示例5: Create
public static Migrator Create(string targetName, Migrator migrator)
{
migrator.Guard = new Guard();
switch (targetName)
{
case "mysql":
migrator.DbInterface = new DbInterface();
migrator.DbInterface.Executor = new Executor();
migrator.Applier = new MySQL.Applier();
break;
case "mssql":
migrator.DbInterface = new MSSQL.DbInterface();
migrator.DbInterface.Executor = new MSSQL.Executor();
migrator.Applier = new MSSQL.Applier();
break;
case "postgresql":
migrator.DbInterface = new PostgreSQL.DbInterface();
migrator.DbInterface.Executor = new PostgreSQL.Executor();
migrator.Applier = new PostgreSQL.Applier();
break;
default:
throw new Exception("Target name " + targetName + " is not valid");
}
return migrator;
}
示例6: SetUp
public void SetUp()
{
_migrator = new Migrator(TransformationProvider, MigrationAssembly, true);
Assert.IsTrue(_migrator.MigrationsTypes.Count > 0, "No migrations in assembly " + MigrationAssembly.Location);
_migrator.MigrateTo(0);
}
示例7: SetUp
public void SetUp()
{
_migrator = new Migrator(TransformationProvider);
Assert.IsTrue(_migrator.MigrationsTypes.Count > 0);
_migrator.MigrateTo(0);
}
示例8: Execute
public override bool Execute()
{
log4net.Config.BasicConfigurator.Configure(new Log4NetMsBuildAppender(this.Log, new log4net.Layout.PatternLayout("%-5p %x %m")));
var migrator = new Migrator();
migrator.Run(this);
return true;
}
示例9: GetMigrator
private Migrator GetMigrator()
{
Assembly asm = Assembly.LoadFrom(ConfigurationManager.AppSettings["MigrationAsembly"]);
string provider = ConfigurationManager.AppSettings["MigrationProvider"];
string connectString = ConfigurationManager.AppSettings["ConnectionString"];
Migrator migrator = new Migrator(provider, connectString, asm, false);
return migrator;
}
示例10: TestIrreversibleMigrationExceptionIsThrown
public void TestIrreversibleMigrationExceptionIsThrown()
{
long timestamp2 = typeof(Migration2).GetTimestamp();
IVersioning versioning = GetVersioning(true, true, true);
Migrator migrator = new Migrator("", ProviderNames.SqlServer2008);
migrator.UseCustomVersioning(versioning);
migrator.FetchMigrationsTo(typeof(Migration1).Assembly, timestamp2); // should throw an IrreversibleMigrationException as Migration3 is irreversible
}
示例11: Execute_WithSingleValue_TakesValue
public void Execute_WithSingleValue_TakesValue()
{
var migrator = new Migrator();
string json = @"{execute: 'SELECT current_timestamp' }";
string command = migrator.GetCommandFromJson(json);
Assert.AreEqual("SELECT current_timestamp", command);
}
示例12: Can_Export_Database_Into_Export_File
public void Can_Export_Database_Into_Export_File()
{
var migrator = new Migrator();
migrator.Migrate();
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, BlogMLExportWorker.ExportFileName);
var exportFile = new FileInfo(path);
Assert.True(exportFile.Exists);
}
示例13: VerifyPendingMigrationsAreFoundForSpecificModule
public void VerifyPendingMigrationsAreFoundForSpecificModule()
{
IVersioning versioning = GetVersioning(false, false, false);
Migrator migrator = new Migrator("", ProviderNames.SqlServer2008, new MigrationOptions { ModuleSelector = m => m == Migration2.Module });
migrator.UseCustomVersioning(versioning);
IMigrationBatch batch = migrator.FetchMigrations(typeof(Migration1).Assembly);
Assert.AreEqual(1, batch.Count, string.Format(CultureInfo.CurrentCulture, "Only one migration for the module named '{0}' exists.", Migration2.Module));
}
示例14: CreateDatabase
public static void CreateDatabase(string dbName, string relativePath)
{
string dbFilePath = GetAbsoluteDatabaseFilePath(dbName, relativePath);
string connectionString = ConnectionString(dbFilePath);
Migrator migrator = new Migrator(connectionString);
#if DEBUG
migrator.Migrate(runner => runner.MigrateDown(0));
#endif
migrator.Migrate(runner => runner.MigrateUp());
DapperExtensions.DapperExtensions.DefaultMapper = typeof(PluralizedAutoClassMapper<>);
}
示例15: VerifyPendingMigrationsAreFound
public int VerifyPendingMigrationsAreFound(bool migration1IsContained, bool migration2IsContained, bool migration3IsContained)
{
IVersioning versioning = GetVersioning(migration1IsContained, migration2IsContained, migration3IsContained);
Migrator migrator = new Migrator("", ProviderNames.SqlServer2008);
migrator.UseCustomVersioning(versioning);
IMigrationBatch batch = migrator.FetchMigrations(typeof(Migration1).Assembly);
versioning.VerifyAllExpectations();
return batch.Count;
}