Skip to content

Fix aot mac #1609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Fix aot mac #1609

wants to merge 8 commits into from

Conversation

hahn-kev
Copy link
Collaborator

@hahn-kev hahn-kev commented Apr 16, 2025

closes #1603
in order to test this I enabled PublishAot on the LCM debugger project and ran it. Unfortunatly Maui windows doesn't support AoT so I can't test it there. This should be tested on a mac to verify that it actually works.

Lots of hacking around issues was required. I'm not sure I love a lot of this code right now but I want to get it here so we can test out if it works. In order to support AoT we needed to use an EF Compiled Model and Source generation for Json support.

Copy link

coderabbitai bot commented Apr 16, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This update introduces a comprehensive set of auto-generated files that define runtime Entity Framework Core (EF Core) model configurations for various entities in the backend, including properties, keys, indexes, foreign keys, and relational annotations. JSON serialization is now handled via source generation, with new converters and serialization logic applied throughout the model. The LcmCrdtDbContext is updated to use a compiled model and internalizes its converters, while explicit property conversions are added for Linq2DB compatibility. A new task for compiling the database model is added to the taskfile, and the harmony subproject reference is updated to a newer commit.

Changes

File(s) Change Summary
backend/FwLite/LcmCrdt/CompiledModels/*.cs
(CommitEntityType, ChangeEntityEntityType, ComplexFormComponentEntityType, ComplexFormTypeEntityType, EntryEntityType, ExampleSentenceEntityType, LcmCrdtDbContextModel, ObjectSnapshotEntityType, PartOfSpeechEntityType, ProjectDataEntityType, PublicationEntityType, SemanticDomainEntityType, SenseEntityType, WritingSystemEntityType)
Added auto-generated internal partial classes for each entity, defining runtime EF Core model configuration: properties, keys, indexes, foreign keys, navigation properties, type mappings (including JSON serialization), and relational annotations. Each includes a static Create method and partial Customize method for extensibility.
backend/FwLite/LcmCrdt/Data/CompileModelCustomization.cs Added partial classes with static Customize methods to configure JSON serialization and type mapping for specific properties in ChangeEntityEntityType and ObjectSnapshotEntityType.
backend/FwLite/LcmCrdt/JsonSourceGenerationContext.cs Added a partial class for source-generated JSON serialization context, specifying serializable types for the model.
backend/FwLite/LcmCrdt/LcmCrdtDbContext.cs Updated to use compiled EF Core model; refactored JSON serialization/deserialization to use source-generated context and internalized converters.
backend/FwLite/LcmCrdt/LcmCrdtKernel.cs Added explicit Linq2DB property conversions for JSON-serialized properties; unified serialization logic; added MakeConfig factory method; set sentinel for WritingSystem.WsId.
backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt Updated snapshot: removed relational filter annotations on certain indexes, added Sentinel:default annotation, and new relational annotations for complex properties.
backend/FwLite/Taskfile.yml Added compile-db-model task to run dotnet ef dbcontext optimize in the LcmCrdt directory.
backend/harmony Updated subproject reference to a newer commit.

Poem

🐇✨
In the meadow of code where models grow,
Bunnies compile mappings, row by row.
With JSON that sparkles and tasks that run,
Entities dance in the database sun.
Converters now internal, snapshots anew—
Hop, hop! This model’s ready for you!
🌱📦


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Apr 16, 2025

C# Unit Tests

116 tests  ±0   116 ✅ ±0   9s ⏱️ -1s
 17 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 4338c62. ± Comparison against base commit 5f91619.

♻️ This comment has been updated with latest results.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (9)
backend/FwLite/LcmCrdt/CompiledModels/LcmCrdtDbContextModel.cs (1)

13-14: Clarify the purpose of _useOldBehavior31751.
This switch-based logic suggests backward compatibility or a workaround for an EF Core issue. If this setting is only needed temporarily, consider adding inline comments or a TODO marker indicating its planned removal or further review later.

backend/FwLite/LcmCrdt/CompiledModels/ProjectDataEntityType.cs (1)

39-45: Consider indexing Code if frequently used in queries.
If Code is essential for lookups or filtering, adding an index could help performance. Otherwise, you may keep it as-is.

backend/FwLite/LcmCrdt/CompiledModels/WritingSystemEntityType.cs (1)

22-197: Reevaluate "jsonb" for exemplars in SQLite.
Similar to the discussion in ComplexFormTypeEntityType, the "jsonb" store type might be a carryover from PostgreSQL. Although not necessarily harmful in a SQLite environment, it may be unclear to other developers. Consider standardizing the store type to something explicitly SQLite-compatible unless cross-database behavior is a strict requirement.

backend/FwLite/LcmCrdt/CompiledModels/PublicationEntityType.cs (1)

116-116: Leverage the partial method
The Customize(runtimeEntityType) method can be used to add specialized mappings or concurrency tokens. If customization isn't required, consider removing or documenting this method.

backend/FwLite/LcmCrdt/CompiledModels/ChangeEntityEntityType.cs (2)

23-105: Handle invalid JSON gracefully and verify 'jsonb' usage
While using a value converter for serialization is effective, consider adding error handling or fallback logic for invalid JSON data to prevent runtime exceptions. Also confirm that labeling the column jsonb does not cause compatibility issues under SQLite.


138-138: Partial method usage
If no extra custom logic is needed, consider removing or documenting the Customize partial method for clarity.

backend/FwLite/LcmCrdt/CompiledModels/ExampleSentenceEntityType.cs (1)

207-207: Clarify or remove partial method
If Customize(runtimeEntityType) does not require additional logic, consider removing or documenting this partial method to reduce confusion.

backend/FwLite/LcmCrdt/CompiledModels/ObjectSnapshotEntityType.cs (1)

132-155: Validate the design of storing the References array as JSON.
If referential integrity or frequent filtering/ordering on these references is needed, relying on JSON-based storage may limit indexing and complicate queries.

backend/FwLite/LcmCrdt/CompiledModels/ComplexFormComponentEntityType.cs (1)

36-43: Check GUID sentinel usage for ComplexFormEntryId.

This property includes a sentinel 00000000-0000-0000-0000-000000000000 for comparisons. Ensure any custom logic in your application does not incorrectly treat the sentinel as valid data, especially if using EF default value behaviors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f91619 and bee488f.

📒 Files selected for processing (21)
  • backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt (2 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/ChangeEntityEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/CommitEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/ComplexFormComponentEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/ComplexFormTypeEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/EntryEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/ExampleSentenceEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/LcmCrdtDbContextModel.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/ObjectSnapshotEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/PartOfSpeechEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/ProjectDataEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/PublicationEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/SemanticDomainEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/SenseEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/CompiledModels/WritingSystemEntityType.cs (1 hunks)
  • backend/FwLite/LcmCrdt/Data/CompileModelCustomization.cs (1 hunks)
  • backend/FwLite/LcmCrdt/JsonSourceGenerationContext.cs (1 hunks)
  • backend/FwLite/LcmCrdt/LcmCrdtDbContext.cs (3 hunks)
  • backend/FwLite/LcmCrdt/LcmCrdtKernel.cs (5 hunks)
  • backend/FwLite/Taskfile.yml (1 hunks)
  • backend/harmony (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
backend/FwLite/LcmCrdt/CompiledModels/LcmCrdtDbContextModel.cs (3)
backend/FwLite/LcmCrdt/LcmCrdtDbContext.cs (1)
  • LcmCrdtDbContext (13-67)
backend/FwLite/LcmCrdt/CompiledModels/LcmCrdtDbContextModelBuilder.cs (2)
  • LcmCrdtDbContextModel (15-1513)
  • Initialize (17-67)
backend/FwLite/LcmCrdt/Data/CompileModelCustomization.cs (2)
  • Customize (15-39)
  • Customize (43-81)
backend/FwLite/LcmCrdt/CompiledModels/ComplexFormComponentEntityType.cs (3)
backend/FwLite/LcmCrdt/CompiledModels/ComplexFormTypeEntityType.cs (3)
  • RuntimeEntityType (20-91)
  • RuntimeForeignKey (93-102)
  • Customize (116-116)
backend/FwLite/LcmCrdt/CompiledModels/EntryEntityType.cs (3)
  • RuntimeEntityType (21-245)
  • RuntimeForeignKey (247-256)
  • Customize (270-270)
backend/FwLite/LcmCrdt/Data/CompileModelCustomization.cs (2)
  • Customize (15-39)
  • Customize (43-81)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build FwHeadless / publish-fw-headless
  • GitHub Check: Build API / publish-api
  • GitHub Check: Analyze (csharp)
  • GitHub Check: Build FW Lite and run tests
🔇 Additional comments (54)
backend/harmony (1)

1-1: Submodule reference update looks good.

This file only updates the submodule pointer. Please ensure the referenced commit is tested and compatible with the parent repository, especially given the recent EF Core and AoT changes.

backend/FwLite/Taskfile.yml (1)

36-39: Good addition for AoT compilation support!

This new task compile-db-model correctly sets up the generation of compiled Entity Framework models using dotnet ef dbcontext optimize. This is an essential step for Ahead-of-Time compilation as it creates source-generated models that don't rely on runtime reflection.

backend/FwLite/LcmCrdt/JsonSourceGenerationContext.cs (1)

12-65: Well-structured JSON source generation configuration

This implementation correctly sets up System.Text.Json source generation, which is essential for AoT compilation. You've properly:

  1. Created a partial class derived from JsonSerializerContext
  2. Configured all required model types with JsonSerializable attributes
  3. Set up the minimal options needed for the serialization context

This approach eliminates runtime reflection during JSON serialization/deserialization, which is necessary for AOT compilation on macOS.

backend/FwLite/LcmCrdt/LcmCrdtKernel.cs (6)

93-110: Good addition of explicit Linq2DB conversions

The additional conversion logic for Linq2DB is necessary since the compiled models aren't being automatically detected. Using the LcmCrdtDbContext centralized serialization methods ensures consistency across the application.


128-133: Useful utility method for CrdtConfig creation

This convenience method for creating and configuring a CrdtConfig instance promotes code reuse and consistency.


156-162: Consistent serialization approach

Replacing direct JsonSerializer calls with the centralized LcmCrdtDbContext.Serialize/Deserialize methods ensures consistent serialization behavior and proper AoT compatibility.


175-176: Aligned serialization pattern

Good consistency with the serialization approach used throughout the codebase.


186-186: Good default sentinel value

Adding a sentinel default value for WritingSystemId is a good practice for entity framework relationships.


190-192: Consistent serialization pattern

Using the same serialization approach for the Exemplars property maintains consistency.

backend/FwLite/LcmCrdt/LcmCrdtDbContext.cs (3)

21-21: Excellent use of compiled model

Using the pre-compiled EF Core model instance is crucial for AoT compilation as it eliminates runtime model building.


45-52: Good refactoring of converter classes

Making the converter classes internal and updating them to use the centralized serialization methods is a necessary change for AoT compatibility.


57-66: Well-implemented serialization utilities

These centralized serialization methods provide a consistent approach to JSON handling throughout the application. The exception thrown on deserialization failure is a good practice to catch issues early.

backend/FwLite/LcmCrdt/CompiledModels/LcmCrdtDbContextModel.cs (2)

20-34: Review the thread-based initialization approach for potential complexity.
While creating and joining a dedicated thread ensures isolation, it might introduce extra overhead or future concurrency concerns. Consider using a Task or performing a direct synchronous call instead, unless a separate thread is strictly required.

Would you like to confirm whether any unhandled exceptions could occur in the new thread? If so, I can propose a quick script to scan for try-catch handling within the initialization path.


43-45: Ensure partial methods Initialize() and Customize() are implemented in companion files.
These partial definitions rely on actual implementations to perform model building and customization. Verify that the corresponding partial methods exist and are properly invoked.

backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.VerifyDbModel.verified.txt (2)

269-269: Confirm the use of Sentinel:default on WsId.
The sentinel value implies a default fallback for WritingSystemId. Double-check that this accurately represents the domain's expected default.


307-313: Validate the relational annotations on HybridDateTime.
Lines 307-313 indicate a complex property with additional relational mapping but no direct table or schema references. Ensure this complex property is correctly persisted and recognized by EF.

backend/FwLite/LcmCrdt/CompiledModels/ProjectDataEntityType.cs (2)

14-20: Entity naming consistency looks good.
Using "LcmCrdt.ProjectData" as the entity name aligns well with the domain naming convention. No immediate concerns.


70-76: Check constraints on the Name column.
Currently, Name is a simple string with no specified length or validation. If there's any length limit or data format requirement, consider adding constraints in the domain model or column definition.

backend/FwLite/LcmCrdt/CompiledModels/PartOfSpeechEntityType.cs (3)

45-75: JSON-based Name property converter looks robust.
Storing MultiString as JSON is a neat solution. This approach should maintain flexibility. The custom ValueComparer also ensures consistent change tracking.


76-97: Double-check handling of the Predefined boolean.
By default, its sentinel is false. Confirm whether there's any scenario where true should be used as a default to avoid confusion or data mismatch.


99-103: SnapshotId usage appears correct.
This nullable GUID property ensures that partial data or dependencies can be softly linked or separated. The unique index and SetNull behavior is consistent with the rest of the model.

backend/FwLite/LcmCrdt/CompiledModels/SemanticDomainEntityType.cs (3)

52-81: Name property leverages a JSON-based multi-string converter.
This is consistent with other entity definitions. The mapping, comparer, and converter approach is well-structured.


83-104: Predefined boolean consistency check.
Similar to other entities, the sentinel value is false. Ensure domain logic is not expecting a default true for certain semantic domains.


105-110: Verify relationships involving SnapshotId.
SnapshotId here is a key part of the foreign key to an ObjectSnapshot. Confirm that the SetNull behavior is correct for all domain scenarios.

backend/FwLite/LcmCrdt/CompiledModels/ComplexFormTypeEntityType.cs (3)

93-102: Confirm foreign key uniqueness requirement.
The foreign key is declared with unique: true and deleteBehavior: DeleteBehavior.SetNull. Verify that a single principal entity can indeed handle multiple dependents if needed. Setting unique to true enforces one-to-one semantics, which might be correct for your use case, but confirm that it aligns with domain requirements.


104-114: Validate table naming and schema usage.
The entity is annotated to map to the table "ComplexFormType", with a null schema, which is standard for SQLite. Ensure consistency across the codebase if you rely on naming conventions or a specific schema approach for deployment.


20-91:

❓ Verification inconclusive

Consider verifying usage of "jsonb" with SQLite.
Although specifying the store type as "jsonb" can be harmless in many SQLite setups, it is typically associated with PostgreSQL. Having a mismatched store type might be confusing or misleading to future maintainers. If you aim to support cross-database functionality or if there's a strict requirement for SQLite, consider clarifying or standardizing the type to "TEXT" (or a more appropriate SQLite-compatible type).

If you want to validate the usage, you could run a quick check on the generated migrations or database schema:


🏁 Script executed:

#!/bin/bash
# Show CREATE TABLE statements for ComplexFormType in SQLite
# (Replace 'your_database_file.db' with your actual database file)
sqlite3 your_database_file.db ".schema ComplexFormType"

Length of output: 155


Verify the usage of "jsonb" for SQLite compatibility
The code in backend/FwLite/LcmCrdt/CompiledModels/ComplexFormTypeEntityType.cs (lines 20–91) configures the "Name" property with a SQL store type "jsonb", which is typically associated with PostgreSQL. Our attempted validation via the SQLite command failed because the sqlite3 utility was not available, so we couldn’t automatically verify that the generated schema is as expected in a SQLite environment.

  • Please manually verify the schema (or run the migration) in an environment where sqlite3 is available to ensure that using "jsonb" is intentional and correctly handled.
  • If targeting SQLite exclusively (or aiming for cross-database functionality), consider using an appropriate SQLite type such as "TEXT" or implementing a custom SQLite-compatible mapping for JSON data.
backend/FwLite/LcmCrdt/Data/CompileModelCustomization.cs (2)

15-39: Thorough converter usage for IChange property.
You are correctly attaching a custom JSON converter for the Change property, which is crucial for storing interface-based objects in relational columns. This approach looks robust. Just confirm that the JsonSerializerOptions modifications (lines 23–25) do not conflict with other parts of the system that might override or reuse the same options instance.


43-82: Verify references property element type mapping.
Setting the element type explicitly (line 80) enables EF Core to treat ObjectSnapshot.References as a primitive collection. This is helpful for your intended JSON storage. However, be sure it correctly handles any advanced scenarios, such as partial updates or concurrency checks on the array. Testing concurrency scenarios or partial updates might be beneficial.

backend/FwLite/LcmCrdt/CompiledModels/WritingSystemEntityType.cs (2)

200-209: Ensure one-to-one relationship is intentional.
A foreign key with unique: true implies a one-to-one or one-to-zero/one relationship, and DeleteBehavior.SetNull ensures proper orphaning behavior. Confirm that each WritingSystem instance having at most one parent entity matches your domain model intent.


211-221: Good use of partial method for customization.
Providing a partial method Customize(runtimeEntityType) invites flexible post-processing of EF Core mappings, thereby separating generated code from manual overrides. This is a sound approach for maintainability.

backend/FwLite/LcmCrdt/CompiledModels/PublicationEntityType.cs (3)

104-114: No issues found
The table name, schema, and other relational annotations look consistent with the rest of the file.


93-102:

❓ Verification inconclusive

Confirm desired foreign key uniqueness
You have marked the foreign key as unique: true with DeleteBehavior.SetNull. This results in a one-to-one relationship. Confirm that this is intended and will handle all use cases properly.


🏁 Script executed:

#!/bin/bash
# Verify usage of the SnapshotId foreign key in the codebase
rg -A 5 "SnapshotId"

Length of output: 65674


Confirm one-to-one FK relationship with SnapshotId is intended
The use of unique: true combined with DeleteBehavior.SetNull for the SnapshotId foreign key is consistently applied across several entity types (e.g., ComplexFormComponent, ExampleSentence, ComplexFormType, WritingSystem, and Publication) as verified in the codebase and accompanying tests. This confirms that the design enforces a one-to-one relationship between the dependent entity and the corresponding snapshot.

Please confirm that this one-to-one relationship is indeed the desired behavior for all use cases before finalizing the changes.


20-90:

❓ Verification inconclusive

Consider verifying 'jsonb' usage with SQLite
Although the property is annotated with "jsonb", SQLite does not natively support the jsonb type as PostgreSQL does. If this is intentional or handled by a custom extension, please ensure proper runtime testing.


🏁 Script executed:

#!/bin/bash
# Search for additional references to "jsonb" in the codebase
rg -A 5 "jsonb"

Length of output: 77284


Action Required: Confirm SQLite JSON Handling

The use of "jsonb" is consistently applied throughout the repository—in migrations, model snapshots, and various entity type configurations (including in PublicationEntityType.cs). Although SQLite doesn’t natively support a PostgreSQL-style jsonb type, the code employs a custom mapping strategy (e.g., via SqliteStringTypeMapping.Default.Clone, custom value converters, and JSON reader/writer implementations) to handle JSON serialization.

Please confirm that:

  • The custom mapping correctly emulates the intended behavior when running against SQLite.
  • Adequate runtime tests are in place to ensure edge cases are covered.
backend/FwLite/LcmCrdt/CompiledModels/ChangeEntityEntityType.cs (2)

108-124: Cascade delete confirmation
The foreign key enforces DeleteBehavior.Cascade. This may trigger extensive cascade deletions if a commit is removed. Confirm it aligns with the system’s desired logic.


126-136: No issues found
Table name and other relational annotations are consistent.

backend/FwLite/LcmCrdt/CompiledModels/ExampleSentenceEntityType.cs (4)

21-163: Double check use of double and 'jsonb'

  1. Storing an Order as double can introduce floating precision issues. Consider decimal or int if precise ordering/sorting must be guaranteed.
  2. The jsonb column type might not be recognized by SQLite unless a custom provider extension is in place—verify runtime behavior.

166-182: Cascade delete on Sense
Deleting a Sense will remove all associated ExampleSentences. This is typically desired if ExampleSentences only make sense in the context of their Sense.


184-193: Confirm unique foreign key usage
Enforcing a unique: true foreign key on SnapshotId with DeleteBehavior.SetNull suggests a one-to-one link. Ensure that your domain model requires this strict uniqueness.


195-205: No issues found
The table name and schema annotations are consistent with the rest of the file.

backend/FwLite/LcmCrdt/CompiledModels/ObjectSnapshotEntityType.cs (2)

50-78: Confirm the feasibility of storing IObjectBase in JSON.
Storing complex objects directly in JSON can make querying or partial updates more cumbersome. Ensure that all current and future querying needs are met and that performance is acceptable when serializing/deserializing.


167-172: Verify uniqueness requirements for the composite index on (CommitId, EntityId).
Confirm that only one ObjectSnapshot can match this combination. If multiple snapshots should share the same commit and entity, this uniqueness constraint may need revisiting.

backend/FwLite/LcmCrdt/CompiledModels/EntryEntityType.cs (2)

70-98: Assess potential performance impacts of storing ComplexFormTypes as JSON.
Large or frequently updated lists could degrade performance during serialization/deserialization and hamper complex queries.


240-243: Confirm whether the unique constraint on snapshotId aligns with your domain logic.
A unique index on a nullable property may limit usage if multiple entries could share the same snapshot reference.

backend/FwLite/LcmCrdt/CompiledModels/CommitEntityType.cs (2)

54-82: Ensure CommitMetadata JSON usage meets functional and performance needs.
Storing metadata in JSON can reduce schema complexity but might complicate advanced filtering. Confirm coverage in tests and migrations.


99-171: Review the HybridDateTime complex property for accuracy and time zone handling.
The ValueConverter<DateTimeOffset, DateTime> sets the offset to UTC. Verify this won’t cause unexpected discrepancies when storing local times.

backend/FwLite/LcmCrdt/CompiledModels/SenseEntityType.cs (5)

19-27: Entity registration appears correct.

The Create(...) method correctly registers the Sense entity and sets it as a RuntimeEntityType for EF Core. The usage of model.AddEntityType("MiniLcm.Models.Sense", typeof(Sense)) is consistent with standard EF Core entity registration practices.


146-175: Verify JSON column type for “SemanticDomains”.

Similarly, the “SemanticDomains” property also uses "jsonb". Ensure your SQLite environment (or any other provider) supports this column type or that the "jsonb" annotation is purely informational. If you do intend to run on PostgreSQL, this is fine, but otherwise confirm it won’t break in production.


199-242: Foreign key structure seems appropriate.

The foreign keys reference other entities (Entry, PartOfSpeech, Snapshot) with reasonable delete behaviors (Cascade or SetNull). Ensure that these behaviors match your domain requirements (e.g., whether you truly want to cascade deletions of Sense when you remove Entry).


256-256: Partial method usage.

The static partial void Customize(RuntimeEntityType runtimeEntityType); hook is a useful extension point. Verify that the corresponding partial implementation is present in another file (e.g. CompileModelCustomization.cs) so that any custom converters or logic is applied as intended.


38-68:

✅ Verification successful

Potential mismatch using "jsonb" with SQLite.

The property “Definition” is assigned a relational column type of "jsonb", which is typically a PostgreSQL-specific type. Since the type mapping references SqliteStringTypeMapping.Default and the file references Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal, confirm that the "jsonb" annotation and column type won’t cause issues on SQLite.

Below is a script to verify the actual DDL or migrations for this property, ensuring the "jsonb" type is recognized or mapped appropriately in SQLite:


🏁 Script executed:

#!/bin/bash
# Description: Scan migrations or generated SQL for any mismatch with column type "jsonb" on SQLite.

# Look for migration files or code referencing "Definition" or "jsonb"
fd 'Migrations' --type d --max-depth 3 --exec rg 'Definition|jsonb'

Length of output: 8229


Mapping Clarification & Resolution on "jsonb" Annotation for SQLite

After scanning the migrations, we see that several migration files (in the LexData area) intentionally use "jsonb" as the column type. In the SenseEntityType.cs file, the property is mapped using the SQLite type mapping (via SqliteStringTypeMapping.Default.Clone), and SQLite’s typeless nature means that the "jsonb" annotation will be treated as text without negative side effects. This confirms that the use of "jsonb" here is deliberate and should not cause issues on SQLite.

To improve clarity, consider adding a brief comment in the code explaining that—even though "jsonb" is PostgreSQL-specific—using the SQLite string type mapping ensures correct handling within SQLite.

backend/FwLite/LcmCrdt/CompiledModels/ComplexFormComponentEntityType.cs (3)

19-25: Entity registration is consistent.

The Create(...) method properly registers ComplexFormComponent as a RuntimeEntityType. The approach aligns with how EF Core sets up runtime models.


127-134: Multiple unique indexes on combined columns.

You have two unique indexes:

  1. (complexFormEntryId, componentEntryId)
  2. (complexFormEntryId, componentEntryId, componentSenseId)

Confirm these indexing requirements don’t overlap or cause conflicts in scenarios where componentSenseId is null. Also verify that unique constraints with partial or null columns behave as intended on your database provider.


195-205: Ensure partial Customize implementation exists.

Like other compiled model files, this file calls Customize(runtimeEntityType) at line 204. Verify that your partial method implementation in another file (e.g. CompileModelCustomization.cs) is present and that you handle any additional JSON serialization or property conversion logic for ComplexFormComponent as needed.

@hahn-kev hahn-kev added the 💻 FW Lite issues related to the fw lite application, not miniLcm or crdt related label Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 FW Lite issues related to the fw lite application, not miniLcm or crdt related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MacOS dotnet publish results in NativeAOT error
1 participant