Skip to content

Commit

Permalink
Merge pull request #2022 from HicServices/bugfix/RDMP-256-migrate-com…
Browse files Browse the repository at this point in the history
…posite-pk-issue

Update Migration Strategy to account for all PK values
  • Loading branch information
rdteviotdale authored Nov 6, 2024
2 parents 23cd4c1 + d8201c5 commit 65c2f42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [8.4.0] - Unreleased

- Add Ordering to Filters
- Update Migration strategy to account for all Primary Keys when moving from staging -> live

## [8.3.1] - 2024-10-22

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
namespace Rdmp.Core.DataLoad.Engine.Migration.QueryBuilding;

/// <summary>
/// Migrates from STAGING to LIVE a single table (with a MigrationColumnSet). This is an UPSERT (new replaces old) operation achieved (in SQL) with MERGE and
/// UPDATE (based on primary key). Both tables must be on the same server. A MERGE sql statement will be created using LiveMigrationQueryHelper and executed
/// within a transaction.
/// Migrates from STAGING to LIVE a single table (with a MigrationColumnSet). This is an UPSERT (new replaces old)
/// operation achieved (in SQL) with MERGE and
/// UPDATE (based on primary key). Both tables must be on the same server. A MERGE sql statement will be created
/// using LiveMigrationQueryHelper and executed
/// within a transaction.
/// </summary>
public class OverwriteMigrationStrategy : DatabaseMigrationStrategy
{
Expand Down Expand Up @@ -97,8 +99,9 @@ CrossDatabaseMergeCommandTo..ToTable.Age is null
columnsToMigrate.DestinationTable.GetFullyQualifiedName()))));

sbInsert.AppendLine("WHERE");
sbInsert.AppendLine(
$"{columnsToMigrate.DestinationTable.GetFullyQualifiedName()}.{syntax.EnsureWrapped(columnsToMigrate.PrimaryKeys.First().GetRuntimeName())} IS NULL");
sbInsert.AppendLine(string.Join(" AND ",
columnsToMigrate.PrimaryKeys.Select(pk =>
$"{columnsToMigrate.DestinationTable.GetFullyQualifiedName()}.{syntax.EnsureWrapped(pk.GetRuntimeName())} IS NULL")));

//right at the end of the SELECT
if (columnsToMigrate.DestinationTable.Database.Server.DatabaseType == DatabaseType.MySql)
Expand Down Expand Up @@ -196,7 +199,10 @@ CrossDatabaseMergeCommandTo..ToTable.Age is null
}
}

private static string GetORLine(DiscoveredColumn c, IQuerySyntaxHelper syntax) => string.Format(
"(t1.{0} <> t2.{0} OR (t1.{0} is null AND t2.{0} is not null) OR (t2.{0} is null AND t1.{0} is not null))",
syntax.EnsureWrapped(c.GetRuntimeName()));
private static string GetORLine(DiscoveredColumn c, IQuerySyntaxHelper syntax)
{
return string.Format(
"(t1.{0} <> t2.{0} OR (t1.{0} is null AND t2.{0} is not null) OR (t2.{0} is null AND t1.{0} is not null))",
syntax.EnsureWrapped(c.GetRuntimeName()));
}
}
2 changes: 1 addition & 1 deletion SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

[assembly: AssemblyVersion("8.4.0")]
[assembly: AssemblyFileVersion("8.4.0")]
[assembly: AssemblyInformationalVersion("8.4.0")]
[assembly: AssemblyInformationalVersion("8.4.0")]

0 comments on commit 65c2f42

Please sign in to comment.