From 1745758df9656174107daec674ce3eb72518e5aa Mon Sep 17 00:00:00 2001 From: philgei Date: Mon, 25 Nov 2024 13:25:46 +0100 Subject: [PATCH] Add Initial Migration --- .../Properties/launchSettings.json | 10 +- .../20241125115430_Initial.Designer.cs | 106 ++++++++++++++++++ .../Migrations/20241125115430_Initial.cs | 82 ++++++++++++++ .../DevelopmentContextModelSnapshot.cs | 103 +++++++++++++++++ .../Repositories/DevelopmentContext.cs | 2 +- .../Repositories/ProductionContext.cs | 1 - 6 files changed, 297 insertions(+), 7 deletions(-) create mode 100644 AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.Designer.cs create mode 100644 AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.cs create mode 100644 AdLerBackend.Infrastructure/Migrations/DevelopmentContextModelSnapshot.cs diff --git a/AdLerBackend.API/Properties/launchSettings.json b/AdLerBackend.API/Properties/launchSettings.json index 44ff1c39..32e950f1 100644 --- a/AdLerBackend.API/Properties/launchSettings.json +++ b/AdLerBackend.API/Properties/launchSettings.json @@ -23,11 +23,11 @@ "ASPNETCORE_ENVIRONMENT": "Production", "ASPNETCORE_ADLER_MOODLEURL": "http://localhost:8085", "ASPNETCORE_ADLER_HTTPPORT": 3000, - "ASPNETCORE_DBPASSWORD": "placeholder", - "ASPNETCORE_DBUSER": "placeholder", - "ASPNETCORE_DBNAME": "placeholder", - "ASPNETCORE_DBHOST": "placeholder", - "ASPNETCORE_DBPORT": "placeholder", + "ASPNETCORE_DBPASSWORD": "b", + "ASPNETCORE_DBUSER": "adler_backend", + "ASPNETCORE_DBNAME": "adler_backend", + "ASPNETCORE_DBHOST": "localhost", + "ASPNETCORE_DBPORT": "3306", "ASPNETCORE_ADLER_ADLERENGINEURL": "http://localhost:8087" } } diff --git a/AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.Designer.cs b/AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.Designer.cs new file mode 100644 index 00000000..a97291c5 --- /dev/null +++ b/AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.Designer.cs @@ -0,0 +1,106 @@ +// +using System; +using AdLerBackend.Infrastructure.Repositories; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AdLerBackend.Infrastructure.Migrations +{ + [DbContext(typeof(DevelopmentContext))] + [Migration("20241125115430_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.10"); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.H5PLocationEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasAnnotation("SqlServer:IdentityIncrement", 1) + .HasAnnotation("SqlServer:IdentitySeed", 1L) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ElementId") + .HasColumnType("INTEGER"); + + b.Property("Path") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("WorldEntityId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("WorldEntityId"); + + b.ToTable("H5PLocationEntity"); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.PlayerData.PlayerData", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("PlayerGender") + .HasColumnType("INTEGER"); + + b.Property("PlayerWorldColor") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("PlayerData"); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.WorldEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AtfJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("AuthorId") + .HasColumnType("INTEGER"); + + b.Property("LmsWorldId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.H5PLocationEntity", b => + { + b.HasOne("AdLerBackend.Domain.Entities.WorldEntity", null) + .WithMany("H5PFilesInCourse") + .HasForeignKey("WorldEntityId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.WorldEntity", b => + { + b.Navigation("H5PFilesInCourse"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.cs b/AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.cs new file mode 100644 index 00000000..6d2df980 --- /dev/null +++ b/AdLerBackend.Infrastructure/Migrations/20241125115430_Initial.cs @@ -0,0 +1,82 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AdLerBackend.Infrastructure.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "PlayerData", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + PlayerGender = table.Column(type: "INTEGER", nullable: false), + PlayerWorldColor = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlayerData", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Worlds", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + LmsWorldId = table.Column(type: "INTEGER", nullable: false), + AuthorId = table.Column(type: "INTEGER", nullable: false), + AtfJson = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Worlds", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "H5PLocationEntity", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Path = table.Column(type: "TEXT", nullable: false), + ElementId = table.Column(type: "INTEGER", nullable: true), + WorldEntityId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_H5PLocationEntity", x => x.Id); + table.ForeignKey( + name: "FK_H5PLocationEntity_Worlds_WorldEntityId", + column: x => x.WorldEntityId, + principalTable: "Worlds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_H5PLocationEntity_WorldEntityId", + table: "H5PLocationEntity", + column: "WorldEntityId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "H5PLocationEntity"); + + migrationBuilder.DropTable( + name: "PlayerData"); + + migrationBuilder.DropTable( + name: "Worlds"); + } + } +} diff --git a/AdLerBackend.Infrastructure/Migrations/DevelopmentContextModelSnapshot.cs b/AdLerBackend.Infrastructure/Migrations/DevelopmentContextModelSnapshot.cs new file mode 100644 index 00000000..a6bd9644 --- /dev/null +++ b/AdLerBackend.Infrastructure/Migrations/DevelopmentContextModelSnapshot.cs @@ -0,0 +1,103 @@ +// +using System; +using AdLerBackend.Infrastructure.Repositories; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AdLerBackend.Infrastructure.Migrations +{ + [DbContext(typeof(DevelopmentContext))] + partial class DevelopmentContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.10"); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.H5PLocationEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER") + .HasAnnotation("SqlServer:IdentityIncrement", 1) + .HasAnnotation("SqlServer:IdentitySeed", 1L) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ElementId") + .HasColumnType("INTEGER"); + + b.Property("Path") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("WorldEntityId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("WorldEntityId"); + + b.ToTable("H5PLocationEntity"); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.PlayerData.PlayerData", b => + { + b.Property("Id") + .HasColumnType("INTEGER"); + + b.Property("PlayerGender") + .HasColumnType("INTEGER"); + + b.Property("PlayerWorldColor") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("PlayerData"); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.WorldEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AtfJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("AuthorId") + .HasColumnType("INTEGER"); + + b.Property("LmsWorldId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Worlds"); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.H5PLocationEntity", b => + { + b.HasOne("AdLerBackend.Domain.Entities.WorldEntity", null) + .WithMany("H5PFilesInCourse") + .HasForeignKey("WorldEntityId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("AdLerBackend.Domain.Entities.WorldEntity", b => + { + b.Navigation("H5PFilesInCourse"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AdLerBackend.Infrastructure/Repositories/DevelopmentContext.cs b/AdLerBackend.Infrastructure/Repositories/DevelopmentContext.cs index 38c55d39..2bb55aa3 100644 --- a/AdLerBackend.Infrastructure/Repositories/DevelopmentContext.cs +++ b/AdLerBackend.Infrastructure/Repositories/DevelopmentContext.cs @@ -13,7 +13,7 @@ public sealed class DevelopmentContext : BaseAdLerBackendDbContext public DevelopmentContext(DbContextOptions options, IConfiguration configuration) : base(options) { _configuration = configuration; - Database.EnsureCreated(); + Database.Migrate(); } protected override void OnConfiguring(DbContextOptionsBuilder options) diff --git a/AdLerBackend.Infrastructure/Repositories/ProductionContext.cs b/AdLerBackend.Infrastructure/Repositories/ProductionContext.cs index 8407772d..2b880826 100644 --- a/AdLerBackend.Infrastructure/Repositories/ProductionContext.cs +++ b/AdLerBackend.Infrastructure/Repositories/ProductionContext.cs @@ -14,7 +14,6 @@ public sealed class ProductionContext : BaseAdLerBackendDbContext public ProductionContext(DbContextOptions options, IOptions confguration) : base(options) { _backendConfig = confguration.Value; - Database.EnsureCreated(); } protected override void OnConfiguring(DbContextOptionsBuilder options)