Files
satellite-provider/SatelliteProvider.DataAccess/Migrations/012_DropTileVersionConstraint.sql
T
Oleksandr Bezdieniezhnykh 581dff206e
ci/woodpecker/push/01-test Pipeline was successful
ci/woodpecker/push/02-build-push Pipeline was successful
[AZ-357] Refactor C06: drop tile Version concept; cumulative review batches 7-9
AZ-357 — eliminate year-based tile cache expiry (LF-1):
- Migration 012: drop 5-col unique index, dedupe by (lat,lon,zoom,
  size) keeping max(updated_at), add new 4-col unique index, make
  version column nullable + drop default. Column itself preserved
  per coderule (column drops require explicit confirmation; tracked
  in AZ-373 / C20).
- TileEntity.Version, TileMetadata.Version, DownloadTileResponse.
  Version: int -> int? (HTTP shape preserved; field still in JSON).
- TileService.DownloadAndStoreTilesAsync: drop currentVersion year
  computation and the .Where(t => t.Version == currentVersion)
  cache filter. BuildTileEntity: drop year arg; write Version=null.
- TileRepository: ON CONFLICT now 4-col; lookup queries
  ORDER BY updated_at DESC instead of version DESC.
- Tests: replace inverted BT02b with positive AZ357_AC1
  (prior-year cached tile is reused). Add BuildTileEntity_
  DoesNotPopulateVersion_AZ357 to enforce the no-write contract.
- 69 unit + 5 smoke + 3 stub-contract integration tests pass.

Cumulative code review (batches 7-9, 7 tasks): VERDICT=PASS.
Report at _docs/03_implementation/reviews/batch_09_review.md.
Zero Critical/High/Medium/Low findings. Architecture baseline
remains clean.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 00:20:47 +03:00

32 lines
1.2 KiB
SQL

-- AZ-357 / C06: drop year-based versioning from the tile uniqueness key.
-- The 'version' column itself is preserved (intentionally; column drops require
-- explicit confirmation per coderule.mdc). This migration:
-- 1. Drops the 5-column unique index that includes version.
-- 2. Dedupes pre-existing duplicates by the new 4-column key, keeping the row
-- with the highest updated_at (tie-break: highest id).
-- 3. Recreates the unique index without version.
-- 4. Makes the version column nullable and drops its default so new rows can
-- be inserted without writing a meaningless year value.
DROP INDEX IF EXISTS idx_tiles_unique_location;
DELETE FROM tiles
WHERE id IN (
SELECT id
FROM (
SELECT id,
ROW_NUMBER() OVER (
PARTITION BY latitude, longitude, tile_zoom, tile_size_meters
ORDER BY updated_at DESC, id DESC
) AS rn
FROM tiles
) ranked
WHERE rn > 1
);
CREATE UNIQUE INDEX idx_tiles_unique_location
ON tiles(latitude, longitude, tile_zoom, tile_size_meters);
ALTER TABLE tiles ALTER COLUMN version DROP NOT NULL;
ALTER TABLE tiles ALTER COLUMN version DROP DEFAULT;