diff --git a/src/GovUk.Education.ExploreEducationStatistics.Common.Tests/Converters/EnumToEnumValueListConverterTests.cs b/src/GovUk.Education.ExploreEducationStatistics.Common.Tests/Converters/EnumToEnumValueListConverterTests.cs new file mode 100644 index 00000000000..980ea1ee350 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Common.Tests/Converters/EnumToEnumValueListConverterTests.cs @@ -0,0 +1,46 @@ +#nullable enable +using System.Diagnostics.CodeAnalysis; +using GovUk.Education.ExploreEducationStatistics.Common.Converters; +using GovUk.Education.ExploreEducationStatistics.Common.Database; +using Xunit; + +namespace GovUk.Education.ExploreEducationStatistics.Common.Tests.Converters; + +public abstract class EnumToEnumValueListConverterTests +{ + [SuppressMessage("ReSharper", "UnusedMember.Local")] + private enum Numbers + { + [EnumLabelValue("1", "Value-1")] One, + [EnumLabelValue("2", "Value-2")] Two, + [EnumLabelValue("3", "Value-3")] Three + } + + private readonly EnumToEnumValueListConverter _converter = new(); + + public class ConvertToProviderTests : EnumToEnumValueListConverterTests + { + [Fact] + public void Success() + { + var converted = _converter.ConvertToProviderTyped([Numbers.Two, Numbers.Three]); + + Assert.Equal(2, converted.Count); + Assert.Equal("Value-2", converted[0]); + Assert.Equal("Value-3", converted[1]); + } + } + + public class ConvertFromProviderTests : EnumToEnumValueListConverterTests + { + [Fact] + public void Success() + { + var converted = _converter.ConvertFromProviderTyped(["Value-1", "Value-2"]); + + Assert.Equal(2, converted.Count); + Assert.Equal(Numbers.One, converted[0]); + Assert.Equal(Numbers.Two, converted[1]); + } + } +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Common/Comparers/ListValueComparer.cs b/src/GovUk.Education.ExploreEducationStatistics.Common/Comparers/ListValueComparer.cs new file mode 100644 index 00000000000..9d24e604bec --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Common/Comparers/ListValueComparer.cs @@ -0,0 +1,19 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore.ChangeTracking; + +namespace GovUk.Education.ExploreEducationStatistics.Common.Comparers; + +public class ListValueComparer(IEqualityComparer? equalityComparer = null) + : ValueComparer>( + equalsExpression: (list, otherList) => list != null + && otherList != null + && list.SequenceEqual(otherList, equalityComparer), + hashCodeExpression: list => list.Aggregate(0, (acc, value) => + value != null + ? HashCode.Combine(acc, value!.GetHashCode()) + : acc), + snapshotExpression: list => list.ToList() + ); diff --git a/src/GovUk.Education.ExploreEducationStatistics.Common/Converters/EnumToEnumValueListConverter.cs b/src/GovUk.Education.ExploreEducationStatistics.Common/Converters/EnumToEnumValueListConverter.cs new file mode 100644 index 00000000000..721a59abf9a --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Common/Converters/EnumToEnumValueListConverter.cs @@ -0,0 +1,30 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace GovUk.Education.ExploreEducationStatistics.Common.Converters; + +public class EnumToEnumValueListConverter(ConverterMappingHints? mappingHints = null) + : ValueConverter, List>( + value => ToProvider(value), + value => FromProvider(value), + mappingHints + ) + where TEnum : Enum +{ + public static List ToProvider(IList values) + { + return values + .Select(EnumToEnumValueConverter.ToProvider) + .ToList(); + } + + public static List FromProvider(IList values) + { + return values + .Select(EnumToEnumValueConverter.FromProvider) + .ToList(); + } +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/DataSetVersionGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/DataSetVersionGeneratorExtensions.cs index 02b37912d6b..081d479a86b 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/DataSetVersionGeneratorExtensions.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/DataSetVersionGeneratorExtensions.cs @@ -150,30 +150,40 @@ public static Generator WithTimePeriodMetas( Func> metas) => generator.ForInstance(s => s.SetTimePeriodMetas(metas)); - public static Generator WithFilterChanges( + public static Generator WithFilterMetaChanges( this Generator generator, - IEnumerable filterChanges) - => generator.ForInstance(s => s.SetFilterChanges(filterChanges)); + IEnumerable metaChanges) + => generator.ForInstance(s => s.SetFilterMetaChanges(metaChanges)); - public static Generator WithFilterOptionChanges( + public static Generator WithFilterOptionMetaChanges( this Generator generator, - IEnumerable filterOptionChanges) - => generator.ForInstance(s => s.SetFilterOptionChanges(filterOptionChanges)); + IEnumerable metaChanges) + => generator.ForInstance(s => s.SetFilterOptionMetaChanges(metaChanges)); - public static Generator WithIndicatorChanges( + public static Generator WithGeographicLevelMetaChanges( this Generator generator, - IEnumerable indicatorChanges) - => generator.ForInstance(s => s.SetIndicatorChanges(indicatorChanges)); + GeographicLevelMetaChange metaChange) + => generator.ForInstance(s => s.SetGeographicLevelMetaChange(metaChange)); - public static Generator WithLocationChanges( + public static Generator WithIndicatorMetaChanges( this Generator generator, - IEnumerable locationChanges) - => generator.ForInstance(s => s.SetLocationChanges(locationChanges)); + IEnumerable metaChanges) + => generator.ForInstance(s => s.SetIndicatorMetaChanges(metaChanges)); - public static Generator WithTimePeriodChanges( + public static Generator WithLocationMetaChanges( this Generator generator, - IEnumerable timePeriodChanges) - => generator.ForInstance(s => s.SetTimePeriodChanges(timePeriodChanges)); + IEnumerable metaChanges) + => generator.ForInstance(s => s.SetLocationMetaChanges(metaChanges)); + + public static Generator WithLocationOptionMetaChanges( + this Generator generator, + IEnumerable metaChanges) + => generator.ForInstance(s => s.SetLocationOptionMetaChanges(metaChanges)); + + public static Generator WithTimePeriodMetaChanges( + this Generator generator, + IEnumerable metaChanges) + => generator.ForInstance(s => s.SetTimePeriodMetaChanges(metaChanges)); public static Generator WithPreviewTokens( this Generator generator, @@ -408,81 +418,110 @@ public static InstanceSetters SetTimePeriodMetas( } ); - public static InstanceSetters SetFilterChanges( + public static InstanceSetters SetFilterMetaChanges( this InstanceSetters instanceSetter, - IEnumerable filterChanges) + IEnumerable filterChanges) => instanceSetter.Set( - dsv => dsv.FilterChanges, + dsv => dsv.FilterMetaChanges, (_, dsv) => filterChanges.Select( - changeSet => + change => { - changeSet.DataSetVersionId = dsv.Id; - changeSet.DataSetVersion = dsv; - return changeSet; + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; } ) .ToList() ); - public static InstanceSetters SetFilterOptionChanges( + public static InstanceSetters SetFilterOptionMetaChanges( this InstanceSetters instanceSetter, - IEnumerable filterOptionChanges) + IEnumerable filterOptionChanges) => instanceSetter.Set( - dsv => dsv.FilterOptionChanges, + dsv => dsv.FilterOptionMetaChanges, (_, dsv) => filterOptionChanges.Select( - changeSet => + change => { - changeSet.DataSetVersionId = dsv.Id; - changeSet.DataSetVersion = dsv; - return changeSet; + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; } ) .ToList() ); + + public static InstanceSetters SetGeographicLevelMetaChange( + this InstanceSetters instanceSetter, + GeographicLevelMetaChange change) + => instanceSetter.Set( + dsv => dsv.GeographicLevelMetaChange, + (_, dsv) => + { + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; + } + ); - public static InstanceSetters SetIndicatorChanges( + public static InstanceSetters SetIndicatorMetaChanges( this InstanceSetters instanceSetter, - IEnumerable indicatorChanges) + IEnumerable indicatorChanges) => instanceSetter.Set( - dsv => dsv.IndicatorChanges, + dsv => dsv.IndicatorMetaChanges, (_, dsv) => indicatorChanges.Select( - changeSet => + change => { - changeSet.DataSetVersionId = dsv.Id; - changeSet.DataSetVersion = dsv; - return changeSet; + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; } ) .ToList() ); - public static InstanceSetters SetLocationChanges( + public static InstanceSetters SetLocationMetaChanges( this InstanceSetters instanceSetter, - IEnumerable locationChanges) + IEnumerable locationChanges) => instanceSetter.Set( - dsv => dsv.LocationChanges, + dsv => dsv.LocationMetaChanges, (_, dsv) => locationChanges.Select( - changeSet => + change => + { + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; + } + ) + .ToList() + ); + + public static InstanceSetters SetLocationOptionMetaChanges( + this InstanceSetters instanceSetter, + IEnumerable locationOptionChanges) + => instanceSetter.Set( + dsv => dsv.LocationOptionMetaChanges, + (_, dsv) => locationOptionChanges.Select( + change => { - changeSet.DataSetVersionId = dsv.Id; - changeSet.DataSetVersion = dsv; - return changeSet; + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; } ) .ToList() ); - public static InstanceSetters SetTimePeriodChanges( + public static InstanceSetters SetTimePeriodMetaChanges( this InstanceSetters instanceSetter, - IEnumerable timePeriodChanges) + IEnumerable timePeriodChanges) => instanceSetter.Set( - dsv => dsv.TimePeriodChanges, + dsv => dsv.TimePeriodMetaChanges, (_, dsv) => timePeriodChanges.Select( - changeSet => + change => { - changeSet.DataSetVersionId = dsv.Id; - changeSet.DataSetVersion = dsv; - return changeSet; + change.DataSetVersion = dsv; + change.DataSetVersionId = dsv.Id; + return change; } ) .ToList() diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/FilterMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/FilterMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..286c4e6df12 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/FilterMetaChangeGeneratorExtensions.cs @@ -0,0 +1,104 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class FilterMetaChangeGeneratorExtensions +{ + public static Generator DefaultFilterMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults(this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + FilterMeta? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentStateId( + this Generator generator, + int? currentStateId) + => generator.ForInstance(s => s.SetCurrentStateId(currentStateId)); + + public static Generator WithPreviousState( + this Generator generator, + FilterMeta? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousStateId( + this Generator generator, + int? previousStateId) + => generator.ForInstance(s => s.SetPreviousStateId(previousStateId)); + + public static InstanceSetters SetDefaults(this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + FilterMeta? currentState) + => setters.SetCurrentState(() => currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters + .Set(c => c.CurrentState, currentState) + .Set(c => c.CurrentStateId, (_, f) => f.CurrentState?.Id); + + public static InstanceSetters SetCurrentStateId( + this InstanceSetters setters, + int? currentStateId) + => setters.Set(c => c.CurrentStateId, currentStateId); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + FilterMeta? previousState) + => setters.SetPreviousState(() => previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters + .Set(c => c.PreviousState, previousState) + .Set(c => c.PreviousStateId, (_, f) => f.PreviousState?.Id); + + public static InstanceSetters SetPreviousStateId( + this InstanceSetters setters, + int? previousStateId) + => setters.Set(c => c.PreviousStateId, previousStateId); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/FilterOptionMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/FilterOptionMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..b4d6462b1b0 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/FilterOptionMetaChangeGeneratorExtensions.cs @@ -0,0 +1,147 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class FilterOptionMetaChangeGeneratorExtensions +{ + public static Generator DefaultFilterOptionMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults(this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + FilterOptionMetaLink? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + FilterOptionMetaChange.State? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithPreviousState( + this Generator generator, + FilterOptionMetaLink? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + FilterOptionMetaChange.State? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static InstanceSetters SetDefaults( + this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + FilterOptionMetaLink? currentState) + => setters.SetCurrentState(() => currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + { + var current = currentState(); + + return current is not null + ? setters.SetCurrentState( + new FilterOptionMetaChange.State + { + MetaId = current.MetaId, + OptionId = current.OptionId, + PublicId = current.PublicId + } + ) + : setters; + } + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + FilterOptionMetaChange.State? currentState) + => setters.Set(c => c.CurrentState, currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters.Set(c => c.CurrentState, currentState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + FilterOptionMetaLink? previousState) + => setters.SetPreviousState(() => previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + { + var previous = previousState(); + + return previous is not null + ? setters.SetPreviousState( + new FilterOptionMetaChange.State + { + MetaId = previous.MetaId, + OptionId = previous.OptionId, + PublicId = previous.PublicId + } + ) + : setters; + } + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + FilterOptionMetaChange.State? previousState) + => setters.Set(c => c.PreviousState, previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters.Set(c => c.PreviousState, previousState); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/GeographicLevelMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/GeographicLevelMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..6bbb5b180ac --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/GeographicLevelMetaChangeGeneratorExtensions.cs @@ -0,0 +1,106 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class GeographicLevelMetaChangeGeneratorExtensions +{ + public static Generator DefaultGeographicLevelMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults( + this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + GeographicLevelMeta? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentStateId( + this Generator generator, + int? currentStateId) + => generator.ForInstance(s => s.SetCurrentStateId(currentStateId)); + + public static Generator WithPreviousState( + this Generator generator, + GeographicLevelMeta? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousStateId( + this Generator generator, + int? previousStateId) + => generator.ForInstance(s => s.SetPreviousStateId(previousStateId)); + + public static InstanceSetters SetDefaults( + this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + GeographicLevelMeta? currentState) + => setters.SetCurrentState(() => currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters + .Set(c => c.CurrentState, currentState) + .Set(c => c.CurrentStateId, (_, f) => f.CurrentState?.Id); + + public static InstanceSetters SetCurrentStateId( + this InstanceSetters setters, + int? currentStateId) + => setters.Set(c => c.CurrentStateId, currentStateId); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + GeographicLevelMeta? currentState) + => setters.SetPreviousState(() => currentState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters + .Set(c => c.PreviousState, previousState) + .Set(c => c.PreviousStateId, (_, f) => f.PreviousState?.Id); + + public static InstanceSetters SetPreviousStateId( + this InstanceSetters setters, + int? previousStateId) + => setters.Set(c => c.PreviousStateId, previousStateId); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/IndicatorMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/IndicatorMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..a015fc185ff --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/IndicatorMetaChangeGeneratorExtensions.cs @@ -0,0 +1,104 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class IndicatorMetaChangeGeneratorExtensions +{ + public static Generator DefaultIndicatorMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults(this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + IndicatorMeta? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentStateId( + this Generator generator, + int? currentStateId) + => generator.ForInstance(s => s.SetCurrentStateId(currentStateId)); + + public static Generator WithPreviousState( + this Generator generator, + IndicatorMeta? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousStateId( + this Generator generator, + int? previousStateId) + => generator.ForInstance(s => s.SetPreviousStateId(previousStateId)); + + public static InstanceSetters SetDefaults(this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + IndicatorMeta? currentState) + => setters.SetCurrentState(() => currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters + .Set(c => c.CurrentState, currentState) + .Set(c => c.CurrentStateId, (_, f) => f.CurrentState?.Id); + + public static InstanceSetters SetCurrentStateId( + this InstanceSetters setters, + int? currentStateId) + => setters.Set(c => c.CurrentStateId, currentStateId); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + IndicatorMeta? previousState) + => setters.SetPreviousState(() => previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters + .Set(c => c.PreviousState, previousState) + .Set(c => c.PreviousStateId, (_, f) => f.PreviousState?.Id); + + public static InstanceSetters SetPreviousStateId( + this InstanceSetters setters, + int? previousStateId) + => setters.Set(c => c.PreviousStateId, previousStateId); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/LocationMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/LocationMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..68d2a943cd7 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/LocationMetaChangeGeneratorExtensions.cs @@ -0,0 +1,104 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class LocationMetaChangeGeneratorExtensions +{ + public static Generator DefaultLocationMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults(this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + LocationMeta? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentStateId( + this Generator generator, + int? currentStateId) + => generator.ForInstance(s => s.SetCurrentStateId(currentStateId)); + + public static Generator WithPreviousState( + this Generator generator, + LocationMeta? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousStateId( + this Generator generator, + int? previousStateId) + => generator.ForInstance(s => s.SetPreviousStateId(previousStateId)); + + public static InstanceSetters SetDefaults(this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + LocationMeta? currentState) + => setters.SetCurrentState(() => currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters + .Set(c => c.CurrentState, currentState) + .Set(c => c.CurrentStateId, (_, f) => f.CurrentState?.Id); + + public static InstanceSetters SetCurrentStateId( + this InstanceSetters setters, + int? currentStateId) + => setters.Set(c => c.CurrentStateId, currentStateId); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + LocationMeta? previousState) + => setters.SetPreviousState(() => previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters + .Set(c => c.PreviousState, previousState) + .Set(c => c.PreviousStateId, (_, f) => f.PreviousState?.Id); + + public static InstanceSetters SetPreviousStateId( + this InstanceSetters setters, + int? previousStateId) + => setters.Set(c => c.PreviousStateId, previousStateId); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/LocationOptionMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/LocationOptionMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..93e5b998152 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/LocationOptionMetaChangeGeneratorExtensions.cs @@ -0,0 +1,148 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class LocationOptionMetaChangeGeneratorExtensions +{ + public static Generator DefaultLocationOptionMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults(this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + LocationOptionMetaLink? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + LocationOptionMetaChange.State? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithPreviousState( + this Generator generator, + LocationOptionMetaLink? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + LocationOptionMetaChange.State? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static InstanceSetters SetDefaults( + this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + LocationOptionMetaLink? currentState) + => setters.SetCurrentState(() => currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + { + var current = currentState(); + + return current is not null + ? setters + .SetCurrentState( + new LocationOptionMetaChange.State + { + MetaId = current.MetaId, + OptionId = current.OptionId + + } + ) + : setters; + } + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + LocationOptionMetaChange.State? currentState) + => setters.Set(c => c.CurrentState, currentState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters.Set(c => c.CurrentState, currentState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + LocationOptionMetaLink? previousState) + => setters.SetPreviousState(() => previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + { + var previous = previousState(); + + return previous is not null + ? setters + .SetPreviousState( + new LocationOptionMetaChange.State + { + MetaId = previous.MetaId, + OptionId = previous.OptionId + } + ) + : setters; + } + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + LocationOptionMetaChange.State? previousState) + => setters.Set(c => c.PreviousState, previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters.Set(c => c.PreviousState, previousState); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/TimePeriodMetaChangeGeneratorExtensions.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/TimePeriodMetaChangeGeneratorExtensions.cs new file mode 100644 index 00000000000..a7c5d7607e8 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests/Fixtures/TimePeriodMetaChangeGeneratorExtensions.cs @@ -0,0 +1,104 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Tests.Fixtures; + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Tests.Fixtures; + +public static class TimePeriodMetaChangeGeneratorExtensions +{ + public static Generator DefaultTimePeriodMetaChange(this DataFixture fixture) + => fixture + .Generator() + .WithDefaults(); + + public static Generator WithDefaults(this Generator generator) + => generator.ForInstance(s => s.SetDefaults()); + + public static Generator WithDataSetVersion( + this Generator generator, + Func dataSetVersion) + => generator.ForInstance(s => s.SetDataSetVersion(dataSetVersion)); + + public static Generator WithDataSetVersionId( + this Generator generator, + Guid dataSetVersionId) + => generator.ForInstance(s => s.SetDataSetVersionId(dataSetVersionId)); + + public static Generator WithCurrentState( + this Generator generator, + TimePeriodMeta? currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentState( + this Generator generator, + Func currentState) + => generator.ForInstance(s => s.SetCurrentState(currentState)); + + public static Generator WithCurrentStateId( + this Generator generator, + int? currentStateId) + => generator.ForInstance(s => s.SetCurrentStateId(currentStateId)); + + public static Generator WithPreviousState( + this Generator generator, + TimePeriodMeta? previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousState( + this Generator generator, + Func previousState) + => generator.ForInstance(s => s.SetPreviousState(previousState)); + + public static Generator WithPreviousStateId( + this Generator generator, + int? previousStateId) + => generator.ForInstance(s => s.SetPreviousStateId(previousStateId)); + + public static InstanceSetters SetDefaults(this InstanceSetters setters) + => setters + .SetDefault(c => c.DataSetVersionId); + + public static InstanceSetters SetDataSetVersion( + this InstanceSetters setters, + Func dataSetVersion) + => setters + .Set(c => c.DataSetVersion, dataSetVersion) + .Set(c => c.DataSetVersionId, (_, f) => f.DataSetVersion.Id); + + public static InstanceSetters SetDataSetVersionId( + this InstanceSetters setters, + Guid dataSetVersionId) + => setters.Set(c => c.DataSetVersionId, dataSetVersionId); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + TimePeriodMeta? previousState) + => setters.SetCurrentState(() => previousState); + + public static InstanceSetters SetCurrentState( + this InstanceSetters setters, + Func currentState) + => setters + .Set(c => c.CurrentState, currentState) + .Set(c => c.CurrentStateId, (_, f) => f.CurrentState?.Id); + + public static InstanceSetters SetCurrentStateId( + this InstanceSetters setters, + int? currentStateId) + => setters.Set(c => c.CurrentStateId, currentStateId); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + TimePeriodMeta? previousState) + => setters.SetPreviousState(() => previousState); + + public static InstanceSetters SetPreviousState( + this InstanceSetters setters, + Func previousState) + => setters + .Set(c => c.PreviousState, previousState) + .Set(c => c.PreviousStateId, (_, f) => f.PreviousState?.Id); + + public static InstanceSetters SetPreviousStateId( + this InstanceSetters setters, + int? previousStateId) + => setters.Set(c => c.PreviousStateId, previousStateId); +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Change.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Change.cs index 486be1011c7..b40959788fc 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Change.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Change.cs @@ -1,14 +1,168 @@ -using GovUk.Education.ExploreEducationStatistics.Common.Utils; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; -public class Change +public abstract class Change { - public Guid Identifier { get; set; } = UuidUtils.UuidV7(); + public long Id { get; set; } - public required ChangeType Type { get; set; } + public DataSetVersion DataSetVersion { get; set; } = null!; - public TState? CurrentState { get; set; } + public required Guid DataSetVersionId { get; set; } - public TState? PreviousState { get; set; } + public TEntity? CurrentState { get; set; } + + public TEntity? PreviousState { get; set; } + + internal abstract class BaseConfig : IEntityTypeConfiguration + where TChange : Change + where TChangeEntity : class + { + public virtual void Configure(EntityTypeBuilder builder) + { + builder + .HasOne(c => c.CurrentState) + .WithMany(); + + builder + .HasOne(c => c.PreviousState) + .WithMany(); + + builder.Navigation(c => c.PreviousState).AutoInclude(); + builder.Navigation(c => c.CurrentState).AutoInclude(); + } + } +} + +public class FilterMetaChange : Change +{ + public int? CurrentStateId { get; set; } + + public int? PreviousStateId { get; set; } + + internal class Config : BaseConfig; +} + +public class FilterOptionMetaChange : Change +{ + internal class Config : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.OwnsOne(c => c.PreviousState, b => + { + b.HasOne(s => s.Meta) + .WithMany(); + + b.HasOne(s => s.Option) + .WithMany(); + + b.Navigation(s => s.Option).AutoInclude(); + }); + + builder.OwnsOne(c => c.CurrentState, b => + { + b.HasOne(s => s.Meta) + .WithMany(); + + b.HasOne(s => s.Option) + .WithMany(); + + b.Navigation(s => s.Option).AutoInclude(); + }); + } + } + + public class State + { + public FilterMeta Meta { get; set; } = null!; + + public required int MetaId { get; set; } + + public FilterOptionMeta Option { get; set; } = null!; + + public required int OptionId { get; set; } + + public required string PublicId { get; set; } + } +} + +public class GeographicLevelMetaChange : Change +{ + public int? CurrentStateId { get; set; } + + public int? PreviousStateId { get; set; } + + internal class Config : BaseConfig; +} + +public class IndicatorMetaChange : Change +{ + public int? CurrentStateId { get; set; } + + public int? PreviousStateId { get; set; } + + internal class Config : BaseConfig; +} + +public class LocationMetaChange : Change + +{ + public int? CurrentStateId { get; set; } + + public int? PreviousStateId { get; set; } + + internal class Config : BaseConfig; +} + +public class LocationOptionMetaChange : Change +{ + internal class Config : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.OwnsOne(c => c.PreviousState, b => + { + b.HasOne(s => s.Meta) + .WithMany(); + + b.HasOne(s => s.Option) + .WithMany(); + + b.Navigation(s => s.Option).AutoInclude(); + }); + + builder.OwnsOne(c => c.CurrentState, b => + { + b.HasOne(s => s.Meta) + .WithMany(); + + b.HasOne(s => s.Option) + .WithMany(); + + b.Navigation(s => s.Option).AutoInclude(); + }); + } + } + + public class State + { + public LocationMeta Meta { get; set; } = null!; + + public required int MetaId { get; set; } + + public LocationOptionMeta Option { get; set; } = null!; + + public required int OptionId { get; set; } + } +} + +public class TimePeriodMetaChange : Change +{ + public int? CurrentStateId { get; set; } + + public int? PreviousStateId { get; set; } + + internal class Config : BaseConfig; } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/ChangeSet.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/ChangeSet.cs deleted file mode 100644 index 040ed55becb..00000000000 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/ChangeSet.cs +++ /dev/null @@ -1,146 +0,0 @@ -using GovUk.Education.ExploreEducationStatistics.Common.Converters; -using GovUk.Education.ExploreEducationStatistics.Common.Database; -using GovUk.Education.ExploreEducationStatistics.Common.Model; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - -namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; - -public abstract class ChangeSet : ICreatedUpdatedTimestamps -{ - public Guid Id { get; set; } - - public DataSetVersion DataSetVersion { get; set; } = null!; - - public required Guid DataSetVersionId { get; set; } - - public required List> Changes { get; set; } - - public DateTimeOffset Created { get; set; } - - public DateTimeOffset? Updated { get; set; } -} - -public class ChangeSetFilters : ChangeSet -{ - internal class Config : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.Property(cs => cs.Id) - .HasValueGenerator(); - - builder.OwnsMany(cs => cs.Changes, cs => - { - cs.ToJson(); - cs.Property(c => c.Identifier).HasJsonPropertyName("Id"); - cs.Property(c => c.Type).HasConversion(); - cs.OwnsOne(c => c.CurrentState); - cs.OwnsOne(c => c.PreviousState); - }); - } - } -} - -public class ChangeSetFilterOptions : ChangeSet -{ - internal class Config : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.Property(cs => cs.Id) - .HasValueGenerator(); - - builder.OwnsMany(cs => cs.Changes, cs => - { - cs.ToJson(); - cs.Property(c => c.Identifier).HasJsonPropertyName("Id"); - cs.Property(c => c.Type).HasConversion(); - cs.OwnsOne(c => c.CurrentState); - cs.OwnsOne(c => c.PreviousState); - }); - } - } -} - -public class ChangeSetIndicators : ChangeSet -{ - public class Config : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.Property(cs => cs.Id) - .HasValueGenerator(); - - builder.OwnsMany(cs => cs.Changes, cs => - { - cs.ToJson(); - cs.Property(c => c.Identifier).HasJsonPropertyName("Id"); - cs.Property(c => c.Type).HasConversion(); - cs.OwnsOne(c => c.CurrentState, s => - { - s.Property(sb => sb.Unit) - .HasConversion(new EnumToEnumValueConverter()); - }); - cs.OwnsOne(c => c.PreviousState, s => - { - s.Property(sb => sb.Unit) - .HasConversion(new EnumToEnumValueConverter()); - }); - }); - } - } -} - -public class ChangeSetLocations : ChangeSet -{ - internal class Config : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.Property(cs => cs.Id) - .HasValueGenerator(); - - builder.OwnsMany(cs => cs.Changes, cs => - { - cs.ToJson(); - cs.Property(c => c.Identifier).HasJsonPropertyName("Id"); - cs.Property(c => c.Type).HasConversion(); - cs.OwnsOne(c => c.CurrentState, s => - { - s.Property(sb => sb.Level).HasConversion(); - }); - cs.OwnsOne(c => c.PreviousState); - }); - } - } -} - -public class ChangeSetTimePeriods : ChangeSet -{ - internal class Config : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.Property(cs => cs.Id) - .HasValueGenerator(); - - builder.OwnsMany(cs => cs.Changes, cs => - { - cs.ToJson(); - cs.Property(c => c.Identifier).HasJsonPropertyName("Id"); - cs.Property(c => c.Type).HasConversion(); - cs.OwnsOne(c => c.CurrentState, s => - { - s.Property(sb => sb.Code) - .HasConversion(new EnumToEnumValueConverter()); - }); - cs.OwnsOne(c => c.PreviousState, s => - { - s.Property(sb => sb.Code) - .HasConversion(new EnumToEnumValueConverter()); - }); - }); - } - } -} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/DataSetVersion.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/DataSetVersion.cs index 0f6705ef056..2195eccc77c 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/DataSetVersion.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/DataSetVersion.cs @@ -47,15 +47,19 @@ public class DataSetVersion : ICreatedUpdatedTimestamps TimePeriodMetas { get; set; } = []; - public List FilterChanges { get; set; } = []; + public List FilterMetaChanges { get; set; } = []; - public List FilterOptionChanges { get; set; } = []; + public List FilterOptionMetaChanges { get; set; } = []; - public List IndicatorChanges { get; set; } = []; + public GeographicLevelMetaChange? GeographicLevelMetaChange { get; set; } - public List LocationChanges { get; set; } = []; + public List IndicatorMetaChanges { get; set; } = []; - public List TimePeriodChanges { get; set; } = []; + public List LocationMetaChanges { get; set; } = []; + + public List LocationOptionMetaChanges { get; set; } = []; + + public List TimePeriodMetaChanges { get; set; } = []; public List Imports { get; set; } = []; diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Database/PublicDataDbContext.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Database/PublicDataDbContext.cs index 0d01e931e7b..f34dd5dd3ee 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Database/PublicDataDbContext.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Database/PublicDataDbContext.cs @@ -65,11 +65,13 @@ SELECT setval('public."{sequenceName}"', {value}) AS "Value" public DbSet FilterOptionMetaLinks { get; init; } = null!; public DbSet IndicatorMetas { get; init; } = null!; public DbSet TimePeriodMetas { get; init; } = null!; - public DbSet ChangeSetFilters { get; init; } = null!; - public DbSet ChangeSetFilterOptions { get; init; } = null!; - public DbSet ChangeSetIndicators { get; init; } = null!; - public DbSet ChangeSetLocations { get; init; } = null!; - public DbSet ChangeSetTimePeriods { get; init; } = null!; + public DbSet FilterMetaChanges { get; init; } = null!; + public DbSet FilterOptionMetaChanges { get; init; } = null!; + public DbSet GeographicLevelMetaChanges { get; init; } = null!; + public DbSet IndicatorMetaChanges { get; init; } = null!; + public DbSet LocationMetaChanges { get; init; } = null!; + public DbSet LocationOptionMetaChanges { get; init; } = null!; + public DbSet TimePeriodMetaChanges { get; init; } = null!; public DbSet PreviewTokens { get; init; } = null!; public DbSet JsonFragments { get; init; } = null!; diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/FilterChangeState.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/FilterChangeState.cs deleted file mode 100644 index c613028fd5a..00000000000 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/FilterChangeState.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; - -public class FilterChangeState -{ - public required string Id { get; set; } - - public required string Label { get; set; } - - public string Hint { get; set; } = string.Empty; -} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/FilterOptionChangeState.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/FilterOptionChangeState.cs deleted file mode 100644 index 4b9a68619f8..00000000000 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/FilterOptionChangeState.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; - -public class FilterOptionChangeState -{ - public required string Id { get; set; } - - public required string Label { get; set; } - - public required string FilterId { get; set; } - - public bool? IsAggregate { get; set; } = null!; -} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/GeographicLevelMeta.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/GeographicLevelMeta.cs index 1754880ada7..933f1d9a2de 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/GeographicLevelMeta.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/GeographicLevelMeta.cs @@ -1,8 +1,8 @@ +using GovUk.Education.ExploreEducationStatistics.Common.Comparers; using GovUk.Education.ExploreEducationStatistics.Common.Converters; using GovUk.Education.ExploreEducationStatistics.Common.Model; using GovUk.Education.ExploreEducationStatistics.Common.Model.Data; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; @@ -28,17 +28,9 @@ public void Configure(EntityTypeBuilder builder) builder.Property(msb => msb.Levels) .HasColumnType("text[]") .HasConversion( - value => value - .Select(EnumToEnumValueConverter.ToProvider) - .ToList(), - value => value - .Select(EnumToEnumValueConverter.FromProvider) - .ToList(), - new ValueComparer>( - (c1, c2) => c1!.SequenceEqual(c2!), - c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), - c => c.ToList()) - ); + new EnumToEnumValueListConverter(), + new ListValueComparer() + ); } } } diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/IndicatorChangeState.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/IndicatorChangeState.cs deleted file mode 100644 index 274f03829b7..00000000000 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/IndicatorChangeState.cs +++ /dev/null @@ -1,14 +0,0 @@ -using GovUk.Education.ExploreEducationStatistics.Common.Model; - -namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; - -public class IndicatorChangeState -{ - public required string Id { get; set; } - - public required string Label { get; set; } - - public IndicatorUnit? Unit { get; set; } - - public byte? DecimalPlaces { get; set; } -} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/LocationChangeState.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/LocationChangeState.cs deleted file mode 100644 index 3779f5d1a94..00000000000 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/LocationChangeState.cs +++ /dev/null @@ -1,14 +0,0 @@ -using GovUk.Education.ExploreEducationStatistics.Common.Model.Data; - -namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; - -public class LocationChangeState -{ - public required string Id { get; set; } - - public required string Label { get; set; } - - public required string Code { get; set; } - - public required GeographicLevel Level { get; set; } -} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/20240725104818_EES4950_RemodelChangeTables.Designer.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/20240725104818_EES4950_RemodelChangeTables.Designer.cs new file mode 100644 index 00000000000..a4e066c28a2 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/20240725104818_EES4950_RemodelChangeTables.Designer.cs @@ -0,0 +1,1407 @@ +// +using System; +using System.Collections.Generic; +using GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Migrations +{ + [DbContext(typeof(PublicDataDbContext))] + [Migration("20240725104818_EES4950_RemodelChangeTables")] + partial class EES4950_RemodelChangeTables + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.HasSequence("FilterOptionMetaLink_seq"); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Common.Model.JsonBool", b => + { + b.Property("BoolValue") + .HasColumnType("boolean"); + + b.ToTable((string)null); + + b.ToView(null, (string)null); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Common.Model.JsonFragment", b => + { + b.Property("JsonValue") + .HasColumnType("text"); + + b.ToTable((string)null); + + b.ToView(null, (string)null); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("LatestDraftVersionId") + .HasColumnType("uuid"); + + b.Property("LatestLiveVersionId") + .HasColumnType("uuid"); + + b.Property("PublicationId") + .HasColumnType("uuid"); + + b.Property("Published") + .HasColumnType("timestamp with time zone"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("Summary") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupersedingDataSetId") + .HasColumnType("uuid"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.Property("Withdrawn") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("LatestDraftVersionId") + .IsUnique(); + + b.HasIndex("LatestLiveVersionId") + .IsUnique(); + + b.HasIndex("SupersedingDataSetId"); + + b.ToTable("DataSets"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetId") + .HasColumnType("uuid"); + + b.Property("Notes") + .IsRequired() + .HasColumnType("text"); + + b.Property("Published") + .HasColumnType("timestamp with time zone"); + + b.Property("ReleaseFileId") + .HasColumnType("uuid"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("TotalResults") + .HasColumnType("bigint"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.Property("VersionMajor") + .HasColumnType("integer"); + + b.Property("VersionMinor") + .HasColumnType("integer"); + + b.Property("VersionPatch") + .HasColumnType("integer"); + + b.Property("Withdrawn") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ReleaseFileId"); + + b.HasIndex("DataSetId", "VersionMajor", "VersionMinor", "VersionPatch") + .IsUnique() + .HasDatabaseName("IX_DataSetVersions_DataSetId_VersionNumber"); + + b.ToTable("DataSetVersions"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersionImport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Completed") + .HasColumnType("timestamp with time zone"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("InstanceId") + .HasColumnType("uuid"); + + b.Property("Stage") + .IsRequired() + .HasColumnType("text"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("InstanceId") + .IsUnique(); + + b.ToTable("DataSetVersionImports"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersionMapping", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("FilterMappingPlan") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("FilterMappingsComplete") + .HasColumnType("boolean"); + + b.Property("LocationMappingPlan") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("LocationMappingsComplete") + .HasColumnType("boolean"); + + b.Property("SourceDataSetVersionId") + .HasColumnType("uuid"); + + b.Property("TargetDataSetVersionId") + .HasColumnType("uuid"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("SourceDataSetVersionId") + .IsUnique() + .HasDatabaseName("IX_DataSetVersionMappings_SourceDataSetVersionId"); + + b.HasIndex("TargetDataSetVersionId") + .IsUnique() + .HasDatabaseName("IX_DataSetVersionMappings_TargetDataSetVersionId"); + + b.ToTable("DataSetVersionMappings"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("Hint") + .IsRequired() + .HasColumnType("text"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("PublicId") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId", "PublicId") + .IsUnique(); + + b.ToTable("FilterMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("FilterMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("IsAggregate") + .HasColumnType("boolean"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("FilterOptionMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId"); + + b.ToTable("FilterOptionMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaLink", b => + { + b.Property("MetaId") + .HasColumnType("integer"); + + b.Property("OptionId") + .HasColumnType("integer"); + + b.Property("PublicId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("MetaId", "OptionId"); + + b.HasIndex("OptionId"); + + b.HasIndex("PublicId"); + + b.HasIndex("MetaId", "PublicId") + .IsUnique(); + + b.ToTable("FilterOptionMetaLinks"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property>("Levels") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId") + .IsUnique(); + + b.ToTable("GeographicLevelMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId") + .IsUnique(); + + b.HasIndex("PreviousStateId"); + + b.ToTable("GeographicLevelMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("DecimalPlaces") + .HasColumnType("smallint"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("PublicId") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Unit") + .HasColumnType("text"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId", "PublicId") + .IsUnique(); + + b.ToTable("IndicatorMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("IndicatorMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("Level") + .IsRequired() + .HasMaxLength(5) + .HasColumnType("character varying(5)"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId", "Level") + .IsUnique(); + + b.ToTable("LocationMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("LocationMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .HasColumnType("text"); + + b.Property("LaEstab") + .HasColumnType("text"); + + b.Property("Label") + .IsRequired() + .HasColumnType("text"); + + b.Property("OldCode") + .HasColumnType("text"); + + b.Property("PublicId") + .IsRequired() + .HasColumnType("text"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("Ukprn") + .HasColumnType("text"); + + b.Property("Urn") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("Code"); + + b.HasIndex("LaEstab"); + + b.HasIndex("OldCode"); + + b.HasIndex("PublicId") + .IsUnique(); + + b.HasIndex("Type"); + + b.HasIndex("Ukprn"); + + b.HasIndex("Urn"); + + b.HasIndex(new[] { "Type", "Label", "Code", "OldCode", "Urn", "LaEstab", "Ukprn" }, "IX_LocationOptionMetas_All") + .IsUnique(); + + NpgsqlIndexBuilderExtensions.AreNullsDistinct(b.HasIndex(new[] { "Type", "Label", "Code", "OldCode", "Urn", "LaEstab", "Ukprn" }, "IX_LocationOptionMetas_All"), false); + + b.ToTable("LocationOptionMetas"); + + b.HasDiscriminator("Type").HasValue("LocationOptionMeta"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId"); + + b.ToTable("LocationOptionMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaLink", b => + { + b.Property("MetaId") + .HasColumnType("integer"); + + b.Property("OptionId") + .HasColumnType("integer"); + + b.HasKey("MetaId", "OptionId"); + + b.HasIndex("OptionId"); + + b.ToTable("LocationOptionMetaLinks"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.PreviewToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedByUserId") + .HasColumnType("uuid"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("Expiry") + .HasColumnType("timestamp with time zone"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId"); + + b.ToTable("PreviewTokens"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMeta", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("Created") + .HasColumnType("timestamp with time zone"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("Period") + .IsRequired() + .HasColumnType("text"); + + b.Property("Updated") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId", "Code", "Period") + .IsUnique(); + + b.ToTable("TimePeriodMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("TimePeriodMetaChanges"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationCodedOptionMeta", b => + { + b.HasBaseType("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta"); + + b.HasDiscriminator().HasValue("CODE"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationLocalAuthorityOptionMeta", b => + { + b.HasBaseType("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta"); + + b.HasDiscriminator().HasValue("LA"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationProviderOptionMeta", b => + { + b.HasBaseType("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta"); + + b.HasDiscriminator().HasValue("PROV"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationRscRegionOptionMeta", b => + { + b.HasBaseType("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta"); + + b.HasDiscriminator().HasValue("RSC"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationSchoolOptionMeta", b => + { + b.HasBaseType("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta"); + + b.HasDiscriminator().HasValue("SCH"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "LatestDraftVersion") + .WithOne() + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "LatestDraftVersionId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "LatestLiveVersion") + .WithOne() + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "LatestLiveVersionId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "SupersedingDataSet") + .WithMany() + .HasForeignKey("SupersedingDataSetId"); + + b.Navigation("LatestDraftVersion"); + + b.Navigation("LatestLiveVersion"); + + b.Navigation("SupersedingDataSet"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "DataSet") + .WithMany("Versions") + .HasForeignKey("DataSetId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersionMetaSummary", "MetaSummary", b1 => + { + b1.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b1.Property>("Filters") + .IsRequired() + .HasColumnType("text[]"); + + b1.Property>("GeographicLevels") + .IsRequired() + .HasColumnType("text[]"); + + b1.Property>("Indicators") + .IsRequired() + .HasColumnType("text[]"); + + b1.HasKey("DataSetVersionId"); + + b1.ToTable("DataSetVersions"); + + b1.ToJson("MetaSummary"); + + b1.WithOwner() + .HasForeignKey("DataSetVersionId"); + + b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodRange", "TimePeriodRange", b2 => + { + b2.Property("DataSetVersionMetaSummaryDataSetVersionId") + .HasColumnType("uuid"); + + b2.HasKey("DataSetVersionMetaSummaryDataSetVersionId"); + + b2.ToTable("DataSetVersions"); + + b2.WithOwner() + .HasForeignKey("DataSetVersionMetaSummaryDataSetVersionId"); + + b2.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodRangeBound", "End", b3 => + { + b3.Property("TimePeriodRangeDataSetVersionMetaSummaryDataSetVersionId") + .HasColumnType("uuid"); + + b3.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b3.Property("Period") + .IsRequired() + .HasColumnType("text"); + + b3.HasKey("TimePeriodRangeDataSetVersionMetaSummaryDataSetVersionId"); + + b3.ToTable("DataSetVersions"); + + b3.WithOwner() + .HasForeignKey("TimePeriodRangeDataSetVersionMetaSummaryDataSetVersionId"); + }); + + b2.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodRangeBound", "Start", b3 => + { + b3.Property("TimePeriodRangeDataSetVersionMetaSummaryDataSetVersionId") + .HasColumnType("uuid"); + + b3.Property("Code") + .IsRequired() + .HasColumnType("text"); + + b3.Property("Period") + .IsRequired() + .HasColumnType("text"); + + b3.HasKey("TimePeriodRangeDataSetVersionMetaSummaryDataSetVersionId"); + + b3.ToTable("DataSetVersions"); + + b3.WithOwner() + .HasForeignKey("TimePeriodRangeDataSetVersionMetaSummaryDataSetVersionId"); + }); + + b2.Navigation("End") + .IsRequired(); + + b2.Navigation("Start") + .IsRequired(); + }); + + b1.Navigation("TimePeriodRange") + .IsRequired(); + }); + + b.Navigation("DataSet"); + + b.Navigation("MetaSummary"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersionImport", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("Imports") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersionMapping", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "SourceDataSetVersion") + .WithMany() + .HasForeignKey("SourceDataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "TargetDataSetVersion") + .WithMany() + .HasForeignKey("TargetDataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SourceDataSetVersion"); + + b.Navigation("TargetDataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("FilterMetas") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("FilterMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("FilterOptionMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange+State", "CurrentState", b1 => + { + b1.Property("FilterOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.Property("PublicId") + .IsRequired() + .HasColumnType("text"); + + b1.HasKey("FilterOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("FilterOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("FilterOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange+State", "PreviousState", b1 => + { + b1.Property("FilterOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.Property("PublicId") + .IsRequired() + .HasColumnType("text"); + + b1.HasKey("FilterOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("FilterOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("FilterOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaLink", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "Meta") + .WithMany("OptionLinks") + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", "Option") + .WithMany("MetaLinks") + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Meta"); + + b.Navigation("Option"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithOne("GeographicLevelMeta") + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", "DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithOne("GeographicLevelMetaChange") + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMetaChange", "DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("IndicatorMetas") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("IndicatorMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("LocationMetas") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("LocationMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("LocationOptionMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange+State", "CurrentState", b1 => + { + b1.Property("LocationOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.HasKey("LocationOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("LocationOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("LocationOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange+State", "PreviousState", b1 => + { + b1.Property("LocationOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.HasKey("LocationOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("LocationOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("LocationOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaLink", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "Meta") + .WithMany("OptionLinks") + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", "Option") + .WithMany("MetaLinks") + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Meta"); + + b.Navigation("Option"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.PreviewToken", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("PreviewTokens") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMeta", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("TimePeriodMetas") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DataSetVersion"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("TimePeriodMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => + { + b.Navigation("Versions"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", b => + { + b.Navigation("FilterMetaChanges"); + + b.Navigation("FilterMetas"); + + b.Navigation("FilterOptionMetaChanges"); + + b.Navigation("GeographicLevelMeta"); + + b.Navigation("GeographicLevelMetaChange"); + + b.Navigation("Imports"); + + b.Navigation("IndicatorMetaChanges"); + + b.Navigation("IndicatorMetas"); + + b.Navigation("LocationMetaChanges"); + + b.Navigation("LocationMetas"); + + b.Navigation("LocationOptionMetaChanges"); + + b.Navigation("PreviewTokens"); + + b.Navigation("TimePeriodMetaChanges"); + + b.Navigation("TimePeriodMetas"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", b => + { + b.Navigation("OptionLinks"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", b => + { + b.Navigation("MetaLinks"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", b => + { + b.Navigation("OptionLinks"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", b => + { + b.Navigation("MetaLinks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/20240725104818_EES4950_RemodelChangeTables.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/20240725104818_EES4950_RemodelChangeTables.cs new file mode 100644 index 00000000000..f46099cc421 --- /dev/null +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/20240725104818_EES4950_RemodelChangeTables.cs @@ -0,0 +1,563 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Migrations +{ + /// + public partial class EES4950_RemodelChangeTables : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ChangeSetFilterOptions"); + + migrationBuilder.DropTable( + name: "ChangeSetFilters"); + + migrationBuilder.DropTable( + name: "ChangeSetIndicators"); + + migrationBuilder.DropTable( + name: "ChangeSetLocations"); + + migrationBuilder.DropTable( + name: "ChangeSetTimePeriods"); + + migrationBuilder.CreateTable( + name: "FilterMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CurrentStateId = table.Column(type: "integer", nullable: true), + PreviousStateId = table.Column(type: "integer", nullable: true), + DataSetVersionId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FilterMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_FilterMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FilterMetaChanges_FilterMetas_CurrentStateId", + column: x => x.CurrentStateId, + principalTable: "FilterMetas", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_FilterMetaChanges_FilterMetas_PreviousStateId", + column: x => x.PreviousStateId, + principalTable: "FilterMetas", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "FilterOptionMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + CurrentState_MetaId = table.Column(type: "integer", nullable: true), + CurrentState_OptionId = table.Column(type: "integer", nullable: true), + CurrentState_PublicId = table.Column(type: "text", nullable: true), + PreviousState_MetaId = table.Column(type: "integer", nullable: true), + PreviousState_OptionId = table.Column(type: "integer", nullable: true), + PreviousState_PublicId = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_FilterOptionMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_FilterOptionMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FilterOptionMetaChanges_FilterMetas_CurrentState_MetaId", + column: x => x.CurrentState_MetaId, + principalTable: "FilterMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FilterOptionMetaChanges_FilterMetas_PreviousState_MetaId", + column: x => x.PreviousState_MetaId, + principalTable: "FilterMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FilterOptionMetaChanges_FilterOptionMetas_CurrentState_Opti~", + column: x => x.CurrentState_OptionId, + principalTable: "FilterOptionMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FilterOptionMetaChanges_FilterOptionMetas_PreviousState_Opt~", + column: x => x.PreviousState_OptionId, + principalTable: "FilterOptionMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "GeographicLevelMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CurrentStateId = table.Column(type: "integer", nullable: true), + PreviousStateId = table.Column(type: "integer", nullable: true), + DataSetVersionId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_GeographicLevelMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_GeographicLevelMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_GeographicLevelMetaChanges_GeographicLevelMetas_CurrentStat~", + column: x => x.CurrentStateId, + principalTable: "GeographicLevelMetas", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_GeographicLevelMetaChanges_GeographicLevelMetas_PreviousSta~", + column: x => x.PreviousStateId, + principalTable: "GeographicLevelMetas", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "IndicatorMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CurrentStateId = table.Column(type: "integer", nullable: true), + PreviousStateId = table.Column(type: "integer", nullable: true), + DataSetVersionId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IndicatorMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_IndicatorMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_IndicatorMetaChanges_IndicatorMetas_CurrentStateId", + column: x => x.CurrentStateId, + principalTable: "IndicatorMetas", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_IndicatorMetaChanges_IndicatorMetas_PreviousStateId", + column: x => x.PreviousStateId, + principalTable: "IndicatorMetas", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "LocationMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CurrentStateId = table.Column(type: "integer", nullable: true), + PreviousStateId = table.Column(type: "integer", nullable: true), + DataSetVersionId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LocationMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_LocationMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LocationMetaChanges_LocationMetas_CurrentStateId", + column: x => x.CurrentStateId, + principalTable: "LocationMetas", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_LocationMetaChanges_LocationMetas_PreviousStateId", + column: x => x.PreviousStateId, + principalTable: "LocationMetas", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "LocationOptionMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + CurrentState_MetaId = table.Column(type: "integer", nullable: true), + CurrentState_OptionId = table.Column(type: "integer", nullable: true), + PreviousState_MetaId = table.Column(type: "integer", nullable: true), + PreviousState_OptionId = table.Column(type: "integer", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_LocationOptionMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_LocationOptionMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LocationOptionMetaChanges_LocationMetas_CurrentState_MetaId", + column: x => x.CurrentState_MetaId, + principalTable: "LocationMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LocationOptionMetaChanges_LocationMetas_PreviousState_MetaId", + column: x => x.PreviousState_MetaId, + principalTable: "LocationMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LocationOptionMetaChanges_LocationOptionMetas_CurrentState_~", + column: x => x.CurrentState_OptionId, + principalTable: "LocationOptionMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_LocationOptionMetaChanges_LocationOptionMetas_PreviousState~", + column: x => x.PreviousState_OptionId, + principalTable: "LocationOptionMetas", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TimePeriodMetaChanges", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CurrentStateId = table.Column(type: "integer", nullable: true), + PreviousStateId = table.Column(type: "integer", nullable: true), + DataSetVersionId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TimePeriodMetaChanges", x => x.Id); + table.ForeignKey( + name: "FK_TimePeriodMetaChanges_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_TimePeriodMetaChanges_TimePeriodMetas_CurrentStateId", + column: x => x.CurrentStateId, + principalTable: "TimePeriodMetas", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_TimePeriodMetaChanges_TimePeriodMetas_PreviousStateId", + column: x => x.PreviousStateId, + principalTable: "TimePeriodMetas", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_FilterMetaChanges_CurrentStateId", + table: "FilterMetaChanges", + column: "CurrentStateId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterMetaChanges_DataSetVersionId", + table: "FilterMetaChanges", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterMetaChanges_PreviousStateId", + table: "FilterMetaChanges", + column: "PreviousStateId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterOptionMetaChanges_CurrentState_MetaId", + table: "FilterOptionMetaChanges", + column: "CurrentState_MetaId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterOptionMetaChanges_CurrentState_OptionId", + table: "FilterOptionMetaChanges", + column: "CurrentState_OptionId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterOptionMetaChanges_DataSetVersionId", + table: "FilterOptionMetaChanges", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterOptionMetaChanges_PreviousState_MetaId", + table: "FilterOptionMetaChanges", + column: "PreviousState_MetaId"); + + migrationBuilder.CreateIndex( + name: "IX_FilterOptionMetaChanges_PreviousState_OptionId", + table: "FilterOptionMetaChanges", + column: "PreviousState_OptionId"); + + migrationBuilder.CreateIndex( + name: "IX_GeographicLevelMetaChanges_CurrentStateId", + table: "GeographicLevelMetaChanges", + column: "CurrentStateId"); + + migrationBuilder.CreateIndex( + name: "IX_GeographicLevelMetaChanges_DataSetVersionId", + table: "GeographicLevelMetaChanges", + column: "DataSetVersionId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_GeographicLevelMetaChanges_PreviousStateId", + table: "GeographicLevelMetaChanges", + column: "PreviousStateId"); + + migrationBuilder.CreateIndex( + name: "IX_IndicatorMetaChanges_CurrentStateId", + table: "IndicatorMetaChanges", + column: "CurrentStateId"); + + migrationBuilder.CreateIndex( + name: "IX_IndicatorMetaChanges_DataSetVersionId", + table: "IndicatorMetaChanges", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_IndicatorMetaChanges_PreviousStateId", + table: "IndicatorMetaChanges", + column: "PreviousStateId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationMetaChanges_CurrentStateId", + table: "LocationMetaChanges", + column: "CurrentStateId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationMetaChanges_DataSetVersionId", + table: "LocationMetaChanges", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationMetaChanges_PreviousStateId", + table: "LocationMetaChanges", + column: "PreviousStateId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationOptionMetaChanges_CurrentState_MetaId", + table: "LocationOptionMetaChanges", + column: "CurrentState_MetaId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationOptionMetaChanges_CurrentState_OptionId", + table: "LocationOptionMetaChanges", + column: "CurrentState_OptionId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationOptionMetaChanges_DataSetVersionId", + table: "LocationOptionMetaChanges", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationOptionMetaChanges_PreviousState_MetaId", + table: "LocationOptionMetaChanges", + column: "PreviousState_MetaId"); + + migrationBuilder.CreateIndex( + name: "IX_LocationOptionMetaChanges_PreviousState_OptionId", + table: "LocationOptionMetaChanges", + column: "PreviousState_OptionId"); + + migrationBuilder.CreateIndex( + name: "IX_TimePeriodMetaChanges_CurrentStateId", + table: "TimePeriodMetaChanges", + column: "CurrentStateId"); + + migrationBuilder.CreateIndex( + name: "IX_TimePeriodMetaChanges_DataSetVersionId", + table: "TimePeriodMetaChanges", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_TimePeriodMetaChanges_PreviousStateId", + table: "TimePeriodMetaChanges", + column: "PreviousStateId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "FilterMetaChanges"); + + migrationBuilder.DropTable( + name: "FilterOptionMetaChanges"); + + migrationBuilder.DropTable( + name: "GeographicLevelMetaChanges"); + + migrationBuilder.DropTable( + name: "IndicatorMetaChanges"); + + migrationBuilder.DropTable( + name: "LocationMetaChanges"); + + migrationBuilder.DropTable( + name: "LocationOptionMetaChanges"); + + migrationBuilder.DropTable( + name: "TimePeriodMetaChanges"); + + migrationBuilder.CreateTable( + name: "ChangeSetFilterOptions", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + Created = table.Column(type: "timestamp with time zone", nullable: false), + Updated = table.Column(type: "timestamp with time zone", nullable: true), + Changes = table.Column(type: "jsonb", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ChangeSetFilterOptions", x => x.Id); + table.ForeignKey( + name: "FK_ChangeSetFilterOptions_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChangeSetFilters", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + Created = table.Column(type: "timestamp with time zone", nullable: false), + Updated = table.Column(type: "timestamp with time zone", nullable: true), + Changes = table.Column(type: "jsonb", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ChangeSetFilters", x => x.Id); + table.ForeignKey( + name: "FK_ChangeSetFilters_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChangeSetIndicators", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + Created = table.Column(type: "timestamp with time zone", nullable: false), + Updated = table.Column(type: "timestamp with time zone", nullable: true), + Changes = table.Column(type: "jsonb", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ChangeSetIndicators", x => x.Id); + table.ForeignKey( + name: "FK_ChangeSetIndicators_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChangeSetLocations", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + Created = table.Column(type: "timestamp with time zone", nullable: false), + Updated = table.Column(type: "timestamp with time zone", nullable: true), + Changes = table.Column(type: "jsonb", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ChangeSetLocations", x => x.Id); + table.ForeignKey( + name: "FK_ChangeSetLocations_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ChangeSetTimePeriods", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DataSetVersionId = table.Column(type: "uuid", nullable: false), + Created = table.Column(type: "timestamp with time zone", nullable: false), + Updated = table.Column(type: "timestamp with time zone", nullable: true), + Changes = table.Column(type: "jsonb", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ChangeSetTimePeriods", x => x.Id); + table.ForeignKey( + name: "FK_ChangeSetTimePeriods_DataSetVersions_DataSetVersionId", + column: x => x.DataSetVersionId, + principalTable: "DataSetVersions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ChangeSetFilterOptions_DataSetVersionId", + table: "ChangeSetFilterOptions", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeSetFilters_DataSetVersionId", + table: "ChangeSetFilters", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeSetIndicators_DataSetVersionId", + table: "ChangeSetIndicators", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeSetLocations_DataSetVersionId", + table: "ChangeSetLocations", + column: "DataSetVersionId"); + + migrationBuilder.CreateIndex( + name: "IX_ChangeSetTimePeriods_DataSetVersionId", + table: "ChangeSetTimePeriods", + column: "DataSetVersionId"); + } + } +} diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/PublicDataDbContextModelSnapshot.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/PublicDataDbContextModelSnapshot.cs index d5fedae8dbc..bedcb5e8db3 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/PublicDataDbContextModelSnapshot.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/Migrations/PublicDataDbContextModelSnapshot.cs @@ -45,116 +45,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToView(null, (string)null); }); - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetFilterOptions", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("DataSetVersionId") - .HasColumnType("uuid"); - - b.Property("Updated") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("DataSetVersionId"); - - b.ToTable("ChangeSetFilterOptions"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetFilters", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("DataSetVersionId") - .HasColumnType("uuid"); - - b.Property("Updated") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("DataSetVersionId"); - - b.ToTable("ChangeSetFilters"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetIndicators", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("DataSetVersionId") - .HasColumnType("uuid"); - - b.Property("Updated") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("DataSetVersionId"); - - b.ToTable("ChangeSetIndicators"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetLocations", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("DataSetVersionId") - .HasColumnType("uuid"); - - b.Property("Updated") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("DataSetVersionId"); - - b.ToTable("ChangeSetLocations"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetTimePeriods", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Created") - .HasColumnType("timestamp with time zone"); - - b.Property("DataSetVersionId") - .HasColumnType("uuid"); - - b.Property("Updated") - .HasColumnType("timestamp with time zone"); - - b.HasKey("Id"); - - b.HasIndex("DataSetVersionId"); - - b.ToTable("ChangeSetTimePeriods"); - }); - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => { b.Property("Id") @@ -383,6 +273,34 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("FilterMetas"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("FilterMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", b => { b.Property("Id") @@ -403,6 +321,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("FilterOptionMetas"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId"); + + b.ToTable("FilterOptionMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaLink", b => { b.Property("MetaId") @@ -456,6 +392,35 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("GeographicLevelMetas"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId") + .IsUnique(); + + b.HasIndex("PreviousStateId"); + + b.ToTable("GeographicLevelMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", b => { b.Property("Id") @@ -496,6 +461,34 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("IndicatorMetas"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("IndicatorMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", b => { b.Property("Id") @@ -526,6 +519,34 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("LocationMetas"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("LocationMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", b => { b.Property("Id") @@ -591,6 +612,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.UseTphMappingStrategy(); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("DataSetVersionId"); + + b.ToTable("LocationOptionMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaLink", b => { b.Property("MetaId") @@ -673,6 +712,34 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("TimePeriodMetas"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMetaChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CurrentStateId") + .HasColumnType("integer"); + + b.Property("DataSetVersionId") + .HasColumnType("uuid"); + + b.Property("PreviousStateId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CurrentStateId"); + + b.HasIndex("DataSetVersionId"); + + b.HasIndex("PreviousStateId"); + + b.ToTable("TimePeriodMetaChanges"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationCodedOptionMeta", b => { b.HasBaseType("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta"); @@ -708,533 +775,26 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasDiscriminator().HasValue("SCH"); }); - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetFilterOptions", b => + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => { - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") - .WithMany("FilterOptionChanges") - .HasForeignKey("DataSetVersionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.OwnsMany("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Change", "Changes", b1 => - { - b1.Property("ChangeSetFilterOptionsId") - .HasColumnType("uuid"); - - b1.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - b1.Property("Identifier") - .HasColumnType("uuid") - .HasAnnotation("Relational:JsonPropertyName", "Id"); + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "LatestDraftVersion") + .WithOne() + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "LatestDraftVersionId"); - b1.Property("Type") - .IsRequired() - .HasColumnType("text"); + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "LatestLiveVersion") + .WithOne() + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "LatestLiveVersionId"); - b1.HasKey("ChangeSetFilterOptionsId", "Id"); + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "SupersedingDataSet") + .WithMany() + .HasForeignKey("SupersedingDataSetId"); - b1.ToTable("ChangeSetFilterOptions"); + b.Navigation("LatestDraftVersion"); - b1.ToJson("Changes"); + b.Navigation("LatestLiveVersion"); - b1.WithOwner() - .HasForeignKey("ChangeSetFilterOptionsId"); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionChangeState", "CurrentState", b2 => - { - b2.Property("ChangeSetFilterOptionsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("FilterId") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("IsAggregate") - .HasColumnType("boolean"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("ChangeSetFilterOptionsId", "ChangeId"); - - b2.ToTable("ChangeSetFilterOptions"); - - b2.WithOwner() - .HasForeignKey("ChangeSetFilterOptionsId", "ChangeId"); - }); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionChangeState", "PreviousState", b2 => - { - b2.Property("ChangeSetFilterOptionsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("FilterId") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("IsAggregate") - .HasColumnType("boolean"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("ChangeSetFilterOptionsId", "ChangeId"); - - b2.ToTable("ChangeSetFilterOptions"); - - b2.WithOwner() - .HasForeignKey("ChangeSetFilterOptionsId", "ChangeId"); - }); - - b1.Navigation("CurrentState"); - - b1.Navigation("PreviousState"); - }); - - b.Navigation("Changes"); - - b.Navigation("DataSetVersion"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetFilters", b => - { - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") - .WithMany("FilterChanges") - .HasForeignKey("DataSetVersionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.OwnsMany("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Change", "Changes", b1 => - { - b1.Property("ChangeSetFiltersId") - .HasColumnType("uuid"); - - b1.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - b1.Property("Identifier") - .HasColumnType("uuid") - .HasAnnotation("Relational:JsonPropertyName", "Id"); - - b1.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b1.HasKey("ChangeSetFiltersId", "Id"); - - b1.ToTable("ChangeSetFilters"); - - b1.ToJson("Changes"); - - b1.WithOwner() - .HasForeignKey("ChangeSetFiltersId"); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterChangeState", "CurrentState", b2 => - { - b2.Property("ChangeSetFiltersId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("Hint") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("ChangeSetFiltersId", "ChangeId"); - - b2.ToTable("ChangeSetFilters"); - - b2.WithOwner() - .HasForeignKey("ChangeSetFiltersId", "ChangeId"); - }); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterChangeState", "PreviousState", b2 => - { - b2.Property("ChangeSetFiltersId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("Hint") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("ChangeSetFiltersId", "ChangeId"); - - b2.ToTable("ChangeSetFilters"); - - b2.WithOwner() - .HasForeignKey("ChangeSetFiltersId", "ChangeId"); - }); - - b1.Navigation("CurrentState"); - - b1.Navigation("PreviousState"); - }); - - b.Navigation("Changes"); - - b.Navigation("DataSetVersion"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetIndicators", b => - { - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") - .WithMany("IndicatorChanges") - .HasForeignKey("DataSetVersionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.OwnsMany("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Change", "Changes", b1 => - { - b1.Property("ChangeSetIndicatorsId") - .HasColumnType("uuid"); - - b1.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - b1.Property("Identifier") - .HasColumnType("uuid") - .HasAnnotation("Relational:JsonPropertyName", "Id"); - - b1.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b1.HasKey("ChangeSetIndicatorsId", "Id"); - - b1.ToTable("ChangeSetIndicators"); - - b1.ToJson("Changes"); - - b1.WithOwner() - .HasForeignKey("ChangeSetIndicatorsId"); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorChangeState", "CurrentState", b2 => - { - b2.Property("ChangeSetIndicatorsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("DecimalPlaces") - .HasColumnType("smallint"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Unit") - .HasColumnType("text"); - - b2.HasKey("ChangeSetIndicatorsId", "ChangeId"); - - b2.ToTable("ChangeSetIndicators"); - - b2.WithOwner() - .HasForeignKey("ChangeSetIndicatorsId", "ChangeId"); - }); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorChangeState", "PreviousState", b2 => - { - b2.Property("ChangeSetIndicatorsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("DecimalPlaces") - .HasColumnType("smallint"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Unit") - .HasColumnType("text"); - - b2.HasKey("ChangeSetIndicatorsId", "ChangeId"); - - b2.ToTable("ChangeSetIndicators"); - - b2.WithOwner() - .HasForeignKey("ChangeSetIndicatorsId", "ChangeId"); - }); - - b1.Navigation("CurrentState"); - - b1.Navigation("PreviousState"); - }); - - b.Navigation("Changes"); - - b.Navigation("DataSetVersion"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetLocations", b => - { - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") - .WithMany("LocationChanges") - .HasForeignKey("DataSetVersionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.OwnsMany("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Change", "Changes", b1 => - { - b1.Property("ChangeSetLocationsId") - .HasColumnType("uuid"); - - b1.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - b1.Property("Identifier") - .HasColumnType("uuid") - .HasAnnotation("Relational:JsonPropertyName", "Id"); - - b1.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b1.HasKey("ChangeSetLocationsId", "Id"); - - b1.ToTable("ChangeSetLocations"); - - b1.ToJson("Changes"); - - b1.WithOwner() - .HasForeignKey("ChangeSetLocationsId"); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationChangeState", "CurrentState", b2 => - { - b2.Property("ChangeSetLocationsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("Code") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Level") - .IsRequired() - .HasColumnType("text"); - - b2.HasKey("ChangeSetLocationsId", "ChangeId"); - - b2.ToTable("ChangeSetLocations"); - - b2.WithOwner() - .HasForeignKey("ChangeSetLocationsId", "ChangeId"); - }); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationChangeState", "PreviousState", b2 => - { - b2.Property("ChangeSetLocationsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("Code") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Id") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Label") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Level") - .HasColumnType("integer"); - - b2.HasKey("ChangeSetLocationsId", "ChangeId"); - - b2.ToTable("ChangeSetLocations"); - - b2.WithOwner() - .HasForeignKey("ChangeSetLocationsId", "ChangeId"); - }); - - b1.Navigation("CurrentState"); - - b1.Navigation("PreviousState"); - }); - - b.Navigation("Changes"); - - b.Navigation("DataSetVersion"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.ChangeSetTimePeriods", b => - { - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") - .WithMany("TimePeriodChanges") - .HasForeignKey("DataSetVersionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.OwnsMany("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.Change", "Changes", b1 => - { - b1.Property("ChangeSetTimePeriodsId") - .HasColumnType("uuid"); - - b1.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - b1.Property("Identifier") - .HasColumnType("uuid") - .HasAnnotation("Relational:JsonPropertyName", "Id"); - - b1.Property("Type") - .IsRequired() - .HasColumnType("text"); - - b1.HasKey("ChangeSetTimePeriodsId", "Id"); - - b1.ToTable("ChangeSetTimePeriods"); - - b1.ToJson("Changes"); - - b1.WithOwner() - .HasForeignKey("ChangeSetTimePeriodsId"); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodChangeState", "CurrentState", b2 => - { - b2.Property("ChangeSetTimePeriodsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("Code") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Year") - .HasColumnType("integer"); - - b2.HasKey("ChangeSetTimePeriodsId", "ChangeId"); - - b2.ToTable("ChangeSetTimePeriods"); - - b2.WithOwner() - .HasForeignKey("ChangeSetTimePeriodsId", "ChangeId"); - }); - - b1.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodChangeState", "PreviousState", b2 => - { - b2.Property("ChangeSetTimePeriodsId") - .HasColumnType("uuid"); - - b2.Property("ChangeId") - .HasColumnType("integer"); - - b2.Property("Code") - .IsRequired() - .HasColumnType("text"); - - b2.Property("Year") - .HasColumnType("integer"); - - b2.HasKey("ChangeSetTimePeriodsId", "ChangeId"); - - b2.ToTable("ChangeSetTimePeriods"); - - b2.WithOwner() - .HasForeignKey("ChangeSetTimePeriodsId", "ChangeId"); - }); - - b1.Navigation("CurrentState"); - - b1.Navigation("PreviousState"); - }); - - b.Navigation("Changes"); - - b.Navigation("DataSetVersion"); - }); - - modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => - { - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "LatestDraftVersion") - .WithOne() - .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "LatestDraftVersionId"); - - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "LatestLiveVersion") - .WithOne() - .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "LatestLiveVersionId"); - - b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", "SupersedingDataSet") - .WithMany() - .HasForeignKey("SupersedingDataSetId"); - - b.Navigation("LatestDraftVersion"); - - b.Navigation("LatestLiveVersion"); - - b.Navigation("SupersedingDataSet"); - }); + b.Navigation("SupersedingDataSet"); + }); modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", b => { @@ -1381,6 +941,130 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("DataSetVersion"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("FilterMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("FilterOptionMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange+State", "CurrentState", b1 => + { + b1.Property("FilterOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.Property("PublicId") + .IsRequired() + .HasColumnType("text"); + + b1.HasKey("FilterOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("FilterOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("FilterOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaChange+State", "PreviousState", b1 => + { + b1.Property("FilterOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.Property("PublicId") + .IsRequired() + .HasColumnType("text"); + + b1.HasKey("FilterOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("FilterOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("FilterOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterOptionMetaLink", b => { b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.FilterMeta", "Meta") @@ -1411,6 +1095,29 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("DataSetVersion"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithOne("GeographicLevelMetaChange") + .HasForeignKey("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMetaChange", "DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.GeographicLevelMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", b => { b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") @@ -1422,6 +1129,29 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("DataSetVersion"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("IndicatorMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.IndicatorMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", b => { b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") @@ -1433,6 +1163,122 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("DataSetVersion"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("LocationMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("LocationOptionMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange+State", "CurrentState", b1 => + { + b1.Property("LocationOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.HasKey("LocationOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("LocationOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("LocationOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.OwnsOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaChange+State", "PreviousState", b1 => + { + b1.Property("LocationOptionMetaChangeId") + .HasColumnType("bigint"); + + b1.Property("MetaId") + .HasColumnType("integer"); + + b1.Property("OptionId") + .HasColumnType("integer"); + + b1.HasKey("LocationOptionMetaChangeId"); + + b1.HasIndex("MetaId"); + + b1.HasIndex("OptionId"); + + b1.ToTable("LocationOptionMetaChanges"); + + b1.WithOwner() + .HasForeignKey("LocationOptionMetaChangeId"); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "Meta") + .WithMany() + .HasForeignKey("MetaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMeta", "Option") + .WithMany() + .HasForeignKey("OptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b1.Navigation("Meta"); + + b1.Navigation("Option"); + }); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationOptionMetaLink", b => { b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.LocationMeta", "Meta") @@ -1474,6 +1320,29 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("DataSetVersion"); }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMetaChange", b => + { + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMeta", "CurrentState") + .WithMany() + .HasForeignKey("CurrentStateId"); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", "DataSetVersion") + .WithMany("TimePeriodMetaChanges") + .HasForeignKey("DataSetVersionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.TimePeriodMeta", "PreviousState") + .WithMany() + .HasForeignKey("PreviousStateId"); + + b.Navigation("CurrentState"); + + b.Navigation("DataSetVersion"); + + b.Navigation("PreviousState"); + }); + modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSet", b => { b.Navigation("Versions"); @@ -1481,27 +1350,31 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("GovUk.Education.ExploreEducationStatistics.Public.Data.Model.DataSetVersion", b => { - b.Navigation("FilterChanges"); + b.Navigation("FilterMetaChanges"); b.Navigation("FilterMetas"); - b.Navigation("FilterOptionChanges"); + b.Navigation("FilterOptionMetaChanges"); b.Navigation("GeographicLevelMeta"); + b.Navigation("GeographicLevelMetaChange"); + b.Navigation("Imports"); - b.Navigation("IndicatorChanges"); + b.Navigation("IndicatorMetaChanges"); b.Navigation("IndicatorMetas"); - b.Navigation("LocationChanges"); + b.Navigation("LocationMetaChanges"); b.Navigation("LocationMetas"); + b.Navigation("LocationOptionMetaChanges"); + b.Navigation("PreviewTokens"); - b.Navigation("TimePeriodChanges"); + b.Navigation("TimePeriodMetaChanges"); b.Navigation("TimePeriodMetas"); }); diff --git a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/TimePeriodChangeState.cs b/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/TimePeriodChangeState.cs deleted file mode 100644 index e0a5baa835d..00000000000 --- a/src/GovUk.Education.ExploreEducationStatistics.Public.Data.Model/TimePeriodChangeState.cs +++ /dev/null @@ -1,10 +0,0 @@ -using GovUk.Education.ExploreEducationStatistics.Common.Model; - -namespace GovUk.Education.ExploreEducationStatistics.Public.Data.Model; - -public class TimePeriodChangeState -{ - public required TimeIdentifier Code { get; set; } - - public required int Year { get; set; } -}