Sqlite support added to C# plugin#854
Sqlite support added to C# plugin#854matecsad wants to merge 1 commit intoEricsson:feature/csharp_pluginfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds SQLite support to the C# plugin by refactoring the EF Core model into a shared DbModel project and introducing separate EF Core migration projects for PostgreSQL and SQLite, enabling the parser/service components to target either DB backend.
Changes:
- Extract EF Core entities/DbContext into a new
plugins/csharp/db_modelproject and update parser/service to reference it. - Add SQLite EF Core provider dependencies and SQLite migration project alongside PostgreSQL migrations.
- Update connection-string handling and DbContext configuration to select provider/migrations by a DB “scheme” prefix (e.g.,
pgsql:vssqlite:).
Reviewed changes
Copilot reviewed 27 out of 31 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/csharp/service/src_csharp/csharpservice.csproj | Switches from compiling model sources to referencing DbModel; adds SQLite provider package. |
| plugins/csharp/service/src_csharp/CSharpQueryServer.cs | Updates model namespace usage to DbModel. |
| plugins/csharp/service/src_csharp/CSharpQueryHandler.cs | Creates CsharpDbContext based on scheme; updates AST node lookup; adds connection-string transformation helper. |
| plugins/csharp/parser/src_csharp/Program.cs | Updates to use DbModel DbContext; adds scheme-based connection-string transform; adjusts assembly scanning logic. |
| plugins/csharp/parser/src_csharp/CSharpParser.csproj | Replaces compiled-in model/migrations with project references; adds EF Core design + SQLite provider. |
| plugins/csharp/parser/src_csharp/AstVisitor.cs | Updates model namespace usage to DbModel. |
| plugins/csharp/model/CsharpEntity.cs | Removes old in-project model type (moved to DbModel). |
| plugins/csharp/model/CsharpDbContext.cs | Removes old in-project DbContext (moved to DbModel). |
| plugins/csharp/migrations/sqliteMigrations/SqliteMigrations.csproj | New SQLite migrations project referencing DbModel. |
| plugins/csharp/migrations/sqliteMigrations/SqliteDbContextModelSnapshot.cs | Adds SQLite model snapshot for migrations. |
| plugins/csharp/migrations/sqliteMigrations/20260302184000_Initial.cs | Adds initial SQLite migration. |
| plugins/csharp/migrations/sqliteMigrations/20260302184000_Initial.Designer.cs | Adds SQLite migration designer metadata. |
| plugins/csharp/migrations/pgsqlMigrations/PgsqlMigrations.csproj | New PostgreSQL migrations project referencing DbModel. |
| plugins/csharp/migrations/pgsqlMigrations/CsharpDbContextModelSnapshot.cs | Moves PostgreSQL model snapshot into new project. |
| plugins/csharp/migrations/pgsqlMigrations/20220518134047_Initial.cs | Moves initial PostgreSQL migration into new project. |
| plugins/csharp/migrations/pgsqlMigrations/20220518134047_Initial.Designer.cs | Moves PostgreSQL migration designer metadata into new project. |
| plugins/csharp/migrations/CsharpDbContextModelSnapshot.cs | Removes old snapshot location. |
| plugins/csharp/migrations/20220518134047_Initial.cs | Removes old migration location. |
| plugins/csharp/migrations/20220518134047_Initial.Designer.cs | Removes old migration designer location. |
| plugins/csharp/db_model/DbModel.csproj | New shared model project with EF Core + providers. |
| plugins/csharp/db_model/CsharpVariable.cs | Updates namespace to DbModel; makes entity/enum public. |
| plugins/csharp/db_model/CsharpNamespace.cs | Updates namespace to DbModel; makes entity public. |
| plugins/csharp/db_model/CsharpMethod.cs | Updates namespace to DbModel; makes entity/enum public. |
| plugins/csharp/db_model/CsharpEnumMember.cs | Updates namespace to DbModel; makes entity public; adds FK id. |
| plugins/csharp/db_model/CsharpEnum.cs | Updates namespace to DbModel; makes entity public; relaxes nullability. |
| plugins/csharp/db_model/CsharpEntity.cs | New shared base entity/types in DbModel. |
| plugins/csharp/db_model/CsharpDbContext.cs | New shared DbContext selecting provider/migrations by scheme. |
| plugins/csharp/db_model/CsharpClass.cs | Updates namespace to DbModel; makes entities/enums public; relaxes nullability. |
| plugins/csharp/db_model/CsharpAstNode.cs | Updates namespace to DbModel; makes entity/enums public; relaxes nullability. |
| CodeCompass-fork.sln | Adds a Visual Studio solution including new projects. |
| .gitignore | Ignores Build/ directory. |
Files not reviewed (3)
- plugins/csharp/migrations/20220518134047_Initial.Designer.cs: Language not supported
- plugins/csharp/migrations/pgsqlMigrations/20220518134047_Initial.Designer.cs: Language not supported
- plugins/csharp/migrations/sqliteMigrations/20260302184000_Initial.Designer.cs: Language not supported
Comments suppressed due to low confidence (1)
plugins/csharp/parser/src_csharp/CSharpParser.csproj:29
- EF Core provider package version (Microsoft.EntityFrameworkCore.Sqlite 8.0.11 / Npgsql.EntityFrameworkCore.PostgreSQL 8.0.11) doesn’t match the shared EF Core runtime version (Microsoft.EntityFrameworkCore 8.0.20). Keeping EFCore + providers on the same patch version avoids binding/runtime incompatibilities; consider aligning all EF-related package versions.
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" /> |
There was a problem hiding this comment.
EF Core provider package versions (Sqlite 8.0.11 / Npgsql 8.0.11) don’t match the EF Core runtime version (8.0.20). Aligning EFCore and provider patch versions reduces the risk of runtime binding and subtle behavior mismatches.
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" /> | |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20"> | |
| <PrivateAssets>all</PrivateAssets> | |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
| </PackageReference> | |
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" /> | |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.20" /> | |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20"> | |
| <PrivateAssets>all</PrivateAssets> | |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | |
| </PackageReference> | |
| <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.20" /> |
| modelBuilder.HasAnnotation("ProductVersion", "8.0.20"); | ||
|
|
||
| modelBuilder.Entity("CSharpParser.model.CsharpAstNode", b => | ||
| { | ||
| b.Property<ulong>("Id") |
There was a problem hiding this comment.
This migration designer still references the old entity type names ("CSharpParser.model.*") even though the entities now live in DbModel. Regenerate/update the migration metadata to reflect the new namespaces to avoid inconsistencies when adding future migrations.
| .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); | ||
|
|
||
| modelBuilder.Entity("CSharpParser.model.CsharpAstNode", b => | ||
| { | ||
| b.Property<decimal>("Id") |
There was a problem hiding this comment.
This snapshot still uses entity type names under the old namespace ("CSharpParser.model.*") even though the model types have been moved to DbModel. Regenerate or update the migrations snapshot so the model reflects the current CLR namespaces; otherwise future migrations generation and model comparisons can become inconsistent.
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqliteMigrations", "plugins\csharp\migrations\sqliteMigrations\sqliteMigrations.csproj", "{4709E553-FC92-44D2-85CC-A1EFE918F70B}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pgsqlMigrations", "plugins\csharp\migrations\pgsqlMigrations\pgsqlMigrations.csproj", "{AB02187B-59AB-4E35-B1C8-B835F25B9692}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "db_model", "plugins\csharp\db_model\db_model.csproj", "{B9532E7A-2CB8-4DEC-A0DA-672AF7D054E6}" |
There was a problem hiding this comment.
The solution references csproj paths that don’t match the actual filenames’ casing (e.g., sqliteMigrations.csproj vs SqliteMigrations.csproj, db_model.csproj vs DbModel.csproj). This breaks loading/building the solution on case-sensitive filesystems. Update the paths to match the real on-disk filenames.
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqliteMigrations", "plugins\csharp\migrations\sqliteMigrations\sqliteMigrations.csproj", "{4709E553-FC92-44D2-85CC-A1EFE918F70B}" | |
| EndProject | |
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pgsqlMigrations", "plugins\csharp\migrations\pgsqlMigrations\pgsqlMigrations.csproj", "{AB02187B-59AB-4E35-B1C8-B835F25B9692}" | |
| EndProject | |
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "db_model", "plugins\csharp\db_model\db_model.csproj", "{B9532E7A-2CB8-4DEC-A0DA-672AF7D054E6}" | |
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqliteMigrations", "plugins\csharp\migrations\sqliteMigrations\SqliteMigrations.csproj", "{4709E553-FC92-44D2-85CC-A1EFE918F70B}" | |
| EndProject | |
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pgsqlMigrations", "plugins\csharp\migrations\pgsqlMigrations\pgsqlMigrations.csproj", "{AB02187B-59AB-4E35-B1C8-B835F25B9692}" | |
| EndProject | |
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "db_model", "plugins\csharp\db_model\DbModel.csproj", "{B9532E7A-2CB8-4DEC-A0DA-672AF7D054E6}" |
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" /> |
There was a problem hiding this comment.
EF Core provider package version (Microsoft.EntityFrameworkCore.Sqlite 8.0.11) doesn’t match the shared EF Core runtime version (8.0.20). Align provider and EFCore patch versions to avoid potential runtime/binding issues.
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" /> | |
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.20" /> |
| ulong NodeId = ulong.Parse(astNodeId); | ||
| ret = dbContext.CsharpAstNodes | ||
| .Where(a => a.Id.ToString()==astNodeId) | ||
| .Where(a => a.Id==NodeId) | ||
| .First(); |
There was a problem hiding this comment.
Parsing astNodeId with ulong.Parse can throw FormatException/OverflowException for non-numeric IDs, but only InvalidOperationException is caught. Use ulong.TryParse (or catch parse exceptions) and return a sensible not-found result instead of crashing the service on malformed input.
| else | ||
| { | ||
| // "sqlite:database=" needs to be removed from the connection string. | ||
| connectionString = connectionString.Substring(connectionString.IndexOf(':') + 10); | ||
| csharpConnectionString = "Data Source=" + connectionString; |
There was a problem hiding this comment.
transformConnectionString treats any dbSystem other than "pgsql" as SQLite and then slices the string using a hard-coded offset. This will mis-handle unknown schemes and is fragile to connection-string format changes. Consider explicitly handling only supported values ("pgsql"/"sqlite"), validating the expected prefix (e.g., "sqlite:database="), and throwing a clear error for unsupported formats.
| default: | ||
| break; | ||
| } |
There was a problem hiding this comment.
OnConfiguring silently does nothing for unknown _dbSystem values, leaving the DbContext potentially unusable and making misconfiguration hard to debug. Consider throwing an ArgumentException/InvalidOperationException with the supported values (or at least logging) in the default branch.
| .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); | ||
|
|
||
| modelBuilder.Entity("CSharpParser.model.CsharpAstNode", b => | ||
| { | ||
| b.Property<decimal>("Id") |
There was a problem hiding this comment.
This migration designer still references the old entity type names ("CSharpParser.model.*") even though the entities now live in DbModel. Regenerate/update the migration metadata to reflect the new namespaces to avoid inconsistencies when adding future migrations.
| <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" /> | ||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" /> |
There was a problem hiding this comment.
EF Core provider package version (Microsoft.EntityFrameworkCore.Sqlite 8.0.11) doesn’t match the shared EF Core runtime version (Microsoft.EntityFrameworkCore 8.0.20). Keeping EFCore + providers on the same patch version avoids binding/runtime incompatibilities; consider bumping the provider to 8.0.20 (or aligning all EF packages consistently).
Resolves #819