Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class ChangeSerializationTests
{
private static readonly Lazy<JsonSerializerOptions> LazyOptions = new(() =>
{
var config = new CrdtConfig();
LcmCrdtKernel.ConfigureCrdt(config);
var config = LcmCrdtKernel.MakeConfig();
config.JsonSerializerOptions.ReadCommentHandling = JsonCommentHandling.Skip;
return config.JsonSerializerOptions;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@
ComponentSenseId
SnapshotId Unique
ComplexFormEntryId, ComponentEntryId Unique
Annotations:
Relational:Filter: ComponentSenseId IS NULL
ComplexFormEntryId, ComponentEntryId, ComponentSenseId Unique
Annotations:
Relational:Filter: ComponentSenseId IS NOT NULL
Annotations:
DiscriminatorProperty:
Relational:FunctionName:
Expand Down Expand Up @@ -270,7 +266,7 @@
Order (double) Required
SnapshotId (no field, Guid?) Shadow FK Index
Type (WritingSystemType) Required Index
WsId (WritingSystemId) Required Index
WsId (WritingSystemId) Required Index Sentinel:default
Keys:
Id PK
Foreign keys:
Expand Down Expand Up @@ -308,6 +304,13 @@
DateTime (DateTimeOffset) Required
Annotations:
Relational:ColumnName: DateTime
Annotations:
Relational:FunctionName:
Relational:Schema:
Relational:SqlQuery:
Relational:TableName: Commits
Relational:ViewName:
Relational:ViewSchema:
Keys:
Id PK
Annotations:
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/LcmCrdt/Changes/CreateEntryChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CreateEntryChange(Entry entry) : base(entry.Id == Guid.Empty ? Guid.NewGu
}

[JsonConstructor]
private CreateEntryChange(Guid entityId) : base(entityId)
internal CreateEntryChange(Guid entityId) : base(entityId)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CreateExampleSentenceChange(ExampleSentence exampleSentence, Guid senseId
}

[JsonConstructor]
private CreateExampleSentenceChange(Guid entityId, Guid senseId) : base(entityId)
internal CreateExampleSentenceChange(Guid entityId, Guid senseId) : base(entityId)
{
SenseId = senseId;
}
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/LcmCrdt/Changes/CreateSenseChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CreateSenseChange(Sense sense, Guid entryId) : base(sense.Id == Guid.Empt
}

[JsonConstructor]
private CreateSenseChange(Guid entityId, Guid entryId) : base(entityId)
internal CreateSenseChange(Guid entityId, Guid entryId) : base(entityId)
{
EntryId = entryId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public CreateWritingSystemChange(WritingSystem writingSystem, WritingSystemType
}

[JsonConstructor]
private CreateWritingSystemChange(Guid entityId) : base(entityId)
internal CreateWritingSystemChange(Guid entityId) : base(entityId)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LcmCrdt.Changes.Entries;
public class SetComplexFormComponentChange : EditChange<ComplexFormComponent>, ISelfNamedType<SetComplexFormComponentChange>
{
[JsonConstructor]
protected SetComplexFormComponentChange(Guid entityId, Guid? complexFormEntryId, Guid? componentEntryId, Guid? componentSenseId) : base(entityId)
internal SetComplexFormComponentChange(Guid entityId, Guid? complexFormEntryId, Guid? componentEntryId, Guid? componentSenseId) : base(entityId)
{
ComplexFormEntryId = complexFormEntryId;
ComponentEntryId = componentEntryId;
Expand Down
140 changes: 140 additions & 0 deletions backend/FwLite/LcmCrdt/CompiledModels/ChangeEntityEntityType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Storage.Json;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SIL.Harmony.Changes;
using SIL.Harmony.Core;
using SIL.Harmony.Db.EntityConfig;

#pragma warning disable 219, 612, 618
#nullable disable

namespace LcmCrdt.CompiledModels
{
internal partial class ChangeEntityEntityType
{
public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType baseEntityType = null)
{
var runtimeEntityType = model.AddEntityType(
"SIL.Harmony.Core.ChangeEntity<SIL.Harmony.Changes.IChange>",
typeof(ChangeEntity<IChange>),
baseEntityType);

var commitId = runtimeEntityType.AddProperty(
"CommitId",
typeof(Guid),
propertyInfo: typeof(ChangeEntity<IChange>).GetProperty("CommitId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(ChangeEntity<IChange>).GetField("<CommitId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
afterSaveBehavior: PropertySaveBehavior.Throw,
sentinel: new Guid("00000000-0000-0000-0000-000000000000"));
commitId.TypeMapping = SqliteGuidTypeMapping.Default;

var index = runtimeEntityType.AddProperty(
"Index",
typeof(int),
propertyInfo: typeof(ChangeEntity<IChange>).GetProperty("Index", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(ChangeEntity<IChange>).GetField("<Index>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
afterSaveBehavior: PropertySaveBehavior.Throw,
sentinel: 0);
index.TypeMapping = IntTypeMapping.Default.Clone(
comparer: new ValueComparer<int>(
(int v1, int v2) => v1 == v2,
(int v) => v,
(int v) => v),
keyComparer: new ValueComparer<int>(
(int v1, int v2) => v1 == v2,
(int v) => v,
(int v) => v),
providerValueComparer: new ValueComparer<int>(
(int v1, int v2) => v1 == v2,
(int v) => v,
(int v) => v),
mappingInfo: new RelationalTypeMappingInfo(
storeTypeName: "INTEGER"));

var change = runtimeEntityType.AddProperty(
"Change",
typeof(IChange),
propertyInfo: typeof(ChangeEntity<IChange>).GetProperty("Change", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(ChangeEntity<IChange>).GetField("<Change>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
nullable: true);
change.TypeMapping = SqliteStringTypeMapping.Default.Clone(
comparer: new ValueComparer<IChange>(
(IChange v1, IChange v2) => object.Equals(v1, v2),
(IChange v) => v.GetHashCode(),
(IChange v) => v),
keyComparer: new ValueComparer<IChange>(
(IChange v1, IChange v2) => object.Equals(v1, v2),
(IChange v) => v.GetHashCode(),
(IChange v) => v),
providerValueComparer: new ValueComparer<string>(
(string v1, string v2) => v1 == v2,
(string v) => v.GetHashCode(),
(string v) => v),
mappingInfo: new RelationalTypeMappingInfo(
storeTypeName: "jsonb"),
converter: new ValueConverter<IChange, string>(
(IChange change) => ChangeEntityConfig.SerializeChange(change, null),
(string json) => ChangeEntityConfig.DeserializeChange(json, null)),
jsonValueReaderWriter: new JsonConvertedValueReaderWriter<IChange, string>(
JsonStringReaderWriter.Instance,
new ValueConverter<IChange, string>(
(IChange change) => ChangeEntityConfig.SerializeChange(change, null),
(string json) => ChangeEntityConfig.DeserializeChange(json, null))));
change.AddAnnotation("Relational:ColumnType", "jsonb");

var entityId = runtimeEntityType.AddProperty(
"EntityId",
typeof(Guid),
propertyInfo: typeof(ChangeEntity<IChange>).GetProperty("EntityId", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(ChangeEntity<IChange>).GetField("<EntityId>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
sentinel: new Guid("00000000-0000-0000-0000-000000000000"));
entityId.TypeMapping = SqliteGuidTypeMapping.Default;

var key = runtimeEntityType.AddKey(
new[] { commitId, index });
runtimeEntityType.SetPrimaryKey(key);

return runtimeEntityType;
}

public static RuntimeForeignKey CreateForeignKey1(RuntimeEntityType declaringEntityType, RuntimeEntityType principalEntityType)
{
var runtimeForeignKey = declaringEntityType.AddForeignKey(new[] { declaringEntityType.FindProperty("CommitId") },
principalEntityType.FindKey(new[] { principalEntityType.FindProperty("Id") }),
principalEntityType,
deleteBehavior: DeleteBehavior.Cascade,
required: true);

var changeEntities = principalEntityType.AddNavigation("ChangeEntities",
runtimeForeignKey,
onDependent: false,
typeof(List<ChangeEntity<IChange>>),
propertyInfo: typeof(CommitBase<IChange>).GetProperty("ChangeEntities", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(CommitBase<IChange>).GetField("<ChangeEntities>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));

return runtimeForeignKey;
}

public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
{
runtimeEntityType.AddAnnotation("Relational:FunctionName", null);
runtimeEntityType.AddAnnotation("Relational:Schema", null);
runtimeEntityType.AddAnnotation("Relational:SqlQuery", null);
runtimeEntityType.AddAnnotation("Relational:TableName", "ChangeEntities");
runtimeEntityType.AddAnnotation("Relational:ViewName", null);
runtimeEntityType.AddAnnotation("Relational:ViewSchema", null);

Customize(runtimeEntityType);
}

static partial void Customize(RuntimeEntityType runtimeEntityType);
}
}
Loading
Loading