Skip to content

Commit

Permalink
A2 migration changes 7 - filter migrated a2 instance from msg box sea…
Browse files Browse the repository at this point in the history
…rch (#497)

- Added new column altinnmainversion to storage.instances table and related search procedure storage.readinstancefromquery_v5
- Added MessageBoxQueryModel.FilterMigrated
- Added InstanceQueryParameters.MainVersionInclude/Exclude parameters

Co-authored-by: Henning Normann <[email protected]>
  • Loading branch information
HenningNormann and HenningNormann authored Sep 18, 2024
1 parent c561506 commit cddf83f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Storage/Controllers/MessageboxInstancesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ private static InstanceQueryParameters GetQueryParams(MessageBoxQueryModel query
queryParams.ArchiveReference = queryModel.ArchiveReference;
}

if (queryModel.FilterMigrated ?? false)
{
queryParams.MainVersionInclude = 3;
}

return queryParams;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Storage/Helpers/MessageBoxQueryModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ public class MessageBoxQueryModel
/// </summary>
[JsonPropertyName("language")]
public string Language { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to filter migrated a1/a2 elements
/// </summary>
[JsonPropertyName("filterMigrated")]
public bool? FilterMigrated { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE FUNCTION storage.readinstancefromquery_v4(
CREATE OR REPLACE FUNCTION storage.readinstancefromquery_v5(
_appId TEXT DEFAULT NULL,
_appIds TEXT[] DEFAULT NULL,
_archiveReference TEXT DEFAULT NULL,
Expand All @@ -23,6 +23,8 @@ CREATE OR REPLACE FUNCTION storage.readinstancefromquery_v4(
_lastChanged_idx TIMESTAMPTZ DEFAULT NULL,
_lastChanged_lt TIMESTAMPTZ DEFAULT NULL,
_lastChanged_lte TIMESTAMPTZ DEFAULT NULL,
_mainVersionInclude SMALLINT DEFAULT NULL,
_mainVersionExclude SMALLINT DEFAULT NULL,
_msgBoxInterval_eq TIMESTAMPTZ DEFAULT NULL,
_msgBoxInterval_gt TIMESTAMPTZ DEFAULT NULL,
_msgBoxInterval_gte TIMESTAMPTZ DEFAULT NULL,
Expand Down Expand Up @@ -87,6 +89,8 @@ BEGIN
AND (_lastChanged_lte IS NULL OR i.lastchanged <= _lastChanged_lte)
AND (_lastChanged_lt IS NULL OR i.lastchanged < _lastChanged_lt)
AND (_lastChanged_eq IS NULL OR i.lastchanged = _lastChanged_eq)
AND (_mainVersionInclude IS NULL OR i.altinnmainversion = _mainVersionInclude)
AND (_mainVersionExclude IS NULL OR i.altinnmainversion <> _mainVersionExclude)
AND (_msgBoxInterval_gte IS NULL OR ((i.instance -> 'Status' -> 'IsArchived')::boolean = false AND i.created >= _msgBoxInterval_gte OR (i.instance -> 'Status' -> 'IsArchived')::boolean = true AND i.lastchanged >= _msgBoxInterval_gte))
AND (_msgBoxInterval_gt IS NULL OR ((i.instance -> 'Status' -> 'IsArchived')::boolean = false AND i.created > _msgBoxInterval_gt OR (i.instance -> 'Status' -> 'IsArchived')::boolean = true AND i.lastchanged > _msgBoxInterval_gt))
AND (_msgBoxInterval_lte IS NULL OR ((i.instance -> 'Status' -> 'IsArchived')::boolean = false AND i.created <= _msgBoxInterval_lte OR (i.instance -> 'Status' -> 'IsArchived')::boolean = true AND i.lastchanged <= _msgBoxInterval_lte))
Expand Down
2 changes: 2 additions & 0 deletions src/Storage/Migration/v0.13/01-setup-tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE storage.instances ADD COLUMN IF NOT EXISTS altinnmainversion SMALLINT NOT NULL DEFAULT 3;
CREATE INDEX IF NOT EXISTS instances_partyid_altinnmainversion_lastchanged ON storage.instances(partyId, altinnmainversion, lastChanged);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This script is autogenerated from the tool DbTools. Do not edit manually.
16 changes: 16 additions & 0 deletions src/Storage/Models/InstanceQueryParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class InstanceQueryParameters
private const string _instanceOwnerPartyIdParameterName = "instanceOwner.partyId";
private const string _instanceOwnerPartyIdsParameterName = "instanceOwner.partyIds";
private const string _lastChangedParameterName = "lastChanged";
private const string _mainVersionExcludeParameterName = "mainVersionExclude";
private const string _mainVersionIncludeParameterName = "mainVersionInclude";
private const string _messageBoxIntervalParameterName = "msgBoxInterval";
private const string _orgParameterName = "org";
private const string _processEndEventParameterName = "process.endEvent";
Expand Down Expand Up @@ -150,6 +152,18 @@ public class InstanceQueryParameters
[FromHeader(Name = _instanceOwnerIdentifierHeaderName)]
public string InstanceOwnerIdentifier { get; set; }

/// <summary>
/// Gets or sets altinn version to include
/// </summary>
[FromQuery(Name = _mainVersionIncludeParameterName)]
public int? MainVersionInclude { get; set; }

/// <summary>
/// Gets or sets altinn version to exclude
/// </summary>
[FromQuery(Name = _mainVersionExcludeParameterName)]
public int? MainVersionExclude { get; set; }

/// <summary>
/// Gets or sets an array of application identifiers.
/// </summary>
Expand Down Expand Up @@ -207,6 +221,8 @@ public Dictionary<string, object> GeneratePostgreSQLParameters()
AddParamIfNotNull(postgresParams, _instanceOwnerPartyIdParameterName, InstanceOwnerPartyId);
AddParamIfNotNull(postgresParams, _statusIsActiveOrSoftDeletedParameterName, IsActiveOrSoftDeleted);
AddParamIfNotNull(postgresParams, _statusIsArchivedOrSoftDeletedParameterName, IsArchivedOrSoftDeleted);
AddParamIfNotNull(postgresParams, _mainVersionExcludeParameterName, MainVersionExclude);
AddParamIfNotNull(postgresParams, _mainVersionIncludeParameterName, MainVersionInclude);

AddParamIfNotEmpty(postgresParams, _orgParameterName, Org);
AddParamIfNotEmpty(postgresParams, _appIdsParameterName, AppIds);
Expand Down
7 changes: 5 additions & 2 deletions src/Storage/Repository/PgInstanceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Altinn.Platform.Storage.Repository
/// </summary>
public class PgInstanceRepository : IInstanceRepository
{
private const string _readSqlFilteredInitial = "select * from storage.readinstancefromquery_v4 (";
private const string _readSqlFilteredInitial = "select * from storage.readinstancefromquery_v5 (";
private readonly string _deleteSql = "select * from storage.deleteinstance ($1)";
private readonly string _insertSql = "call storage.insertinstance ($1, $2, $3, $4, $5, $6, $7, $8)";
private readonly string _updateSql = "select * from storage.updateinstance_v2 (@_alternateid, @_toplevelsimpleprops, @_datavalues, @_completeconfirmations, @_presentationtexts, @_status, @_substatus, @_process, @_lastchanged, @_taskid)";
Expand Down Expand Up @@ -195,11 +195,12 @@ private static string FormatManualFunctionCall(Dictionary<string, object> postgr
NpgsqlDbType.Bigint => $"{value}",
NpgsqlDbType.TimestampTz => $"{((DateTime)value != DateTime.MinValue ? "'" + ((DateTime)value).ToString(DateTimeHelper.Iso8601UtcFormat, CultureInfo.InvariantCulture) + "'::timestamptz" : "NULL")}",
NpgsqlDbType.Integer => $"{value}",
NpgsqlDbType.Smallint => $"{value}",
NpgsqlDbType.Boolean => $"{value}",
NpgsqlDbType.Text | NpgsqlDbType.Array => ArrayVariableFromText((string[])value),
NpgsqlDbType.Jsonb | NpgsqlDbType.Array => ArrayVariableFromJsonText((string[])value),
NpgsqlDbType.Integer | NpgsqlDbType.Array => ArrayVariableFromInteger((int?[])value),
_ => throw new NotImplementedException()
_ => throw new NotImplementedException(_paramTypes[name].ToString())
};
}
else
Expand Down Expand Up @@ -439,6 +440,8 @@ private static Instance ToExternal(Instance instance)
{ "_lastChanged_idx", NpgsqlDbType.TimestampTz },
{ "_lastChanged_lt", NpgsqlDbType.TimestampTz },
{ "_lastChanged_lte", NpgsqlDbType.TimestampTz },
{ "_mainVersionInclude", NpgsqlDbType.Smallint },
{ "_mainVersionExclude", NpgsqlDbType.Smallint },
{ "_msgBoxInterval_eq", NpgsqlDbType.TimestampTz },
{ "_msgBoxInterval_gt", NpgsqlDbType.TimestampTz },
{ "_msgBoxInterval_gte", NpgsqlDbType.TimestampTz },
Expand Down

0 comments on commit cddf83f

Please sign in to comment.