mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 06:51:13 +00:00
5d84d2839e
Step 12 (Test-Spec Sync, cycle-update mode): - blackbox-tests.md: append BT-23..BT-26 for AZ-505's new observable behaviors (inventory order/shape; leaflet most-recent via location_hash; HTTP/2 multiplex over TLS+ALPN; request validation). - performance-tests.md: append PT-09 (inventory p95 ≤ 1000ms / 2500 tiles); records cycle-6 measured p95=66ms; documents promotion path to scripts/run-performance-tests.sh if budget ever tightens. - traceability-matrix.md: resolve the 5 AZ-503 deferrals (AC-5/6/9/10/12) by pointing at AZ-505 test names + add 7 AZ-505 AC rows (AC-1..AC-7) + bump totals (90 -> 94 tests, 56/56 -> 63/63 in-scope) + add cycle-6 coverage shape notes (budget relaxation rationale, voting-filter deferral note, TLS+ALPN pivot, NFR propagation). Step 13 (Update Docs, task mode): - common_dtos.md: add 5 new TileInventory DTOs. - common_interfaces.md: add ITileService.GetInventoryAsync. - services_tile_service.md: document TileService.GetInventoryAsync steps + the XOR-validation-in-handler note. - dataaccess_migrator.md: bump migration count 14 -> 15; describe migration 015 (AZ-505 leaflet covering index, lock window, INCLUDE-list trade-off). - system-flows.md: add F7 (Leaflet Tile Serving, AZ-310 + AZ-505 location_hash rewire + TLS+ALPN) and F8 (Tile Inventory Bulk Lookup) with sequence diagrams, validation surface, and AC-4 perf evidence. Update Flow Inventory + Dependencies tables accordingly. - glossary.md: add "Tile Inventory" entry pointing at the v1.0.0 contract. - ripple_log_cycle6.md: new file — exhaustive reverse-dependency analysis confirms zero stale downstream module docs. Advance autodev state from step 11 -> 14 (skipping 12+13 as completed in this commit; auto-chain through Step 14 = Security Audit optional gate). Co-authored-by: Cursor <cursoragent@cursor.com>
4.6 KiB
4.6 KiB
Module: DataAccess/DatabaseMigrator
Purpose
Runs DbUp-based SQL migrations against PostgreSQL on application startup. Ensures the database schema is up to date before the API begins serving requests.
Public Interface
DatabaseMigrator
- Constructor:
DatabaseMigrator(string connectionString, ILogger<DatabaseMigrator>? logger) RunMigrations() → bool: creates the database if missing (EnsureDatabase.For.PostgresqlDatabase), then runs all embedded SQL scripts matching.Migrations.from the DataAccess assembly. Returnstrueon success.
Internal Logic
- Uses
DbUp.DeployChangesfluent API targeting PostgreSQL - Scripts are embedded resources filtered by path containing
.Migrations. - Logs to console via DbUp's built-in
LogToConsole() - On failure, logs the error and returns
false
Dependencies
- NuGet:
dbup-postgresql(6.0.3) Microsoft.Extensions.Logging- Embedded SQL resources from
SatelliteProvider.DataAccess/Migrations/
Consumers
Program.cs— instantiated directly (not via DI) and called during startup. If migration fails, the application throws and does not start.
Migrations (15 scripts)
001_CreateTilesTable.sql002_CreateRegionsTable.sql003_CreateIndexes.sql004_AddVersionColumn.sql005_CreateRoutesTables.sql006_AddStitchTilesToRegions.sql007_AddRouteMapFields.sql008_AddGeofenceFlagToRouteRegions.sql009_AddGeofencePolygonIndex.sql010_AddTilesZipToRoutes.sql011_AddTileCoordinates.sql012_DropTileVersionConstraint.sql— drops the legacy 5-col(latitude, longitude, tile_zoom, tile_size_meters, version)unique index, replaces with 4-colidx_tiles_unique_location(preparation for AZ-484).013_AddTileSourceAndCapturedAt.sql— AZ-484 multi-source tile storage. Transactional. Addssource(VARCHAR(32) NOT NULL DEFAULT 'google_maps') andcaptured_at(TIMESTAMP NOT NULL) columns; backfills existing rows withsource='google_maps',captured_at=created_at; dropsidx_tiles_unique_locationand creates 5-colidx_tiles_unique_location_sourceon(latitude, longitude, tile_zoom, tile_size_meters, source). Idempotent against partial replays.014_AddTileIdentityColumns.sql— AZ-503 tile-identity foundation. Transactional. Enables thepgcryptoextension (CREATE EXTENSION IF NOT EXISTS pgcrypto) for the in-migration SHA-1 digest. Addsflight_id(UUID NULL),location_hash(UUID — backfilled then set NOT NULL),content_sha256(BYTEA NULL),legacy_id(UUID NULL). Defines a transactionalpg_temp.uuidv5(namespace, name)PL/pgSQL function that mirrorsSatelliteProvider.Common.Utils.Uuidv5.Createbyte-for-byte, then backfillslocation_hash = pg_temp.uuidv5(TILE_NAMESPACE, '{tile_zoom}/{tile_x}/{tile_y}')andlegacy_id = idfor every pre-existing row. Drops AZ-484'sidx_tiles_unique_location_sourceand createsidx_tiles_unique_identityUNIQUE on(tile_zoom, tile_x, tile_y, tile_size_meters, source, COALESCE(flight_id, '00000000-0000-0000-0000-000000000000'::uuid))plus a non-uniqueidx_tiles_location_hashon(location_hash). Safe to replay on a partially-migrated database because column adds areIF NOT EXISTS-equivalent andpg_temp.uuidv5is deterministic — re-running yields the samelocation_hashvalues.015_AddTilesLeafletPathIndex.sql— AZ-505 leaflet covering index. Transactional. Createstiles_leaflet_pathcovering index on(location_hash, captured_at DESC, updated_at DESC, id DESC) INCLUDE (file_path, source)so the leaflet hot path (SELECT file_path FROM tiles WHERE location_hash = $1 ORDER BY captured_at DESC, updated_at DESC, id DESC LIMIT 1) becomes anIndex Only ScanonceVACUUM ANALYZEsets the visibility map. Drops the lightweightidx_tiles_location_hashintroduced by migration 014 — the new covering index has the same leading column, so equality lookups bylocation_hashuse it instead. Lock window: runs in DbUp's per-script transaction (incompatible withCREATE INDEX CONCURRENTLY); on a populatedtilestable the build holds anACCESS SHARE+SHARElock for the build duration, blocking writes (see AZ-505 Risk 2). Inventory queries (GetTilesByLocationHashesAsync) intentionally project columns beyond the INCLUDE list (id,captured_at,flight_id, etc.) and therefore trigger a bounded heap fetch — acceptable per AZ-505 NFR-Perf-2 (p95 ≤ 1000 ms / 2500 tiles) and explicit in the migration header.
Configuration
Receives connection string directly as constructor parameter.
External Integrations
PostgreSQL — DDL operations via DbUp.
Security
None directly, but controls schema evolution.
Tests
No dedicated tests.