Initial commit

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-25 05:21:08 +02:00
commit 0625cd4157
90 changed files with 3430 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
using LinqToDB;
using LinqToDB.Data;
using Azaion.Flights.Database.Entities;
namespace Azaion.Flights.Database;
public class AppDataConnection(DataOptions options) : DataConnection(options)
{
public ITable<Aircraft> Aircrafts => this.GetTable<Aircraft>();
public ITable<Flight> Flights => this.GetTable<Flight>();
public ITable<Waypoint> Waypoints => this.GetTable<Waypoint>();
public ITable<Orthophoto> Orthophotos => this.GetTable<Orthophoto>();
public ITable<GpsCorrection> GpsCorrections => this.GetTable<GpsCorrection>();
public ITable<MapObject> MapObjects => this.GetTable<MapObject>();
public ITable<Media> Media => this.GetTable<Media>();
public ITable<Annotation> Annotations => this.GetTable<Annotation>();
public ITable<Detection> Detections => this.GetTable<Detection>();
}
+88
View File
@@ -0,0 +1,88 @@
using LinqToDB.Data;
namespace Azaion.Flights.Database;
public static class DatabaseMigrator
{
public static void Migrate(AppDataConnection db)
{
db.Execute(Sql);
}
private const string Sql = """
CREATE TABLE IF NOT EXISTS aircrafts (
id UUID PRIMARY KEY,
type INTEGER NOT NULL DEFAULT 0,
model TEXT NOT NULL,
name TEXT NOT NULL,
fuel_type INTEGER NOT NULL DEFAULT 0,
battery_capacity NUMERIC NOT NULL DEFAULT 0,
engine_consumption NUMERIC NOT NULL DEFAULT 0,
engine_consumption_idle NUMERIC NOT NULL DEFAULT 0,
is_default BOOLEAN NOT NULL DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS flights (
id UUID PRIMARY KEY,
created_date TIMESTAMP NOT NULL DEFAULT NOW(),
name TEXT NOT NULL,
aircraft_id UUID NOT NULL REFERENCES aircrafts(id)
);
CREATE TABLE IF NOT EXISTS waypoints (
id UUID PRIMARY KEY,
flight_id UUID NOT NULL REFERENCES flights(id),
lat NUMERIC,
lon NUMERIC,
mgrs TEXT,
waypoint_source INTEGER NOT NULL DEFAULT 0,
waypoint_objective INTEGER NOT NULL DEFAULT 0,
order_num INTEGER NOT NULL DEFAULT 0,
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),
h3_index TEXT NOT NULL,
mgrs TEXT NOT NULL,
lat NUMERIC,
lon NUMERIC,
class_num INTEGER NOT NULL DEFAULT 0,
label TEXT NOT NULL DEFAULT '',
size_width_m NUMERIC NOT NULL DEFAULT 0,
size_length_m NUMERIC NOT NULL DEFAULT 0,
confidence NUMERIC NOT NULL DEFAULT 0,
object_status INTEGER NOT NULL DEFAULT 0,
first_seen_at TIMESTAMP NOT NULL DEFAULT NOW(),
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);
""";
}
+36
View File
@@ -0,0 +1,36 @@
using LinqToDB.Mapping;
using Azaion.Flights.Enums;
namespace Azaion.Flights.Database.Entities;
[Table("aircrafts")]
public class Aircraft
{
[PrimaryKey]
[Column("id")]
public Guid Id { get; set; }
[Column("type")]
public AircraftType Type { get; set; }
[Column("model")]
public string Model { get; set; } = string.Empty;
[Column("name")]
public string Name { get; set; } = string.Empty;
[Column("fuel_type")]
public FuelType FuelType { get; set; }
[Column("battery_capacity")]
public decimal BatteryCapacity { get; set; }
[Column("engine_consumption")]
public decimal EngineConsumption { get; set; }
[Column("engine_consumption_idle")]
public decimal EngineConsumptionIdle { get; set; }
[Column("is_default")]
public bool IsDefault { get; set; }
}
+14
View File
@@ -0,0 +1,14 @@
using LinqToDB.Mapping;
namespace Azaion.Flights.Database.Entities;
[Table("annotations")]
public class Annotation
{
[PrimaryKey]
[Column("id")]
public string Id { get; set; } = string.Empty;
[Column("media_id")]
public string MediaId { get; set; } = string.Empty;
}
+14
View File
@@ -0,0 +1,14 @@
using LinqToDB.Mapping;
namespace Azaion.Flights.Database.Entities;
[Table("detection")]
public class Detection
{
[PrimaryKey]
[Column("id")]
public Guid Id { get; set; }
[Column("annotation_id")]
public string AnnotationId { get; set; } = string.Empty;
}
+27
View File
@@ -0,0 +1,27 @@
using LinqToDB.Mapping;
using Azaion.Flights.Enums;
namespace Azaion.Flights.Database.Entities;
[Table("flights")]
public class Flight
{
[PrimaryKey]
[Column("id")]
public Guid Id { get; set; }
[Column("created_date")]
public DateTime CreatedDate { get; set; }
[Column("name")]
public string Name { get; set; } = string.Empty;
[Column("aircraft_id")]
public Guid AircraftId { get; set; }
[Association(ThisKey = nameof(AircraftId), OtherKey = nameof(Aircraft.Id))]
public Aircraft? Aircraft { get; set; }
[Association(ThisKey = nameof(Id), OtherKey = nameof(Waypoint.FlightId))]
public List<Waypoint> Waypoints { get; set; } = [];
}
+26
View File
@@ -0,0 +1,26 @@
using LinqToDB.Mapping;
namespace Azaion.Flights.Database.Entities;
[Table("gps_corrections")]
public class GpsCorrection
{
[PrimaryKey]
[Column("id")]
public Guid Id { get; set; }
[Column("flight_id")]
public Guid FlightId { get; set; }
[Column("waypoint_id")]
public Guid WaypointId { get; set; }
[Column("original_gps")]
public string OriginalGps { get; set; } = string.Empty;
[Column("corrected_gps")]
public string CorrectedGps { get; set; } = string.Empty;
[Column("applied_at")]
public DateTime AppliedAt { get; set; }
}
+51
View File
@@ -0,0 +1,51 @@
using LinqToDB.Mapping;
using Azaion.Flights.Enums;
namespace Azaion.Flights.Database.Entities;
[Table("map_objects")]
public class MapObject
{
[PrimaryKey]
[Column("id")]
public Guid Id { get; set; }
[Column("flight_id")]
public Guid FlightId { get; set; }
[Column("h3_index")]
public string H3Index { get; set; } = string.Empty;
[Column("mgrs")]
public string Mgrs { get; set; } = string.Empty;
[Column("lat")]
public decimal? Lat { get; set; }
[Column("lon")]
public decimal? Lon { get; set; }
[Column("class_num")]
public int ClassNum { get; set; }
[Column("label")]
public string Label { get; set; } = string.Empty;
[Column("size_width_m")]
public decimal SizeWidthM { get; set; }
[Column("size_length_m")]
public decimal SizeLengthM { get; set; }
[Column("confidence")]
public decimal Confidence { get; set; }
[Column("object_status")]
public ObjectStatus ObjectStatus { get; set; }
[Column("first_seen_at")]
public DateTime FirstSeenAt { get; set; }
[Column("last_seen_at")]
public DateTime LastSeenAt { get; set; }
}
+14
View File
@@ -0,0 +1,14 @@
using LinqToDB.Mapping;
namespace Azaion.Flights.Database.Entities;
[Table("media")]
public class Media
{
[PrimaryKey]
[Column("id")]
public string Id { get; set; } = string.Empty;
[Column("waypoint_id")]
public Guid? WaypointId { get; set; }
}
+32
View File
@@ -0,0 +1,32 @@
using LinqToDB.Mapping;
namespace Azaion.Flights.Database.Entities;
[Table("orthophotos")]
public class Orthophoto
{
[PrimaryKey]
[Column("id")]
public string Id { get; set; } = string.Empty;
[Column("flight_id")]
public Guid FlightId { get; set; }
[Column("name")]
public string Name { get; set; } = string.Empty;
[Column("path")]
public string Path { get; set; } = string.Empty;
[Column("lat")]
public decimal? Lat { get; set; }
[Column("lon")]
public decimal? Lon { get; set; }
[Column("mgrs")]
public string? Mgrs { get; set; }
[Column("uploaded_at")]
public DateTime UploadedAt { get; set; }
}
+39
View File
@@ -0,0 +1,39 @@
using LinqToDB.Mapping;
using Azaion.Flights.Enums;
namespace Azaion.Flights.Database.Entities;
[Table("waypoints")]
public class Waypoint
{
[PrimaryKey]
[Column("id")]
public Guid Id { get; set; }
[Column("flight_id")]
public Guid FlightId { get; set; }
[Column("lat")]
public decimal? Lat { get; set; }
[Column("lon")]
public decimal? Lon { get; set; }
[Column("mgrs")]
public string? Mgrs { get; set; }
[Column("waypoint_source")]
public WaypointSource WaypointSource { get; set; }
[Column("waypoint_objective")]
public WaypointObjective WaypointObjective { get; set; }
[Column("order_num")]
public int OrderNum { get; set; }
[Column("height")]
public decimal Height { get; set; }
[Association(ThisKey = nameof(FlightId), OtherKey = nameof(Flight.Id))]
public Flight? Flight { get; set; }
}