refactor: rename project from Flights to Missions and update related components
ci/woodpecker/push/build-arm Pipeline was successful

This commit transitions the project from Azaion.Flights to Azaion.Missions, updating namespaces, DTOs, services, and database entities accordingly. The Docker configuration and entry points have been modified to reflect the new project structure. Additionally, the README and documentation have been updated to clarify the ongoing renaming process and its implications. All references to flights have been replaced with missions, ensuring consistency across the codebase.
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-15 04:35:49 +03:00
parent 4f226e91d5
commit 2840ccb9b6
51 changed files with 381 additions and 352 deletions
+65 -34
View File
@@ -1,16 +1,64 @@
using LinqToDB.Data;
namespace Azaion.Flights.Database;
namespace Azaion.Missions.Database;
// Forward-only migrator. Two SQL blocks run on every container start, in order:
//
// 1. RenameAndDropSql -- idempotent ALTERs that bring a legacy `flights`-era
// schema up to the renamed `missions` schema, plus DROPs for the
// GPS-Denied tables (Jira AZ-EPIC B7 / B9). On a fresh DB or an
// already-migrated DB this block is a no-op (every statement guards on
// IF EXISTS / column existence).
//
// 2. InitSql -- CREATE TABLE IF NOT EXISTS for the post-migration schema.
// On a legacy DB the renames in (1) leave tables already present; this
// block is a no-op for them. On a fresh-install device this block IS
// the schema. On an already-migrated DB it is a no-op.
//
// Re-running the migrator on any DB state above produces no errors and no
// changes -- this is the suite's "idempotent forward-only" convention.
public static class DatabaseMigrator
{
public static void Migrate(AppDataConnection db)
{
db.Execute(Sql);
db.Execute(RenameAndDropSql);
db.Execute(InitSql);
}
private const string Sql = """
CREATE TABLE IF NOT EXISTS aircrafts (
// Bring legacy `flights` / `aircrafts` schemas up to the renamed shape.
// Safe to re-run on any DB state.
private const string RenameAndDropSql = """
ALTER TABLE IF EXISTS aircrafts RENAME TO vehicles;
ALTER TABLE IF EXISTS flights RENAME TO missions;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.columns
WHERE table_name = 'missions' AND column_name = 'aircraft_id') THEN
ALTER TABLE missions RENAME COLUMN aircraft_id TO vehicle_id;
END IF;
IF EXISTS (SELECT 1 FROM information_schema.columns
WHERE table_name = 'waypoints' AND column_name = 'flight_id') THEN
ALTER TABLE waypoints RENAME COLUMN flight_id TO mission_id;
END IF;
IF EXISTS (SELECT 1 FROM information_schema.columns
WHERE table_name = 'map_objects' AND column_name = 'flight_id') THEN
ALTER TABLE map_objects RENAME COLUMN flight_id TO mission_id;
END IF;
END $$;
ALTER INDEX IF EXISTS ix_flights_aircraft_id RENAME TO ix_missions_vehicle_id;
ALTER INDEX IF EXISTS ix_waypoints_flight_id RENAME TO ix_waypoints_mission_id;
ALTER INDEX IF EXISTS ix_map_objects_flight_id RENAME TO ix_map_objects_mission_id;
DROP TABLE IF EXISTS orthophotos;
DROP TABLE IF EXISTS gps_corrections;
""";
// Post-migration schema. CREATE TABLE IF NOT EXISTS is the idempotent path
// for fresh DBs; on already-migrated DBs every statement here is a no-op.
private const string InitSql = """
CREATE TABLE IF NOT EXISTS vehicles (
id UUID PRIMARY KEY,
type INTEGER NOT NULL DEFAULT 0,
model TEXT NOT NULL,
@@ -22,16 +70,16 @@ public static class DatabaseMigrator
is_default BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS flights (
CREATE TABLE IF NOT EXISTS missions (
id UUID PRIMARY KEY,
created_date TIMESTAMP NOT NULL DEFAULT NOW(),
name TEXT NOT NULL,
aircraft_id UUID NOT NULL REFERENCES aircrafts(id)
vehicle_id UUID NOT NULL REFERENCES vehicles(id)
);
CREATE TABLE IF NOT EXISTS waypoints (
id UUID PRIMARY KEY,
flight_id UUID NOT NULL REFERENCES flights(id),
mission_id UUID NOT NULL REFERENCES missions(id),
lat NUMERIC,
lon NUMERIC,
mgrs TEXT,
@@ -41,29 +89,9 @@ public static class DatabaseMigrator
height NUMERIC NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS orthophotos (
id TEXT PRIMARY KEY,
flight_id UUID NOT NULL REFERENCES flights(id),
name TEXT NOT NULL,
path TEXT NOT NULL,
lat NUMERIC,
lon NUMERIC,
mgrs TEXT,
uploaded_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS gps_corrections (
id UUID PRIMARY KEY,
flight_id UUID NOT NULL REFERENCES flights(id),
waypoint_id UUID NOT NULL REFERENCES waypoints(id),
original_gps TEXT NOT NULL,
corrected_gps TEXT NOT NULL,
applied_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS map_objects (
id UUID PRIMARY KEY,
flight_id UUID NOT NULL REFERENCES flights(id),
mission_id UUID NOT NULL REFERENCES missions(id),
h3_index TEXT NOT NULL,
mgrs TEXT NOT NULL,
lat NUMERIC,
@@ -78,11 +106,14 @@ public static class DatabaseMigrator
last_seen_at TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS ix_flights_aircraft_id ON flights(aircraft_id);
CREATE INDEX IF NOT EXISTS ix_waypoints_flight_id ON waypoints(flight_id);
CREATE INDEX IF NOT EXISTS ix_orthophotos_flight_id ON orthophotos(flight_id);
CREATE INDEX IF NOT EXISTS ix_gps_corrections_flight_id ON gps_corrections(flight_id);
CREATE INDEX IF NOT EXISTS ix_gps_corrections_waypoint_id ON gps_corrections(waypoint_id);
CREATE INDEX IF NOT EXISTS ix_map_objects_flight_id ON map_objects(flight_id);
CREATE INDEX IF NOT EXISTS ix_missions_vehicle_id ON missions(vehicle_id);
CREATE INDEX IF NOT EXISTS ix_waypoints_mission_id ON waypoints(mission_id);
CREATE INDEX IF NOT EXISTS ix_map_objects_mission_id ON map_objects(mission_id);
-- B12 (Option A): exactly-one-default vehicle is enforced by a partial
-- unique index. Only rows with is_default = true are indexed; two such
-- rows would conflict. Existing 0-default and 1-default DBs are valid.
CREATE UNIQUE INDEX IF NOT EXISTS ux_vehicles_one_default
ON vehicles (is_default) WHERE is_default = TRUE;
""";
}