From 64f4a3a58ca9c7556f4dcc8ec80e412c42976872 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Tue, 25 Feb 2025 17:12:31 +0100 Subject: [PATCH] Started migrating to postgresql --- .../Database/CoreDataContext.cs | 3 +- ...1001090841_AddedBasicUserModel.Designer.cs | 63 ----------- .../20241001090841_AddedBasicUserModel.cs | 53 --------- ...dedAccessAndRefreshTokenFields.Designer.cs | 74 ------------- ...214600_AddedAccessAndRefreshTokenFields.cs | 58 ---------- .../20241029134013_AddedApiKeys.Designer.cs | 102 ------------------ .../Migrations/20241029134013_AddedApiKeys.cs | 45 -------- ...RemovedUnusedFieldsInUserModel.Designer.cs | 91 ---------------- ...05073340_RemovedUnusedFieldsInUserModel.cs | 58 ---------- .../CoreDataContextModelSnapshot.cs | 88 --------------- .../Helpers/DatabaseContext.cs | 49 --------- .../Helpers/DatabaseContextCollection.cs | 17 --- .../Moonlight.ApiServer.csproj | 1 - Moonlight.ApiServer/Startup.cs | 2 + 14 files changed, 4 insertions(+), 700 deletions(-) delete mode 100644 Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.Designer.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.Designer.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.Designer.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.Designer.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.cs delete mode 100644 Moonlight.ApiServer/Database/Migrations/CoreDataContextModelSnapshot.cs delete mode 100644 Moonlight.ApiServer/Helpers/DatabaseContext.cs delete mode 100644 Moonlight.ApiServer/Helpers/DatabaseContextCollection.cs diff --git a/Moonlight.ApiServer/Database/CoreDataContext.cs b/Moonlight.ApiServer/Database/CoreDataContext.cs index 5c586842..ab02fc0b 100644 --- a/Moonlight.ApiServer/Database/CoreDataContext.cs +++ b/Moonlight.ApiServer/Database/CoreDataContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using MoonCore.Extended.SingleDb; using Moonlight.ApiServer.Configuration; using Moonlight.ApiServer.Database.Entities; using Moonlight.ApiServer.Helpers; @@ -12,7 +13,7 @@ public class CoreDataContext : DatabaseContext public DbSet Users { get; set; } public DbSet ApiKeys { get; set; } - public CoreDataContext(AppConfiguration configuration) : base(configuration) + public CoreDataContext(DatabaseOptions options) : base(options) { } } \ No newline at end of file diff --git a/Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.Designer.cs b/Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.Designer.cs deleted file mode 100644 index 958c8d42..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Moonlight.ApiServer.Database; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - [DbContext(typeof(CoreDataContext))] - [Migration("20241001090841_AddedBasicUserModel")] - partial class AddedBasicUserModel - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasDefaultSchema("Core") - .HasAnnotation("ProductVersion", "8.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Password") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TokenValidTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users", "Core"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.cs b/Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.cs deleted file mode 100644 index 1c7b6edb..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20241001090841_AddedBasicUserModel.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - /// - public partial class AddedBasicUserModel : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "Core"); - - migrationBuilder.AlterDatabase() - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "Users", - schema: "Core", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - Username = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Email = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Password = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - TokenValidTimestamp = table.Column(type: "datetime(6)", nullable: false), - PermissionsJson = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Users", - schema: "Core"); - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.Designer.cs b/Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.Designer.cs deleted file mode 100644 index c81eb31c..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.Designer.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Moonlight.ApiServer.Database; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - [DbContext(typeof(CoreDataContext))] - [Migration("20241017214600_AddedAccessAndRefreshTokenFields")] - partial class AddedAccessAndRefreshTokenFields - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasDefaultSchema("Core") - .HasAnnotation("ProductVersion", "8.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("AccessToken") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Email") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Password") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("RefreshTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("RefreshToken") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TokenValidTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users", "Core"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.cs b/Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.cs deleted file mode 100644 index d815cc14..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20241017214600_AddedAccessAndRefreshTokenFields.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - /// - public partial class AddedAccessAndRefreshTokenFields : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "AccessToken", - schema: "Core", - table: "Users", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "RefreshTimestamp", - schema: "Core", - table: "Users", - type: "datetime(6)", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); - - migrationBuilder.AddColumn( - name: "RefreshToken", - schema: "Core", - table: "Users", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "AccessToken", - schema: "Core", - table: "Users"); - - migrationBuilder.DropColumn( - name: "RefreshTimestamp", - schema: "Core", - table: "Users"); - - migrationBuilder.DropColumn( - name: "RefreshToken", - schema: "Core", - table: "Users"); - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.Designer.cs b/Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.Designer.cs deleted file mode 100644 index 7895b1f1..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.Designer.cs +++ /dev/null @@ -1,102 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Moonlight.ApiServer.Database; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - [DbContext(typeof(CoreDataContext))] - [Migration("20241029134013_AddedApiKeys")] - partial class AddedApiKeys - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasDefaultSchema("Core") - .HasAnnotation("ProductVersion", "8.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ExpiresAt") - .HasColumnType("datetime(6)"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Secret") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("ApiKeys", "Core"); - }); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("AccessToken") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Email") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Password") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("RefreshTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("RefreshToken") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TokenValidTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users", "Core"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.cs b/Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.cs deleted file mode 100644 index bbc69b7c..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20241029134013_AddedApiKeys.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - /// - public partial class AddedApiKeys : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "ApiKeys", - schema: "Core", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - Secret = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Description = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - PermissionsJson = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ExpiresAt = table.Column(type: "datetime(6)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_ApiKeys", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ApiKeys", - schema: "Core"); - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.Designer.cs b/Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.Designer.cs deleted file mode 100644 index 64246be9..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.Designer.cs +++ /dev/null @@ -1,91 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Moonlight.ApiServer.Database; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - [DbContext(typeof(CoreDataContext))] - [Migration("20250205073340_RemovedUnusedFieldsInUserModel")] - partial class RemovedUnusedFieldsInUserModel - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasDefaultSchema("Core") - .HasAnnotation("ProductVersion", "8.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ExpiresAt") - .HasColumnType("datetime(6)"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Secret") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("ApiKeys", "Core"); - }); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Password") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TokenValidTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users", "Core"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.cs b/Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.cs deleted file mode 100644 index 03e69cff..00000000 --- a/Moonlight.ApiServer/Database/Migrations/20250205073340_RemovedUnusedFieldsInUserModel.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - /// - public partial class RemovedUnusedFieldsInUserModel : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "AccessToken", - schema: "Core", - table: "Users"); - - migrationBuilder.DropColumn( - name: "RefreshTimestamp", - schema: "Core", - table: "Users"); - - migrationBuilder.DropColumn( - name: "RefreshToken", - schema: "Core", - table: "Users"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "AccessToken", - schema: "Core", - table: "Users", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.AddColumn( - name: "RefreshTimestamp", - schema: "Core", - table: "Users", - type: "datetime(6)", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); - - migrationBuilder.AddColumn( - name: "RefreshToken", - schema: "Core", - table: "Users", - type: "longtext", - nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"); - } - } -} diff --git a/Moonlight.ApiServer/Database/Migrations/CoreDataContextModelSnapshot.cs b/Moonlight.ApiServer/Database/Migrations/CoreDataContextModelSnapshot.cs deleted file mode 100644 index 84d645e9..00000000 --- a/Moonlight.ApiServer/Database/Migrations/CoreDataContextModelSnapshot.cs +++ /dev/null @@ -1,88 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Moonlight.ApiServer.Database; - -#nullable disable - -namespace Moonlight.ApiServer.Database.Migrations -{ - [DbContext(typeof(CoreDataContext))] - partial class CoreDataContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasDefaultSchema("Core") - .HasAnnotation("ProductVersion", "8.0.8") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - MySqlModelBuilderExtensions.AutoIncrementColumns(modelBuilder); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.ApiKey", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("ExpiresAt") - .HasColumnType("datetime(6)"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Secret") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("ApiKeys", "Core"); - }); - - modelBuilder.Entity("Moonlight.ApiServer.Database.Entities.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - MySqlPropertyBuilderExtensions.UseMySqlIdentityColumn(b.Property("Id")); - - b.Property("Email") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Password") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PermissionsJson") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("TokenValidTimestamp") - .HasColumnType("datetime(6)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("Id"); - - b.ToTable("Users", "Core"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Moonlight.ApiServer/Helpers/DatabaseContext.cs b/Moonlight.ApiServer/Helpers/DatabaseContext.cs deleted file mode 100644 index 5cb85555..00000000 --- a/Moonlight.ApiServer/Helpers/DatabaseContext.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Moonlight.ApiServer.Configuration; -using Pomelo.EntityFrameworkCore.MySql.Infrastructure; - -namespace Moonlight.ApiServer.Helpers; - -public abstract class DatabaseContext : DbContext -{ - public abstract string Prefix { get; } - - private readonly AppConfiguration Configuration; - - public DatabaseContext(AppConfiguration configuration) - { - Configuration = configuration; - } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - if (optionsBuilder.IsConfigured) - return; - - var config = Configuration.Database; - - var connectionString = $"host={config.Host};" + - $"port={config.Port};" + - $"database={config.Database};" + - $"uid={config.Username};" + - $"pwd={config.Password}"; - - optionsBuilder.UseMySql( - connectionString, - ServerVersion.AutoDetect(connectionString), - builder => - { - builder.EnableRetryOnFailure(5); - builder.SchemaBehavior(MySqlSchemaBehavior.Translate, (name, objectName) => $"{name}_{objectName}"); - builder.MigrationsHistoryTable($"{Prefix}_MigrationHistory"); - } - ); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Model.SetDefaultSchema(Prefix); - - base.OnModelCreating(modelBuilder); - } -} \ No newline at end of file diff --git a/Moonlight.ApiServer/Helpers/DatabaseContextCollection.cs b/Moonlight.ApiServer/Helpers/DatabaseContextCollection.cs deleted file mode 100644 index 781dc97b..00000000 --- a/Moonlight.ApiServer/Helpers/DatabaseContextCollection.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections; - -namespace Moonlight.ApiServer.Helpers; - -public class DatabaseContextCollection : IEnumerable -{ - private readonly List Types = new(); - - public IEnumerator GetEnumerator() => Types.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => Types.GetEnumerator(); - - public void Add() where T : DatabaseContext - => Types.Add(typeof(T)); - - public void Remove(Type type) => Types.Remove(type); - public void Remove() where T : DatabaseContext => Remove(typeof(T)); -} \ No newline at end of file diff --git a/Moonlight.ApiServer/Moonlight.ApiServer.csproj b/Moonlight.ApiServer/Moonlight.ApiServer.csproj index 2362b1f3..b88d59e9 100644 --- a/Moonlight.ApiServer/Moonlight.ApiServer.csproj +++ b/Moonlight.ApiServer/Moonlight.ApiServer.csproj @@ -27,7 +27,6 @@ - diff --git a/Moonlight.ApiServer/Startup.cs b/Moonlight.ApiServer/Startup.cs index 2788fbba..143ac4e5 100644 --- a/Moonlight.ApiServer/Startup.cs +++ b/Moonlight.ApiServer/Startup.cs @@ -9,12 +9,14 @@ using MoonCore.Extended.Abstractions; using MoonCore.Extended.Extensions; using MoonCore.Extended.Helpers; using MoonCore.Extended.JwtInvalidation; +using MoonCore.Extended.SingleDb; using MoonCore.Extensions; using MoonCore.Helpers; using MoonCore.PluginFramework.Extensions; using MoonCore.Plugins; using MoonCore.Services; using Moonlight.ApiServer.Configuration; +using Moonlight.ApiServer.Database; using Moonlight.ApiServer.Database.Entities; using Moonlight.ApiServer.Helpers; using Moonlight.ApiServer.Interfaces.Auth;