public override ExitCodeType Run(IDataLoadJob job, GracefulCancellationToken cancellationToken) { if (Skip(job)) { return(ExitCodeType.Error); } //if(_migrationHost != null) // throw new Exception("Load stage already started once"); // After the user-defined load process, the framework handles the insert into staging and resolves any conflicts var stagingDbInfo = _databaseConfiguration.DeployInfo[LoadBubble.Staging]; var liveDbInfo = _databaseConfiguration.DeployInfo[LoadBubble.Live]; job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Migrating '" + stagingDbInfo + "' to '" + liveDbInfo + "'")); var migrationConfig = new MigrationConfiguration(stagingDbInfo, LoadBubble.Staging, LoadBubble.Live, _databaseConfiguration.DatabaseNamer); var migrationHost = new MigrationHost(stagingDbInfo, liveDbInfo, migrationConfig, _databaseConfiguration); migrationHost.Migrate(job, cancellationToken); return(ExitCodeType.Success); }
public void TestMerge(DatabaseType databaseType) { //microsoft one gets called for free in test setup (see base class) if (databaseType != DatabaseType.MicrosoftSQLServer) { SetupFromTo(databaseType); } var dt = new DataTable(); var colName = new DataColumn("Name", typeof(string)); var colAge = new DataColumn("Age", typeof(int)); dt.Columns.Add(colName); dt.Columns.Add(colAge); dt.Columns.Add("Postcode", typeof(string)); //Data in live awaiting toTbl be updated dt.Rows.Add(new object[] { "Dave", 18, "DD3 1AB" }); dt.Rows.Add(new object[] { "Dave", 25, "DD1 1XS" }); dt.Rows.Add(new object[] { "Mango", 32, DBNull.Value }); dt.Rows.Add(new object[] { "Filli", 32, "DD3 78L" }); dt.Rows.Add(new object[] { "Mandrake", 32, DBNull.Value }); dt.PrimaryKey = new[] { colName, colAge }; var toTbl = To.CreateTable("ToTable", dt); Assert.IsTrue(toTbl.DiscoverColumn("Name").IsPrimaryKey); Assert.IsTrue(toTbl.DiscoverColumn("Age").IsPrimaryKey); Assert.IsFalse(toTbl.DiscoverColumn("Postcode").IsPrimaryKey); dt.Rows.Clear(); //new data being loaded dt.Rows.Add(new object[] { "Dave", 25, "DD1 1PS" }); //update toTbl change postcode toTbl "DD1 1PS" dt.Rows.Add(new object[] { "Chutney", 32, DBNull.Value }); //new insert Chutney dt.Rows.Add(new object[] { "Mango", 32, DBNull.Value }); //ignored because already present in dataset dt.Rows.Add(new object[] { "Filli", 32, DBNull.Value }); //update from "DD3 78L" null dt.Rows.Add(new object[] { "Mandrake", 32, "DD1 1PS" }); //update from null toTbl "DD1 1PS" dt.Rows.Add(new object[] { "Mandrake", 31, "DD1 1PS" }); // insert because Age is unique (and part of pk) var fromTbl = From.CreateTable(DatabaseName + "_ToTable_STAGING", dt); //import the toTbl table as a TableInfo TableInfo ti; ColumnInfo[] cis; var cata = Import(toTbl, out ti, out cis); //put the backup trigger on the live table (this will also create the needed hic_ columns etc) var triggerImplementer = new TriggerImplementerFactory(databaseType).Create(toTbl); triggerImplementer.CreateTrigger(new ThrowImmediatelyCheckNotifier()); var configuration = new MigrationConfiguration(From, LoadBubble.Staging, LoadBubble.Live, new FixedStagingDatabaseNamer(toTbl.Database.GetRuntimeName(), fromTbl.Database.GetRuntimeName())); var lmd = new LoadMetadata(CatalogueRepository); cata.LoadMetadata_ID = lmd.ID; cata.SaveToDatabase(); var migrationHost = new MigrationHost(From, To, configuration, new HICDatabaseConfiguration(lmd)); //set SetUp a logging task var logServer = new ServerDefaults(CatalogueRepository).GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID); var logManager = new LogManager(logServer); logManager.CreateNewLoggingTaskIfNotExists("CrossDatabaseMergeCommandTest"); var dli = logManager.CreateDataLoadInfo("CrossDatabaseMergeCommandTest", "tests", "running test", "", true); var job = new ThrowImmediatelyDataLoadJob(); job.DataLoadInfo = dli; job.RegularTablesToLoad = new List <ITableInfo>(new[] { ti }); migrationHost.Migrate(job, new GracefulCancellationToken()); var resultantDt = toTbl.GetDataTable(); Assert.AreEqual(7, resultantDt.Rows.Count); AssertRowEquals(resultantDt, "Dave", 25, "DD1 1PS"); AssertRowEquals(resultantDt, "Chutney", 32, DBNull.Value); AssertRowEquals(resultantDt, "Mango", 32, DBNull.Value); AssertRowEquals(resultantDt, "Filli", 32, DBNull.Value); AssertRowEquals(resultantDt, "Mandrake", 32, "DD1 1PS"); AssertRowEquals(resultantDt, "Mandrake", 31, "DD1 1PS"); AssertRowEquals(resultantDt, "Dave", 18, "DD3 1AB"); var archival = logManager.GetArchivalDataLoadInfos("CrossDatabaseMergeCommandTest", new CancellationToken()); var log = archival.First(); Assert.AreEqual(dli.ID, log.ID); Assert.AreEqual(2, log.TableLoadInfos.Single().Inserts); Assert.AreEqual(3, log.TableLoadInfos.Single().Updates); }