Skip to content

Database

Run a local SQL Server instance with Docker:

Terminal window
docker run --name sql2022 \
-e 'ACCEPT_EULA=Y' \
-e 'MSSQL_SA_PASSWORD=<password>' \
-p 1433:1433 \
-d mcr.microsoft.com/mssql/server:2022-latest

Build and deploy the schema:

Terminal window
cd src/data/app
dotnet build
SqlPackage /Action:Publish \
/SourceFile:"data.app.dacpac" \
/TargetUser:sa \
/TargetPassword:<password> \
/TargetServerName:. \
/TargetDatabaseName:Formation \
/TargetEncryptConnection:False \
/v:environment=dev \
/p:BlockOnPossibleDataLoss=False

The database uses a relational model with the following core tables:

TableDescription
SchemeProperty schemes
DevelopmentDevelopments within schemes
CompanyCompany directory
AddressPhysical addresses with geometry
AuditLogChange audit trail

Spatial data is stored using SQL Server’s geometry type and accessed via NetTopologySuite in EF Core. The API exposes geometry as WKT (Well-Known Text) strings.

-- Example: Find schemes within 5km of a point
SELECT * FROM Scheme s
JOIN Address a ON s.AddressId = a.AddressId
WHERE a.Location.STDistance(geometry::Point(51.5074, -0.1278, 4326)) < 5000

Full-text indexing is enabled on key fields. The full-text catalogue is defined in the SQL project under FullTextCatalogs/.

All write operations are automatically logged via IAuditLogger:

ColumnDescription
TableNameEntity type
OperationTypeINSERT, UPDATE, DELETE, MERGE
UserNameFrom JWT claims
PreviousValueJSON of old state
NewValueJSON of new state