using Npgsql; namespace Azaion.Missions.E2E.Fixtures; /// /// Creates the borrowed-schema stub tables (media, annotations, detection) /// required by the cascade-delete fixtures. The migrator (DatabaseMigrator) /// only owns the missions/vehicles/waypoints/map_objects tables; media, /// annotations, and detection are owned by sibling services in production /// (out of scope for this repo per /// _docs/02_document/tests/environment.md). The cascade walk in /// MissionService.DeleteMission still references them, so tests must /// supply their schema via side-channel. /// /// /// Idempotent — every statement is CREATE … IF NOT EXISTS. /// Column shapes match the LinqToDB entities (Database/Entities/Media.cs, /// Database/Entities/Annotation.cs, Database/Entities/Detection.cs). /// public static class StubSchema { public static void EnsureCreated() { using var conn = new NpgsqlConnection(TestEnvironment.DbSideChannel); conn.Open(); using var cmd = conn.CreateCommand(); cmd.CommandText = """ CREATE TABLE IF NOT EXISTS media ( id TEXT PRIMARY KEY, waypoint_id UUID ); CREATE TABLE IF NOT EXISTS annotations ( id TEXT PRIMARY KEY, media_id TEXT NOT NULL ); CREATE TABLE IF NOT EXISTS detection ( id UUID PRIMARY KEY, annotation_id TEXT NOT NULL ); """; cmd.ExecuteNonQuery(); } }