Add initial entity and migration for MissionLaunch
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
using MissionControl.Domain.Entities;
|
||||||
|
|
||||||
|
namespace MissionControl.Data.EntityConfigurations;
|
||||||
|
|
||||||
|
public class MissionLaunchConfiguration : IEntityTypeConfiguration<MissionLaunch>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<MissionLaunch> builder)
|
||||||
|
{
|
||||||
|
builder.Property(m => m.Status).HasConversion<string>().HasMaxLength(20);
|
||||||
|
}
|
||||||
|
}
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using MissionControl.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace MissionControl.Data.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(MissionControlContext))]
|
||||||
|
[Migration("20260727193151_Add_MissionLaunches")]
|
||||||
|
partial class Add_MissionLaunches
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.10")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.Mission", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreatedAt")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasMaxLength(500)
|
||||||
|
.HasColumnType("nvarchar(500)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.HasColumnType("nvarchar(100)");
|
||||||
|
|
||||||
|
b.Property<string>("Status")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("nvarchar(20)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Missions");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.MissionLaunch", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreatedAt")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<Guid>("MissionId")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ScheduledFor")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("Status")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("nvarchar(20)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MissionId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MissionLaunches");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.MissionLaunch", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("MissionControl.Domain.Entities.Mission", "Mission")
|
||||||
|
.WithOne("MissionLaunch")
|
||||||
|
.HasForeignKey("MissionControl.Domain.Entities.MissionLaunch", "MissionId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Mission");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.Mission", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("MissionLaunch");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace MissionControl.Data.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Add_MissionLaunches : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "MissionLaunches",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
|
||||||
|
ScheduledFor = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
|
||||||
|
Status = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
|
||||||
|
CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
|
||||||
|
MissionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_MissionLaunches", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_MissionLaunches_Missions_MissionId",
|
||||||
|
column: x => x.MissionId,
|
||||||
|
principalTable: "Missions",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_MissionLaunches_MissionId",
|
||||||
|
table: "MissionLaunches",
|
||||||
|
column: "MissionId",
|
||||||
|
unique: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "MissionLaunches");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,6 +49,50 @@ namespace MissionControl.Data.Migrations
|
|||||||
|
|
||||||
b.ToTable("Missions");
|
b.ToTable("Missions");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.MissionLaunch", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("CreatedAt")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<Guid>("MissionId")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset>("ScheduledFor")
|
||||||
|
.HasColumnType("datetimeoffset");
|
||||||
|
|
||||||
|
b.Property<string>("Status")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(20)
|
||||||
|
.HasColumnType("nvarchar(20)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MissionId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MissionLaunches");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.MissionLaunch", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("MissionControl.Domain.Entities.Mission", "Mission")
|
||||||
|
.WithOne("MissionLaunch")
|
||||||
|
.HasForeignKey("MissionControl.Domain.Entities.MissionLaunch", "MissionId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Mission");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("MissionControl.Domain.Entities.Mission", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("MissionLaunch");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,15 @@ public class MissionControlContext(DbContextOptions<MissionControlContext> optio
|
|||||||
: DbContext(options)
|
: DbContext(options)
|
||||||
{
|
{
|
||||||
public DbSet<Mission> Missions => Set<Mission>();
|
public DbSet<Mission> Missions => Set<Mission>();
|
||||||
|
public DbSet<MissionLaunch> MissionLaunches => Set<MissionLaunch>();
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<Mission>()
|
||||||
|
.HasOne(mission => mission.MissionLaunch)
|
||||||
|
.WithOne(missionLaunch => missionLaunch.Mission)
|
||||||
|
.HasForeignKey<MissionLaunch>(missionLaunch => missionLaunch.MissionId);
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
|
|
||||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(MissionControlContext).Assembly);
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(MissionControlContext).Assembly);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ public class Mission
|
|||||||
public MissionStatus Status { get; set; } = MissionStatus.Planned;
|
public MissionStatus Status { get; set; } = MissionStatus.Planned;
|
||||||
|
|
||||||
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.UtcNow;
|
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
|
public MissionLaunch? MissionLaunch { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace MissionControl.Domain.Entities;
|
||||||
|
|
||||||
|
public class MissionLaunch
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
public DateTimeOffset ScheduledFor { get; set; }
|
||||||
|
|
||||||
|
public MissionLaunchStatus Status { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
|
public Guid MissionId { get; set; }
|
||||||
|
|
||||||
|
public Mission Mission { get; set; } = null!;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace MissionControl.Domain.Entities;
|
||||||
|
|
||||||
|
public enum MissionLaunchStatus
|
||||||
|
{
|
||||||
|
Pending,
|
||||||
|
Delayed,
|
||||||
|
Launching,
|
||||||
|
Launched,
|
||||||
|
Cancelled,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user