Skip to content

Commit

Permalink
Added capability to do EM replacement tokens in Iteration migrations.…
Browse files Browse the repository at this point in the history
… Fixed Organizational participant bug. (#187)
  • Loading branch information
Alex Vorobiev authored Feb 4, 2021
1 parent a456057 commit da9958a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 15 additions & 1 deletion CDP4Orm/MigrationEngine/GenericMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,25 @@ public override void ApplyMigration(NpgsqlTransaction transaction, IReadOnlyList

foreach (var applicableSchema in applicableSchemas)
{
var replaceList = new List<Tuple<string, string>>();

// using the actual schema name in the generic script to execute
var replace = new Tuple<string, string>(SCHEMA_NAME_REPLACE, applicableSchema);
replaceList.Add(replace);

// allow possibility of replacing engineeringmodel tokens in iterations
if (this.MigrationMetaData.MigrationScriptApplicationKind == MigrationScriptApplicationKind.Iteration)
{
if (applicableSchema.Contains("Iteration_"))
{
var applicableEngineeringModelSchema = applicableSchema.Replace("Iteration_", "EngineeringModel_");
replaceList.Add(new Tuple<string, string>(ENGINEERING_MODEL_REPLACE, applicableEngineeringModelSchema));
}
}

using (var sqlCommand = new NpgsqlCommand())
{
sqlCommand.ReadSqlFromResource(this.MigrationMetaData.ResourceName, null, new [] { replace });
sqlCommand.ReadSqlFromResource(this.MigrationMetaData.ResourceName, null, replaceList);

sqlCommand.Connection = transaction.Connection;
sqlCommand.Transaction = transaction;
Expand Down
7 changes: 6 additions & 1 deletion CDP4Orm/MigrationEngine/MigrationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public abstract class MigrationBase
/// The string to replace in the script for schema partition
/// </summary>
protected const string SCHEMA_NAME_REPLACE = "SchemaName_Replace";


/// <summary>
/// The string to replace in the script for engineeringModel partition
/// </summary>
protected const string ENGINEERING_MODEL_REPLACE = "EngineeringModel_Replace";

/// <summary>
/// Initializes a new instance of the <see cref="MigrationBase"/> class
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ CREATE TRIGGER elementdefinition_organizationalparticipant_apply_revision
BEFORE INSERT OR UPDATE OR DELETE
ON "SchemaName_Replace"."ElementDefinition_OrganizationalParticipant"
FOR EACH ROW
EXECUTE PROCEDURE "SiteDirectory".revision_management('ElementDefinition', 'SchemaName_Replace');
EXECUTE PROCEDURE "SiteDirectory".revision_management('ElementDefinition', 'EngineeringModel_Replace');

CREATE OR REPLACE FUNCTION "SchemaName_Replace"."ElementDefinition_OrganizationalParticipant_Data" ()
RETURNS SETOF "SchemaName_Replace"."ElementDefinition_OrganizationalParticipant" AS
Expand Down

0 comments on commit da9958a

Please sign in to comment.