CI / Build and test (SQLite) (pull_request) Successful in 45s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 3s
CI / Docker image (pull_request) Successful in 51s
Every later milestone stores its data through this layer, so it has to behave the same on both engines and be safe by construction: - Khaemhat.Data: explicit entity maps, typed queries over a safe expression subset, SqlFragment where every interpolated value becomes a parameter, unit of work with transactions, repositories with audit columns and optimistic concurrency on row_version, retries on transient errors. - SQLite provider (STRICT tables, WAL, exact decimals as integers scaled by 10^6, Unicode case-insensitive LIKE, serialised writes) and PostgreSQL 16+ provider (numeric(19,6), timestamptz, jsonb, advisory locks, database creation and server info). Databases are configured from postgres:// and sqlite:// URLs whose password never appears in messages. - C# migrations with system and company catalogues, schema_version with checksums, one transaction per migration under a lock, refusal of unknown applied versions; first system tables sys_companies and sys_settings. - CompanyRegistry stores each company's database URL encrypted with the instance key (AES-256-GCM, HKDF-derived key, purpose as associated data), so a copied row cannot be read for another company. - tools/Khaemhat.DataModelTool, scripts/gen-datamodel.sh and scripts/new-migration.sh: the current schema section of docs/DATA-MODEL.md is generated from the migrations and a test fails when it is stale. - C# 14 binds array.Contains to MemoryExtensions over spans; the query translator unwraps the span conversion. - Tests run every data scenario on SQLite and PostgreSQL (PostgreSQL in CI); ADR 0018 records where the contracts differ from SPEC 5.1. Docs, wiki, changelog and status updated. Closes #7, #8, #9, #10, #11, #12, #13, #14 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
1.9 KiB
C#
80 lines
1.9 KiB
C#
using Khaemhat.Core.Entities;
|
|
using Khaemhat.Data.Mapping;
|
|
using Khaemhat.Data.Schema;
|
|
|
|
namespace Khaemhat.Data.Tests.Support;
|
|
|
|
internal enum TestKind
|
|
{
|
|
Goods = 0,
|
|
Service = 1,
|
|
Kit = 2,
|
|
}
|
|
|
|
/// <summary>An entity with one property of every logical type.</summary>
|
|
internal sealed class TestItem : Entity<long>, IDemoMarkable
|
|
{
|
|
public string Code { get; set; } = string.Empty;
|
|
|
|
public string? Name { get; set; }
|
|
|
|
public int Quantity { get; set; }
|
|
|
|
public long Big { get; set; }
|
|
|
|
public decimal Amount { get; set; }
|
|
|
|
public bool Active { get; set; }
|
|
|
|
public DateOnly? Day { get; set; }
|
|
|
|
public DateTime? At { get; set; }
|
|
|
|
public Guid? Uid { get; set; }
|
|
|
|
public byte[]? Data { get; set; }
|
|
|
|
public string? Payload { get; set; }
|
|
|
|
public TestKind Kind { get; set; }
|
|
|
|
public bool IsDemo { get; set; }
|
|
}
|
|
|
|
internal sealed class TestItemMap : EntityMap<TestItem>
|
|
{
|
|
public TestItemMap()
|
|
{
|
|
ToTable("test_items");
|
|
Map(x => x.Code).MaxLength(20);
|
|
Map(x => x.Name).MaxLength(100);
|
|
Map(x => x.Payload).Json();
|
|
}
|
|
|
|
public static IReadOnlyList<SchemaOperation> Schema()
|
|
{
|
|
var schema = new SchemaBuilder();
|
|
schema.CreateTable("test_items", t =>
|
|
{
|
|
t.Id();
|
|
t.String("code", 20).NotNull();
|
|
t.String("name", 100);
|
|
t.Int32("quantity").NotNull();
|
|
t.Int64("big").NotNull();
|
|
t.Decimal("amount").NotNull();
|
|
t.Bool("active").NotNull();
|
|
t.Date("day");
|
|
t.DateTimeUtc("at");
|
|
t.Guid("uid");
|
|
t.Bytes("data");
|
|
t.Json("payload");
|
|
t.String("kind", 40).NotNull();
|
|
t.DemoColumn();
|
|
t.AuditColumns();
|
|
t.Unique("ux_test_items_code", "code");
|
|
t.Index("ix_test_items_at", "at");
|
|
});
|
|
return schema.Operations;
|
|
}
|
|
}
|