mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 08:11:13 +00:00
687d6bdd5b
Add per-source tile rows to support multi-provider imagery (Google Maps + future UAV). Migration 013 (transactional) introduces source/captured_at columns, backfills existing rows to (source='google_maps', captured_at=created_at), and replaces the 4-column unique index with a 5-column index that includes source. TileRepository: - ColumnList includes source + captured_at - GetByTileCoordinatesAsync returns most-recent row across sources (ORDER BY captured_at DESC, updated_at DESC, id DESC) - GetTilesByRegionAsync uses DISTINCT ON to pick the most-recent tile per cell, restoring caller-facing row order - Insert/Update upsert on the new 5-column conflict key TileSource enum lives in Common.Enums. Snake_case wire format (google_maps, uav) is enforced by a focused TileSourceTypeHandler because the generic ToLowerInvariant pattern would emit "googlemaps", violating contract v1.0.0. TileService stamps Source=GoogleMaps + CapturedAt=UtcNow on every new tile. Tile-storage contract is now frozen at v1.0.0. AC coverage 7/7. New unit + integration tests cover all ACs; existing 200 unit + 5 smoke tests preserved. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System.Data;
|
|
using Dapper;
|
|
using SatelliteProvider.Common.Enums;
|
|
|
|
namespace SatelliteProvider.DataAccess.TypeHandlers;
|
|
|
|
// AZ-484: TileSource needs an explicit string mapping because the multi-word
|
|
// member 'GoogleMaps' must round-trip as the snake_case wire value 'google_maps'
|
|
// per the v1.0.0 tile-storage contract. The generic EnumStringTypeHandler<T>
|
|
// only does ToString().ToLowerInvariant(), which would emit 'googlemaps'.
|
|
public class TileSourceTypeHandler : SqlMapper.TypeHandler<TileSource>
|
|
{
|
|
public const string GoogleMapsWireValue = "google_maps";
|
|
public const string UavWireValue = "uav";
|
|
|
|
public override TileSource Parse(object value)
|
|
{
|
|
if (value is null || value is DBNull)
|
|
{
|
|
throw new DataException("Cannot parse null DB value into enum TileSource");
|
|
}
|
|
|
|
var s = value as string ?? value.ToString();
|
|
if (string.IsNullOrEmpty(s))
|
|
{
|
|
throw new DataException("Cannot parse empty DB value into enum TileSource");
|
|
}
|
|
|
|
return s.ToLowerInvariant() switch
|
|
{
|
|
GoogleMapsWireValue => TileSource.GoogleMaps,
|
|
UavWireValue => TileSource.Uav,
|
|
_ => throw new DataException($"DB value '{s}' is not a defined member of enum TileSource"),
|
|
};
|
|
}
|
|
|
|
public override void SetValue(IDbDataParameter parameter, TileSource value)
|
|
{
|
|
parameter.Value = ToWireValue(value);
|
|
parameter.DbType = DbType.String;
|
|
}
|
|
|
|
public static string ToWireValue(TileSource value) => value switch
|
|
{
|
|
TileSource.GoogleMaps => GoogleMapsWireValue,
|
|
TileSource.Uav => UavWireValue,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown TileSource"),
|
|
};
|
|
}
|