Skip to content

Commit a38edd6

Browse files
authored
Merge pull request #5488 from dfe-analytical-services/EES-5756
EES-5756 Set DataSetFileMeta geographic levels to null
2 parents 7f9ab7d + fb7fb2d commit a38edd6

File tree

12 files changed

+2376
-62
lines changed

12 files changed

+2376
-62
lines changed
+14-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using System.Collections.Generic;
21
using System.Linq;
32
using System.Threading;
43
using System.Threading.Tasks;
54
using GovUk.Education.ExploreEducationStatistics.Admin.Models;
6-
using GovUk.Education.ExploreEducationStatistics.Common.Extensions;
75
using GovUk.Education.ExploreEducationStatistics.Common.Model;
86
using GovUk.Education.ExploreEducationStatistics.Content.Model;
97
using GovUk.Education.ExploreEducationStatistics.Content.Model.Database;
@@ -21,18 +19,19 @@ public class MigrationResult
2119
{
2220
public bool IsDryRun;
2321
public int Processed;
24-
public string Errors;
22+
public int NumLeftToProcess;
2523
}
2624

27-
[HttpPut("bau/migrate-datasetfile-geographiclevels")]
25+
[HttpPut("bau/meta-geographic-levels-remove")]
2826
public async Task<MigrationResult> DataSetFileVersionGeographicLevelsMigration(
2927
[FromQuery] bool isDryRun = true,
3028
[FromQuery] int? num = null,
3129
CancellationToken cancellationToken = default)
3230
{
3331
var queryable = contentDbContext.Files
3432
.Where(f => f.Type == FileType.Data
35-
&& f.DataSetFileVersionGeographicLevels.Count == 0);
33+
&& f.DataSetFileMetaGeogLvlMigrated == false
34+
&& f.DataSetFileVersionGeographicLevels.Count > 0); // Paranoidly protecting against data set where geog lvls aren't migrated
3635

3736
if (num != null)
3837
{
@@ -42,30 +41,21 @@ public async Task<MigrationResult> DataSetFileVersionGeographicLevelsMigration(
4241
var files = queryable.ToList();
4342

4443
var numProcessed = 0;
45-
List<string> errors = [];
4644

4745
foreach (var file in files)
4846
{
49-
var meta = file.DataSetFileMeta;
50-
51-
if (meta == null)
47+
if (file.DataSetFileMeta != null)
5248
{
53-
errors.Add($"No DataSetFileMeta found for File {file.Id}");
54-
continue;
55-
}
56-
57-
var dataSetFileVersionGeographicLevels = meta!.GeographicLevels
58-
.Distinct()
59-
.Select(gl => new DataSetFileVersionGeographicLevel
49+
file.DataSetFileMeta = new DataSetFileMeta
6050
{
61-
DataSetFileVersionId = file.Id,
62-
GeographicLevel = gl,
63-
})
64-
.ToList();
65-
66-
contentDbContext.DataSetFileVersionGeographicLevels.AddRange(
67-
dataSetFileVersionGeographicLevels);
51+
GeographicLevels = null,
52+
TimePeriodRange = file.DataSetFileMeta.TimePeriodRange,
53+
Filters = file.DataSetFileMeta.Filters,
54+
Indicators = file.DataSetFileMeta.Indicators,
55+
};
56+
}
6857

58+
file.DataSetFileMetaGeogLvlMigrated = true;
6959
numProcessed++;
7060
}
7161

@@ -78,7 +68,7 @@ public async Task<MigrationResult> DataSetFileVersionGeographicLevelsMigration(
7868
{
7969
IsDryRun = isDryRun,
8070
Processed = numProcessed,
81-
Errors = errors.IsNullOrEmpty() ? "No errors" : errors.JoinToString("\n"),
71+
NumLeftToProcess = contentDbContext.Files.Count(f => f.DataSetFileMetaGeogLvlMigrated == false),
8272
};
8373
}
8474

0 commit comments

Comments
 (0)