From e8d5c9801aae71d90b85eabc23b01ed360da76e3 Mon Sep 17 00:00:00 2001 From: Louis DEVIE Date: Thu, 4 Jul 2024 00:35:02 +0200 Subject: [PATCH] migrations setup --- ".github/workflows/V\303\251rifications.yml" | 6 +- .gitignore | 1 + .../.idea/codeStyles/Project.xml | 7 + .../.idea/codeStyles/codeStyleConfig.xml | 5 + .idea/.idea.Gallium+ API/.idea/encodings.xml | 6 + Gallium+ API.sln.DotSettings | 4 + MariaDb/{ => Implementations}/CategoryDao.cs | 2 +- MariaDb/{ => Implementations}/ClientDao.cs | 6 +- MariaDb/{ => Implementations}/HistoryDao.cs | 12 +- MariaDb/{ => Implementations}/ProductDao.cs | 2 +- MariaDb/{ => Implementations}/RoleDao.cs | 2 +- MariaDb/{ => Implementations}/SessionDao.cs | 5 +- MariaDb/{ => Implementations}/UserDao.cs | 7 +- MariaDb/MariaDb.csproj | 3 + MariaDb/MariaDbOptions.cs | 3 + ...eateForeignKey_BotClient_extends_Client.cs | 22 +++ ...eignKey_HistoryAction_HistoryUser_actor.cs | 22 +++ ...ignKey_HistoryAction_HistoryUser_target.cs | 22 +++ ...reignKey_PasswordResetToken_User_userId.cs | 23 +++ ...ateForeignKey_Product_Category_category.cs | 22 +++ .../CreateForeignKey_Session_Client_client.cs | 22 +++ .../CreateForeignKey_Session_User_user.cs | 22 +++ ...eateForeignKey_SsoClient_extends_Client.cs | 22 +++ .../CreateForeignKey_User_Role_role.cs | 22 +++ .../v1_00_00/CreateTable_BotClient.cs | 22 +++ .../v1_00_00/CreateTable_Category.cs | 21 +++ .../Migrations/v1_00_00/CreateTable_Client.cs | 25 +++ .../v1_00_00/CreateTable_HistoryAction.cs | 26 ++++ .../v1_00_00/CreateTable_HistoryUser.cs | 21 +++ .../CreateTable_PasswordResetToken.cs | 25 +++ .../v1_00_00/CreateTable_Product.cs | 26 ++++ .../Migrations/v1_00_00/CreateTable_Role.cs | 22 +++ .../v1_00_00/CreateTable_Session.cs | 25 +++ .../v1_00_00/CreateTable_SsoClient.cs | 24 +++ .../Migrations/v1_00_00/CreateTable_User.cs | 31 ++++ .../CreateConstraint_HistoryAction_kind.cs | 19 +++ .../CreateConstraint_Product_availability.cs | 19 +++ MariaDb/MigrationsRunner.cs | 13 ++ SQL/galliumplus-ddl.sql | 142 ------------------ SQL/galliumplus-enums.sql | 14 -- Service/Program.cs | 70 +++++---- Service/appsettings.Development.json | 25 --- 42 files changed, 609 insertions(+), 231 deletions(-) create mode 100644 .idea/.idea.Gallium+ API/.idea/codeStyles/Project.xml create mode 100644 .idea/.idea.Gallium+ API/.idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/.idea.Gallium+ API/.idea/encodings.xml create mode 100644 Gallium+ API.sln.DotSettings rename MariaDb/{ => Implementations}/CategoryDao.cs (97%) rename MariaDb/{ => Implementations}/ClientDao.cs (98%) rename MariaDb/{ => Implementations}/HistoryDao.cs (93%) rename MariaDb/{ => Implementations}/ProductDao.cs (99%) rename MariaDb/{ => Implementations}/RoleDao.cs (97%) rename MariaDb/{ => Implementations}/SessionDao.cs (96%) rename MariaDb/{ => Implementations}/UserDao.cs (98%) create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_BotClient_extends_Client.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_actor.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_target.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_PasswordResetToken_User_userId.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_Product_Category_category.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_Client_client.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_User_user.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_SsoClient_extends_Client.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateForeignKey_User_Role_role.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_BotClient.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_Category.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_Client.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_HistoryAction.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_HistoryUser.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_PasswordResetToken.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_Product.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_Role.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_Session.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_SsoClient.cs create mode 100644 MariaDb/Migrations/v1_00_00/CreateTable_User.cs create mode 100644 MariaDb/Migrations/v1_00_04/CreateConstraint_HistoryAction_kind.cs create mode 100644 MariaDb/Migrations/v1_00_04/CreateConstraint_Product_availability.cs create mode 100644 MariaDb/MigrationsRunner.cs delete mode 100644 SQL/galliumplus-ddl.sql delete mode 100644 SQL/galliumplus-enums.sql delete mode 100644 Service/appsettings.Development.json diff --git "a/.github/workflows/V\303\251rifications.yml" "b/.github/workflows/V\303\251rifications.yml" index 86fe044..6f9ef31 100644 --- "a/.github/workflows/V\303\251rifications.yml" +++ "b/.github/workflows/V\303\251rifications.yml" @@ -23,17 +23,17 @@ jobs: uses: actions/setup-python@v4.7.1 with: python-version: '3.10' - if: github.event_name != 'pull_request' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' - name: Install Paramiko run: python3 -m pip install paramiko - if: github.event_name != 'pull_request' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' - name: Deploy build env: DEPLOY_HOSTNAME: ${{ secrets.DEPLOY_HOSTNAME }} DEPLOY_USERNAME: ${{ secrets.DEPLOY_USERNAME }} DEPLOY_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }} run: python3 .deployment/galliumplus-deploy - if: github.event_name != 'pull_request' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' unit-tests: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index fa0da14..18db682 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore MariaDbTests +appsettings.Development.json # User-specific files *.rsuser diff --git a/.idea/.idea.Gallium+ API/.idea/codeStyles/Project.xml b/.idea/.idea.Gallium+ API/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..b471bb1 --- /dev/null +++ b/.idea/.idea.Gallium+ API/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Gallium+ API/.idea/codeStyles/codeStyleConfig.xml b/.idea/.idea.Gallium+ API/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/.idea.Gallium+ API/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Gallium+ API/.idea/encodings.xml b/.idea/.idea.Gallium+ API/.idea/encodings.xml new file mode 100644 index 0000000..6cc3165 --- /dev/null +++ b/.idea/.idea.Gallium+ API/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Gallium+ API.sln.DotSettings b/Gallium+ API.sln.DotSettings new file mode 100644 index 0000000..acc9c9c --- /dev/null +++ b/Gallium+ API.sln.DotSettings @@ -0,0 +1,4 @@ + + WARNING + FileScoped + True \ No newline at end of file diff --git a/MariaDb/CategoryDao.cs b/MariaDb/Implementations/CategoryDao.cs similarity index 97% rename from MariaDb/CategoryDao.cs rename to MariaDb/Implementations/CategoryDao.cs index 99c73c5..4f3113a 100644 --- a/MariaDb/CategoryDao.cs +++ b/MariaDb/Implementations/CategoryDao.cs @@ -4,7 +4,7 @@ using KiwiQuery; using MySqlConnector; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class CategoryDao : Dao, ICategoryDao { diff --git a/MariaDb/ClientDao.cs b/MariaDb/Implementations/ClientDao.cs similarity index 98% rename from MariaDb/ClientDao.cs rename to MariaDb/Implementations/ClientDao.cs index 4c615c3..d1b5625 100644 --- a/MariaDb/ClientDao.cs +++ b/MariaDb/Implementations/ClientDao.cs @@ -1,13 +1,13 @@ -using GalliumPlus.WebApi.Core; +using System.Data; +using GalliumPlus.WebApi.Core; using GalliumPlus.WebApi.Core.Applications; using GalliumPlus.WebApi.Core.Data; using GalliumPlus.WebApi.Core.Exceptions; using GalliumPlus.WebApi.Core.Users; using KiwiQuery; using MySqlConnector; -using System.Data; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class ClientDao : Dao, IClientDao { diff --git a/MariaDb/HistoryDao.cs b/MariaDb/Implementations/HistoryDao.cs similarity index 93% rename from MariaDb/HistoryDao.cs rename to MariaDb/Implementations/HistoryDao.cs index 4e7caf0..a0f4853 100644 --- a/MariaDb/HistoryDao.cs +++ b/MariaDb/Implementations/HistoryDao.cs @@ -1,12 +1,12 @@ -using GalliumPlus.WebApi.Core.Data; +using System.Data; +using GalliumPlus.WebApi.Core.Data; using GalliumPlus.WebApi.Core.Data.HistorySearch; using GalliumPlus.WebApi.Core.Exceptions; using GalliumPlus.WebApi.Core.History; using KiwiQuery; using MySqlConnector; -using System.Data; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class HistoryDao : Dao, IHistoryDao { @@ -51,7 +51,7 @@ private int EnsureUserIsInHistory(string userId, Schema db) { try { - if (FindHistoryUserId(userId, db, out int id)) + if (this.FindHistoryUserId(userId, db, out int id)) { return id; } @@ -63,7 +63,7 @@ private int EnsureUserIsInHistory(string userId, Schema db) catch (MySqlException error) { if (error.ErrorCode == MySqlErrorCode.DuplicateKeyEntry - && FindHistoryUserId(userId, db, out int id)) + && this.FindHistoryUserId(userId, db, out int id)) { return id; } @@ -75,7 +75,7 @@ public void CheckUserNotInHistory(string userId) { using var connection = this.Connect(); - if (FindHistoryUserId(userId, new Schema(connection), out int _)) + if (this.FindHistoryUserId(userId, new Schema(connection), out int _)) { throw new DuplicateItemException("Un autre utilisateur avec cet identifiant existe déjà dans l'historique."); } diff --git a/MariaDb/ProductDao.cs b/MariaDb/Implementations/ProductDao.cs similarity index 99% rename from MariaDb/ProductDao.cs rename to MariaDb/Implementations/ProductDao.cs index 76082e5..09bae45 100644 --- a/MariaDb/ProductDao.cs +++ b/MariaDb/Implementations/ProductDao.cs @@ -4,7 +4,7 @@ using KiwiQuery; using MySqlConnector; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class ProductDao : Dao, IProductDao { diff --git a/MariaDb/RoleDao.cs b/MariaDb/Implementations/RoleDao.cs similarity index 97% rename from MariaDb/RoleDao.cs rename to MariaDb/Implementations/RoleDao.cs index 3329093..6bacbe5 100644 --- a/MariaDb/RoleDao.cs +++ b/MariaDb/Implementations/RoleDao.cs @@ -4,7 +4,7 @@ using KiwiQuery; using MySqlConnector; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class RoleDao : Dao, IRoleDao { diff --git a/MariaDb/SessionDao.cs b/MariaDb/Implementations/SessionDao.cs similarity index 96% rename from MariaDb/SessionDao.cs rename to MariaDb/Implementations/SessionDao.cs index 949d3ad..ff1764a 100644 --- a/MariaDb/SessionDao.cs +++ b/MariaDb/Implementations/SessionDao.cs @@ -1,11 +1,10 @@ -using GalliumPlus.WebApi.Core.Applications; -using GalliumPlus.WebApi.Core.Data; +using GalliumPlus.WebApi.Core.Data; using GalliumPlus.WebApi.Core.Exceptions; using GalliumPlus.WebApi.Core.Users; using KiwiQuery; using MySqlConnector; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class SessionDao : Dao, ISessionDao { diff --git a/MariaDb/UserDao.cs b/MariaDb/Implementations/UserDao.cs similarity index 98% rename from MariaDb/UserDao.cs rename to MariaDb/Implementations/UserDao.cs index 93a7625..91478ac 100644 --- a/MariaDb/UserDao.cs +++ b/MariaDb/Implementations/UserDao.cs @@ -1,13 +1,12 @@ -using GalliumPlus.WebApi.Core; -using GalliumPlus.WebApi.Core.Applications; +using System.Data; +using GalliumPlus.WebApi.Core; using GalliumPlus.WebApi.Core.Data; using GalliumPlus.WebApi.Core.Exceptions; using GalliumPlus.WebApi.Core.Users; using KiwiQuery; using MySqlConnector; -using System.Data; -namespace GalliumPlus.WebApi.Data.MariaDb +namespace GalliumPlus.WebApi.Data.MariaDb.Implementations { public class UserDao : Dao, IUserDao { diff --git a/MariaDb/MariaDb.csproj b/MariaDb/MariaDb.csproj index 50143d4..772a647 100644 --- a/MariaDb/MariaDb.csproj +++ b/MariaDb/MariaDb.csproj @@ -8,6 +8,9 @@ + + + diff --git a/MariaDb/MariaDbOptions.cs b/MariaDb/MariaDbOptions.cs index bbecf7b..3fda25d 100644 --- a/MariaDb/MariaDbOptions.cs +++ b/MariaDb/MariaDbOptions.cs @@ -11,5 +11,8 @@ public class MariaDbOptions public string Schema { get; set; } = "galliumplus"; public uint Port { get; set; } = 3306; + + public string ToConnectionString() => + $"Server={this.Host};Port={this.Port};User ID={this.UserId};Password={this.Password};Database={this.Schema}"; } } diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_BotClient_extends_Client.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_BotClient_extends_Client.cs new file mode 100644 index 0000000..4ce0c0f --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_BotClient_extends_Client.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_016)] +public class CreateForeignKey_BotClient_extends_Client : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_BotClient_extends_Client") + .FromTable("BotClient").ForeignColumn("id").ToTable("Client").PrimaryColumn("id") + .OnUpdate(Rule.Cascade) .OnDelete(Rule.Cascade); + } + + public override void Down() + { + this.Delete.ForeignKey("BotClient_extends_Client"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_actor.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_actor.cs new file mode 100644 index 0000000..b5bfe2c --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_actor.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_019)] +public class CreateForeignKey_HistoryAction_HistoryUser_actor : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_HistoryAction_HistoryUser_actor") + .FromTable("HistoryAction").ForeignColumn("actor").ToTable("HistoryUser").PrimaryColumn("id") + .OnUpdate(Rule.None).OnDelete(Rule.None); + } + + public override void Down() + { + this.Delete.ForeignKey("HistoryAction_HistoryUser_actor"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_target.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_target.cs new file mode 100644 index 0000000..248056a --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_HistoryAction_HistoryUser_target.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_020)] +public class CreateForeignKey_HistoryAction_HistoryUser_target : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_HistoryAction_HistoryUser_target") + .FromTable("HistoryAction").ForeignColumn("target").ToTable("HistoryUser").PrimaryColumn("id") + .OnUpdate(Rule.None).OnDelete(Rule.None); + } + + public override void Down() + { + this.Delete.ForeignKey("HistoryAction_HistoryUser_target"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_PasswordResetToken_User_userId.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_PasswordResetToken_User_userId.cs new file mode 100644 index 0000000..01ef06f --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_PasswordResetToken_User_userId.cs @@ -0,0 +1,23 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_013)] +public class CreateForeignKey_PasswordResetToken_User_userId : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_PasswordResetToken_User_userId") + .FromTable("PasswordResetToken").ForeignColumn("userId").ToTable("User").PrimaryColumn("userId") + .OnUpdate(Rule.Cascade).OnDelete(Rule.Cascade); + + } + + public override void Down() + { + this.Delete.ForeignKey("FK_PasswordResetToken_User_userId"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_Product_Category_category.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_Product_Category_category.cs new file mode 100644 index 0000000..65110c2 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_Product_Category_category.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_018)] +public class CreateForeignKey_Product_Category_category : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_Product_Category_category") + .FromTable("Product").ForeignColumn("category").ToTable("Category").PrimaryColumn("id") + .OnUpdate(Rule.Cascade) .OnDelete(Rule.None); + } + + public override void Down() + { + this.Delete.ForeignKey("Product_Category_category"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_Client_client.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_Client_client.cs new file mode 100644 index 0000000..2aaf21e --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_Client_client.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_015)] +public class CreateForeignKey_Session_Client_client : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_Session_Client_client") + .FromTable("Session").ForeignColumn("client").ToTable("Client").PrimaryColumn("id") + .OnUpdate(Rule.Cascade) .OnDelete(Rule.Cascade); + } + + public override void Down() + { + this.Delete.ForeignKey("Session_Client_client"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_User_user.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_User_user.cs new file mode 100644 index 0000000..17eb493 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_Session_User_user.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_014)] +public class CreateForeignKey_Session_User_user : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_Session_User_user") + .FromTable("Session").ForeignColumn("user").ToTable("User").PrimaryColumn("id") + .OnUpdate(Rule.Cascade) .OnDelete(Rule.Cascade); + } + + public override void Down() + { + this.Delete.ForeignKey("Session_User_user"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_SsoClient_extends_Client.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_SsoClient_extends_Client.cs new file mode 100644 index 0000000..5a42f97 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_SsoClient_extends_Client.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_017)] +public class CreateForeignKey_SsoClient_extends_Client : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_SsoClient_extends_Client") + .FromTable("SsoClient").ForeignColumn("id").ToTable("Client").PrimaryColumn("id") + .OnUpdate(Rule.Cascade) .OnDelete(Rule.Cascade); + } + + public override void Down() + { + this.Delete.ForeignKey("SsoClient_extends_Client"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateForeignKey_User_Role_role.cs b/MariaDb/Migrations/v1_00_00/CreateForeignKey_User_Role_role.cs new file mode 100644 index 0000000..079a06c --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateForeignKey_User_Role_role.cs @@ -0,0 +1,22 @@ +using System.Data; +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_012)] +public class CreateForeignKey_User_Role_role : Migration +{ + public override void Up() + { + this.Create.ForeignKey("FK_User_Role_role") + .FromTable("User").ForeignColumn("role").ToTable("Role").PrimaryColumn("id") + .OnUpdate(Rule.Cascade).OnDelete(Rule.None); + } + + public override void Down() + { + this.Delete.ForeignKey("FK_User_Role_role"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_BotClient.cs b/MariaDb/Migrations/v1_00_00/CreateTable_BotClient.cs new file mode 100644 index 0000000..1b86416 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_BotClient.cs @@ -0,0 +1,22 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_007)] +public class CreateTable_BotClient : Migration +{ + public override void Up() + { + this.Create.Table("BotClient") + .WithColumn("id").AsInt64().PrimaryKey() + .WithColumn("secret").AsCustom("BINARY(32)").NotNullable().WithDefaultValue(new string('\0', 32)) + .WithColumn("salt").AsCustom("CHAR(32) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().WithDefaultValue(""); + } + + public override void Down() + { + this.Delete.Table("BotClient"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_Category.cs b/MariaDb/Migrations/v1_00_00/CreateTable_Category.cs new file mode 100644 index 0000000..9bef47a --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_Category.cs @@ -0,0 +1,21 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_001)] +public class CreateTable_Category : Migration +{ + public override void Up() + { + this.Create.Table("Category") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("name").AsString().NotNullable(); + } + + public override void Down() + { + this.Delete.Table("Category"); + } +} diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_Client.cs b/MariaDb/Migrations/v1_00_00/CreateTable_Client.cs new file mode 100644 index 0000000..416f92a --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_Client.cs @@ -0,0 +1,25 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_006)] +public class CreateTable_Client : Migration +{ + public override void Up() + { + this.Create.Table("Client") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("apiKey").AsCustom("CHAR(20) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().Unique() + .WithColumn("name").AsString(50).NotNullable() + .WithColumn("granted").AsInt16().NotNullable() + .WithColumn("revoked").AsInt16().NotNullable() + .WithColumn("isEnabled").AsBoolean().NotNullable(); + } + + public override void Down() + { + this.Delete.Table("Client"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_HistoryAction.cs b/MariaDb/Migrations/v1_00_00/CreateTable_HistoryAction.cs new file mode 100644 index 0000000..06c921e --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_HistoryAction.cs @@ -0,0 +1,26 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_010)] +public class CreateTable_HistoryAction : Migration +{ + public override void Up() + { + this.Create.Table("HistoryAction") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("text").AsString(120).NotNullable() + .WithColumn("time").AsDateTime2().NotNullable() + .WithColumn("kind").AsInt16().NotNullable() + .WithColumn("actor").AsInt64().Nullable() + .WithColumn("target").AsInt64().Nullable() + .WithColumn("numericValue").AsDecimal(6, 2).Nullable(); + } + + public override void Down() + { + this.Delete.Table("HistoryAction"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_HistoryUser.cs b/MariaDb/Migrations/v1_00_00/CreateTable_HistoryUser.cs new file mode 100644 index 0000000..0a5752d --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_HistoryUser.cs @@ -0,0 +1,21 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_011)] +public class CreateTable_HistoryUser : Migration +{ + public override void Up() + { + this.Create.Table("HistoryUser") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("userId").AsCustom("VARCHAR(21) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().Unique(); + } + + public override void Down() + { + this.Delete.Table("HistoryUser"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_PasswordResetToken.cs b/MariaDb/Migrations/v1_00_00/CreateTable_PasswordResetToken.cs new file mode 100644 index 0000000..e7240f4 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_PasswordResetToken.cs @@ -0,0 +1,25 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_003)] +public class CreateTable_PasswordResetToken : Migration +{ + public override void Up() + { + this.Create.Table("PasswordResetToken") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("token").AsCustom("CHAR(20) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().Unique() + .WithColumn("secret").AsCustom("BINARY(32)").NotNullable().WithDefaultValue(new string('\0', 32)) + .WithColumn("salt").AsCustom("CHAR(32) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().WithDefaultValue("") + .WithColumn("expiration").AsDateTime2().NotNullable() + .WithColumn("userId").AsCustom("VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin").NotNullable(); + } + + public override void Down() + { + this.Delete.Table("PasswordResetToken"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_Product.cs b/MariaDb/Migrations/v1_00_00/CreateTable_Product.cs new file mode 100644 index 0000000..fd46877 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_Product.cs @@ -0,0 +1,26 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_009)] +public class CreateTable_Product : Migration +{ + public override void Up() + { + this.Create.Table("Product") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("name").AsString(50).NotNullable() + .WithColumn("stock").AsInt32().NotNullable() + .WithColumn("nonMemberPrice").AsDecimal(6, 2).NotNullable() + .WithColumn("memberPrice").AsDecimal(6, 2).NotNullable() + .WithColumn("availability").AsInt16().NotNullable() + .WithColumn("category").AsInt64().NotNullable(); + } + + public override void Down() + { + this.Delete.Table("Product"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_Role.cs b/MariaDb/Migrations/v1_00_00/CreateTable_Role.cs new file mode 100644 index 0000000..44323ad --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_Role.cs @@ -0,0 +1,22 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_004)] +public class CreateTable_Role : Migration +{ + public override void Up() + { + this.Create.Table("Role") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("name").AsString(50).NotNullable() + .WithColumn("permissions").AsInt16().NotNullable(); + } + + public override void Down() + { + this.Delete.Table("Role"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_Session.cs b/MariaDb/Migrations/v1_00_00/CreateTable_Session.cs new file mode 100644 index 0000000..6ee544d --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_Session.cs @@ -0,0 +1,25 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_005)] +public class CreateTable_Session : Migration +{ + public override void Up() + { + this.Create.Table("Session") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("token").AsCustom("CHAR(20) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().Unique() + .WithColumn("lastUse").AsDateTime2().NotNullable() + .WithColumn("expiration").AsDateTime2().NotNullable() + .WithColumn("user").AsInt64().Nullable() + .WithColumn("client").AsInt64().NotNullable(); + } + + public override void Down() + { + this.Delete.Table("Session"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_SsoClient.cs b/MariaDb/Migrations/v1_00_00/CreateTable_SsoClient.cs new file mode 100644 index 0000000..49d5596 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_SsoClient.cs @@ -0,0 +1,24 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_008)] +public class CreateTable_SsoClient : Migration +{ + public override void Up() + { + this.Create.Table("SsoClient") + .WithColumn("id").AsInt64().PrimaryKey() + .WithColumn("secret").AsString(30).NotNullable() + .WithColumn("usesApi").AsBoolean().NotNullable() + .WithColumn("redirectUrl").AsString(120).NotNullable() + .WithColumn("logoUrl").AsString(120).Nullable(); + } + + public override void Down() + { + this.Delete.Table("SsoClient"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_00/CreateTable_User.cs b/MariaDb/Migrations/v1_00_00/CreateTable_User.cs new file mode 100644 index 0000000..4168b80 --- /dev/null +++ b/MariaDb/Migrations/v1_00_00/CreateTable_User.cs @@ -0,0 +1,31 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_00; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_002)] +public class CreateTable_User : Migration +{ + public override void Up() + { + this.Create.Table("User") + .WithColumn("id").AsInt64().PrimaryKey().Identity() + .WithColumn("userId").AsCustom("VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().Unique().NotNullable() + .WithColumn("firstName").AsString(50).NotNullable() + .WithColumn("lastName").AsString(50).NotNullable() + .WithColumn("email").AsString(80).NotNullable() + .WithColumn("role").AsInt64().NotNullable() + .WithColumn("year").AsString(10).NotNullable() + .WithColumn("deposit").AsDecimal(6,2).Nullable() + .WithColumn("isMember").AsBoolean().NotNullable() + .WithColumn("password").AsCustom("BINARY(32)").NotNullable().WithDefaultValue(new string('\0', 32)) + .WithColumn("salt").AsCustom("CHAR(32) CHARACTER SET ascii COLLATE ascii_bin").NotNullable().WithDefaultValue("") + .WithColumn("registration").AsDateTime2().NotNullable(); + } + + public override void Down() + { + this.Delete.Table("Client"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_04/CreateConstraint_HistoryAction_kind.cs b/MariaDb/Migrations/v1_00_04/CreateConstraint_HistoryAction_kind.cs new file mode 100644 index 0000000..8ab64ff --- /dev/null +++ b/MariaDb/Migrations/v1_00_04/CreateConstraint_HistoryAction_kind.cs @@ -0,0 +1,19 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_04; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_022)] +public class CreateConstraint_HistoryAction_kind : Migration +{ + public override void Up() + { + this.Execute.Sql("ALTER TABLE `HistoryAction` ADD CONSTRAINT ENUM_HistoryAction_kind CHECK (`kind` BETWEEN 1 AND 4);"); + } + + public override void Down() + { + this.Execute.Sql("ALTER TABLE `HistoryAction` DROP CONSTRAINT ENUM_HistoryAction_kind;"); + } +} \ No newline at end of file diff --git a/MariaDb/Migrations/v1_00_04/CreateConstraint_Product_availability.cs b/MariaDb/Migrations/v1_00_04/CreateConstraint_Product_availability.cs new file mode 100644 index 0000000..5eb0c39 --- /dev/null +++ b/MariaDb/Migrations/v1_00_04/CreateConstraint_Product_availability.cs @@ -0,0 +1,19 @@ +using FluentMigrator; + +namespace GalliumPlus.WebApi.Data.MariaDb.Migrations.v1_00_04; + +// ReSharper disable once InconsistentNaming +// ReSharper disable once UnusedType.Global +[Migration(2024_07_03_021)] +public class CreateConstraint_Product_availability : Migration +{ + public override void Up() + { + this.Execute.Sql("ALTER TABLE `Product` ADD CONSTRAINT ENUM_Product_availability CHECK (`availability` BETWEEN 0 AND 2);"); + } + + public override void Down() + { + this.Execute.Sql("ALTER TABLE `Product` DROP CONSTRAINT ENUM_Product_availability;"); + } +} \ No newline at end of file diff --git a/MariaDb/MigrationsRunner.cs b/MariaDb/MigrationsRunner.cs new file mode 100644 index 0000000..570e649 --- /dev/null +++ b/MariaDb/MigrationsRunner.cs @@ -0,0 +1,13 @@ +using FluentMigrator.Runner; +using Microsoft.Extensions.DependencyInjection; + +namespace GalliumPlus.WebApi.Data.MariaDb; + +public class MigrationsRunner +{ + public static void UpdateDatabase(IServiceProvider serviceProvider) + { + var runner = serviceProvider.GetRequiredService(); + runner.MigrateUp(); + } +} \ No newline at end of file diff --git a/SQL/galliumplus-ddl.sql b/SQL/galliumplus-ddl.sql deleted file mode 100644 index f426980..0000000 --- a/SQL/galliumplus-ddl.sql +++ /dev/null @@ -1,142 +0,0 @@ --- Création des tables -- - -USE galliumplus; - -ALTER DATABASE `galliumplus` -DEFAULT CHARACTER SET utf8mb4 -DEFAULT COLLATE utf8mb4_unicode_520_ci; - -CREATE TABLE `User` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `userId` VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - `firstName` VARCHAR(50) NOT NULL, - `lastName` VARCHAR(50) NOT NULL, - `email` VARCHAR(80) NOT NULL, - `role` INTEGER NOT NULL, - `year` VARCHAR(10) NOT NULL, - `deposit` DECIMAL(6,2), - `isMember` BOOLEAN NOT NULL, - `password` BINARY(32) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', - `salt` CHAR(32) NOT NULL DEFAULT '', - `registration` DATETIME NOT NULL, - PRIMARY KEY (`id`), - UNIQUE (`userId`) -); - -CREATE TABLE `PasswordResetToken` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `token` VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - `secret` BINARY(32) NOT NULL, - `salt` CHAR(32) NOT NULL, - `expiration` DATETIME NOT NULL, - `userId` VARCHAR(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - PRIMARY KEY (`id`), - UNIQUE (`token`) -); - -CREATE TABLE `Role` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(50) NOT NULL, - `permissions` INTEGER NOT NULL, - PRIMARY KEY (`id`) -); - -CREATE TABLE `Session` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `token` CHAR(20) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - `lastUse` DATETIME NOT NULL, - `expiration` DATETIME NOT NULL, - `user` INTEGER, - `client` INTEGER NOT NULL, - PRIMARY KEY (`id`), - UNIQUE (`token`) -); - -CREATE TABLE `Client` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `apiKey` CHAR(20) NOT NULL CHARACTER SET ascii COLLATE ascii_bin, - `name` VARCHAR(50) NOT NULL, - `granted` INTEGER NOT NULL, - `revoked` INTEGER NOT NULL, - `isEnabled` BOOLEAN NOT NULL, - PRIMARY KEY (`id`), - UNIQUE (`apiKey`) -); - -CREATE TABLE `BotClient` ( - `id` INTEGER NOT NULL, - `secret` BINARY(32) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0', - `salt` CHAR(32) NOT NULL DEFAULT '', - PRIMARY KEY (`id`) -); - -CREATE TABLE `SsoClient` ( - `id` INTEGER NOT NULL, - `secret` CHAR(30) NOT NULL, - `usesApi` BOOLEAN NOT NULL, - `redirectUrl` VARCHAR(120) NOT NULL, - `logoUrl` VARCHAR(120), - PRIMARY KEY (`id`) -); - -CREATE TABLE `Product` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(50) NOT NULL, - `stock` INTEGER NOT NULL, - `nonMemberPrice` DECIMAL(6,2) NOT NULL, - `memberPrice` DECIMAL(6,2) NOT NULL, - `availability` INTEGER NOT NULL, - `category` INTEGER NOT NULL, - PRIMARY KEY (`id`) -); - -CREATE TABLE `Availability` ( - `enum` INTEGER NOT NULL, - `description` VARCHAR(50), - PRIMARY KEY (`enum`) -); - -CREATE TABLE `Category` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `name` VARCHAR(50) NOT NULL, - PRIMARY KEY (`id`) -); - -CREATE TABLE `HistoryAction` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `text` VARCHAR(120) NOT NULL, - `time` DATETIME NOT NULL, - `kind` INTEGER NOT NULL, - `actor` INTEGER, - `target` INTEGER, - `numericValue` DECIMAL(6,2), - PRIMARY KEY (`id`) -); - -CREATE TABLE `HistoryActionKind` ( - `enum` INTEGER NOT NULL, - `description` VARCHAR(50), - PRIMARY KEY (`enum`) -); - -CREATE TABLE `HistoryUser` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `userId` VARCHAR(21) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - PRIMARY KEY (`id`), - UNIQUE (`userId`) -); - -ALTER TABLE `User` ADD FOREIGN KEY (`role`) REFERENCES `Role`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT; -ALTER TABLE `PasswordResetToken` ADD FOREIGN KEY (`userId`) REFERENCES `User`(`userId`) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE `Session` ADD FOREIGN KEY (`user`) REFERENCES `User`(`id`) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE `Session` ADD FOREIGN KEY (`client`) REFERENCES `Client`(`id`) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE `BotClient` ADD FOREIGN KEY (`id`) REFERENCES `Client`(`id`) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE `SsoClient` ADD FOREIGN KEY (`id`) REFERENCES `Client`(`id`) ON UPDATE CASCADE ON DELETE CASCADE; -ALTER TABLE `Product` ADD FOREIGN KEY (`availability`) REFERENCES `Availability`(`enum`) ON UPDATE RESTRICT ON DELETE RESTRICT; -ALTER TABLE `Product` ADD FOREIGN KEY (`category`) REFERENCES `Category`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT; -ALTER TABLE `HistoryAction` ADD FOREIGN KEY (`actor`) REFERENCES `HistoryUser`(`id`) ON UPDATE RESTRICT ON DELETE RESTRICT; -ALTER TABLE `HistoryAction` ADD FOREIGN KEY (`target`) REFERENCES `HistoryUser`(`id`) ON UPDATE RESTRICT ON DELETE RESTRICT; -ALTER TABLE `HistoryAction` ADD FOREIGN KEY (`kind`) REFERENCES `HistoryActionKind`(`enum`) ON UPDATE RESTRICT ON DELETE RESTRICT; -ALTER TABLE `HistoryUser` ADD FOREIGN KEY (`activeUser`) REFERENCES `User`(`id`) ON UPDATE RESTRICT ON DELETE RESTRICT; - -SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/SQL/galliumplus-enums.sql b/SQL/galliumplus-enums.sql deleted file mode 100644 index 7fe47f4..0000000 --- a/SQL/galliumplus-enums.sql +++ /dev/null @@ -1,14 +0,0 @@ --- Remplissage des tables d'énumération -- - -USE galliumplus; - -INSERT INTO `Availability`(`enum`, `description`) VALUES - (0, 'Automatique'), - (1, 'Toujours'), - (2, 'Jamais'); - -INSERT INTO `HistoryActionKind`(`enum`, `description`) VALUES - (1, 'Connexion'); - (2, 'Gestion des produits et des catégories'), - (3, 'Gestion des utilisateurs et des rôles'), - (4, 'Achat'); \ No newline at end of file diff --git a/Service/Program.cs b/Service/Program.cs index 48a7b30..d08ff15 100644 --- a/Service/Program.cs +++ b/Service/Program.cs @@ -13,24 +13,31 @@ using System.Text.Json.Serialization; using GalliumPlus.WebApi.Scheduling; using GalliumPlus.WebApi.Core.Email; -#if FAKE_DB && FAKE_EMAIL + +#if FAKE_DB using GalliumPlus.WebApi.Data.FakeDatabase; -using GalliumPlus.WebApi.Email.FakeEmailService; #else using GalliumPlus.WebApi.Data.MariaDb; +using GalliumPlus.WebApi.Data.MariaDb.Implementations; +using FluentMigrator.Runner; +#endif + +#if FAKE_EMAIL +using GalliumPlus.WebApi.Email.FakeEmailService; +#else using GalliumPlus.WebApi.Email.MailKit; -#endif +#endif #endregion var builder = WebApplication.CreateBuilder(args); -#region Configuration g?n?rale et options +#region Configuration générale et options builder.Services .AddControllers(options => { - // Filtre pour les exceptions propres ? Gallium + // Filtre pour les exceptions propres à Gallium options.Filters.Add(); // Filtre pour les permissions de Gallium options.Filters.Add(); @@ -44,17 +51,18 @@ options.SuppressMapClientErrors = true; }); -GalliumOptions galliumOptions = builder.Configuration.GetSection("Gallium").Get() ?? new GalliumOptions(); +GalliumOptions galliumOptions = + builder.Configuration.GetSection("Gallium").Get() ?? new GalliumOptions(); builder.Services.AddSingleton(galliumOptions); builder.Services.AddServerInfo(); #endregion -#region Base de donn?es (Fake & MariaDB) +#region Base de données (Fake & MariaDB) #if FAKE_DB -// ajout en singleton, sinon les donn?es ne sont pas persist?es d'une requ?te ? l'autre +// ajout en singleton, sinon les données ne sont pas persist?es d'une requête à l'autre builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -72,21 +80,23 @@ builder.Services.AddScoped(); builder.Services.AddSingleton(new DatabaseConnector(galliumOptions.MariaDb)); + +builder.Services.AddFluentMigratorCore() + .ConfigureRunner(rb => + { + rb.AddMySql8() + .WithGlobalConnectionString(galliumOptions.MariaDb.ToConnectionString()) + .ScanIn(typeof(MigrationsRunner).Assembly).For.Migrations(); + }); #endif #endregion #region Planification (Quartz) -builder.Services.AddQuartz(quartz => -{ - quartz.AddJobs(); -}); +builder.Services.AddQuartz(quartz => { quartz.AddJobs(); }); -builder.Services.AddQuartzHostedService(quartz => -{ - quartz.WaitForJobsToComplete = true; -}); +builder.Services.AddQuartzHostedService(quartz => { quartz.WaitForJobsToComplete = true; }); #endregion @@ -97,14 +107,14 @@ services => new CachedLocalEmailTemplateLoader(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "templates")) ) #if FAKE_EMAIL - .AddSingleton(services => new FakeEmailSender()); + .AddSingleton(services => new FakeEmailSender()); #else .AddSingleton(services => new EmailSender(galliumOptions.MailKit)); #endif #endregion -#region S?rialisation (JSON) +#region Sérialisation (JSON) builder.Services.Configure(options => { @@ -112,9 +122,9 @@ options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.Strict; // accepte les virgules en fin de liste / d'objet options.JsonSerializerOptions.AllowTrailingCommas = true; - // garde les noms de propri?t?s tels quels + // garde les noms de propriétés tels quels options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; - // s?rialise les ?num?rations sous forme de texte + // sérialise les énumérations sous forme de texte options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); @@ -126,15 +136,15 @@ { Action httpsConfiguration = options => { - if (galliumOptions.CertificateFile is { } certififcate) + if (galliumOptions.CertificateFile is { } certificate) { if (galliumOptions.CertificatePassword is { } password) { - options.UseHttps(certififcate, password); + options.UseHttps(certificate, password); } else { - options.UseHttps(certififcate); + options.UseHttps(certificate); } } else @@ -157,10 +167,7 @@ builder.Services.AddCors(options => { - options.AddDefaultPolicy(policy => - { - policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); - }); + options.AddDefaultPolicy(policy => { policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); }); }); #endregion @@ -187,4 +194,11 @@ ServerInfo.Current.SetVersion(1, 0, 2, "beta"); Console.WriteLine(ServerInfo.Current); -app.Run(); +#if !FAKE_DB +using (IServiceScope scope = app.Services.CreateScope()) +{ + MigrationsRunner.UpdateDatabase(scope.ServiceProvider); +} +#endif + +app.Run(); \ No newline at end of file diff --git a/Service/appsettings.Development.json b/Service/appsettings.Development.json deleted file mode 100644 index 48f8fa2..0000000 --- a/Service/appsettings.Development.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning", - "GalliumPlus.WebApi.Middleware": "Warning" - } - }, - "Gallium": { - "MailKit": { - "SenderDisplayName": "Gallium+", - "SenderAddress": "noreply.lotd@gmail.com", - "Host": "smtp.gmail.com", - "Port": 465, - "Username": "noreply.lotd@gmail.com", - "UseSSL": true, - "UseStartTls": false - }, - "MariaDb": { - "UserId": "root", - "Password": "mdp", - "Schema": "test2" - } - } -}