diff --git a/src/Storage/Controllers/MessageboxInstancesController.cs b/src/Storage/Controllers/MessageboxInstancesController.cs
index ba2f3bfc..bc14591e 100644
--- a/src/Storage/Controllers/MessageboxInstancesController.cs
+++ b/src/Storage/Controllers/MessageboxInstancesController.cs
@@ -451,6 +451,11 @@ private static InstanceQueryParameters GetQueryParams(MessageBoxQueryModel query
queryParams.ArchiveReference = queryModel.ArchiveReference;
}
+ if (queryModel.FilterMigrated ?? false)
+ {
+ queryParams.MainVersionInclude = 3;
+ }
+
return queryParams;
}
diff --git a/src/Storage/Helpers/MessageBoxQueryModel.cs b/src/Storage/Helpers/MessageBoxQueryModel.cs
index c78e357d..61d70367 100644
--- a/src/Storage/Helpers/MessageBoxQueryModel.cs
+++ b/src/Storage/Helpers/MessageBoxQueryModel.cs
@@ -82,5 +82,11 @@ public class MessageBoxQueryModel
///
[JsonPropertyName("language")]
public string Language { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether to filter migrated a1/a2 elements
+ ///
+ [JsonPropertyName("filterMigrated")]
+ public bool? FilterMigrated { get; set; }
}
}
diff --git a/src/Storage/Migration/FunctionsAndProcedures/readinstancefromquery.sql b/src/Storage/Migration/FunctionsAndProcedures/readinstancefromquery.sql
index 219f2ea4..cb93febb 100644
--- a/src/Storage/Migration/FunctionsAndProcedures/readinstancefromquery.sql
+++ b/src/Storage/Migration/FunctionsAndProcedures/readinstancefromquery.sql
@@ -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,
@@ -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,
@@ -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))
diff --git a/src/Storage/Migration/v0.13/01-setup-tables.sql b/src/Storage/Migration/v0.13/01-setup-tables.sql
new file mode 100644
index 00000000..7462fe97
--- /dev/null
+++ b/src/Storage/Migration/v0.13/01-setup-tables.sql
@@ -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);
\ No newline at end of file
diff --git a/src/Storage/Migration/v0.13/02-functions-and-procedures.sql b/src/Storage/Migration/v0.13/02-functions-and-procedures.sql
new file mode 100644
index 00000000..eb981ed0
--- /dev/null
+++ b/src/Storage/Migration/v0.13/02-functions-and-procedures.sql
@@ -0,0 +1 @@
+-- This script is autogenerated from the tool DbTools. Do not edit manually.
diff --git a/src/Storage/Models/InstanceQueryParameters.cs b/src/Storage/Models/InstanceQueryParameters.cs
index a86e48ec..86e22934 100644
--- a/src/Storage/Models/InstanceQueryParameters.cs
+++ b/src/Storage/Models/InstanceQueryParameters.cs
@@ -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";
@@ -150,6 +152,18 @@ public class InstanceQueryParameters
[FromHeader(Name = _instanceOwnerIdentifierHeaderName)]
public string InstanceOwnerIdentifier { get; set; }
+ ///
+ /// Gets or sets altinn version to include
+ ///
+ [FromQuery(Name = _mainVersionIncludeParameterName)]
+ public int? MainVersionInclude { get; set; }
+
+ ///
+ /// Gets or sets altinn version to exclude
+ ///
+ [FromQuery(Name = _mainVersionExcludeParameterName)]
+ public int? MainVersionExclude { get; set; }
+
///
/// Gets or sets an array of application identifiers.
///
@@ -207,6 +221,8 @@ public Dictionary 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);
diff --git a/src/Storage/Repository/PgInstanceRepository.cs b/src/Storage/Repository/PgInstanceRepository.cs
index f2dc3472..c4af8314 100644
--- a/src/Storage/Repository/PgInstanceRepository.cs
+++ b/src/Storage/Repository/PgInstanceRepository.cs
@@ -25,7 +25,7 @@ namespace Altinn.Platform.Storage.Repository
///
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)";
@@ -195,11 +195,12 @@ private static string FormatManualFunctionCall(Dictionary 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
@@ -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 },