-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/1719 add support mysql (#1734)
* init support mysql * Add MySQL migrations + move postgres migration to new project * update namespace Postgres + fix quartz migration MySQL * Fix startup check connectionstring * Add MySql Quartz scheduler configuration * Update unit tests + startup Quartz config * update sql Quartz migration * Add custom mysql provider for quartz * Remove unused directive * Move database migrate to app configure * Add DatabaseHelper.GetMySqlServerVersion * Remove db migrate * Use DatabaseHelper.GetMySqlServerVersion on MySQL PortalDbContextFactory * Remove ef migrate of configure app * Run ef migrate only when can connect to db * Add unit test on DatabaseHelper.GetMySqlServerVersion * update exception DatabaseHelper * Update ef nuget packages on mysql/postgres migrations projects --------- Co-authored-by: Hocine Hacherouf <hacherouf.hocine@gmail.com>
- Loading branch information
1 parent
ee3547a
commit 9964589
Showing
75 changed files
with
2,086 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/AzureIoTHub.Portal.Domain/Shared/Constants/DbProviders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace AzureIoTHub.Portal.Domain.Shared.Constants | ||
{ | ||
|
||
public static class DbProviders | ||
{ | ||
public const string PostgreSQL = "PostgreSQL"; | ||
|
||
public const string MySQL = "MySQL"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/AzureIoTHub.Portal.Infrastructure/Helpers/DatabaseHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace AzureIoTHub.Portal.Infrastructure.Helpers | ||
{ | ||
using System; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
public static class DatabaseHelper | ||
{ | ||
public static ServerVersion GetMySqlServerVersion(string mySQLConnectionString) | ||
{ | ||
try | ||
{ | ||
return ServerVersion.AutoDetect(mySQLConnectionString); | ||
} | ||
catch (ArgumentException ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
return new MySqlServerVersion(new Version(8, 0, 32)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/AzureIoTHub.Portal.MySql/AzureIoTHub.Portal.MySql.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.3" /> | ||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AzureIoTHub.Portal.Infrastructure\AzureIoTHub.Portal.Infrastructure.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
4 changes: 2 additions & 2 deletions
4
...20220903171411_Initial Create.Designer.cs → ...20220903171411_Initial Create.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#nullable disable | ||
|
||
namespace AzureIoTHub.Portal.MySql.Migrations | ||
{ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
public partial class AddQuartzNETtables : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
_ = migrationBuilder.Sql("DROP TABLE IF EXISTS QRTZ_FIRED_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_PAUSED_TRIGGER_GRPS;\r\nDROP TABLE IF EXISTS QRTZ_SCHEDULER_STATE;\r\nDROP TABLE IF EXISTS QRTZ_LOCKS;\r\nDROP TABLE IF EXISTS QRTZ_SIMPROP_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_SIMPLE_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_CRON_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_BLOB_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_JOB_DETAILS;\r\nDROP TABLE IF EXISTS QRTZ_CALENDARS;\r\n\r\n\r\nCREATE TABLE QRTZ_JOB_DETAILS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n\tJOB_NAME VARCHAR(200) NOT NULL,\r\n JOB_GROUP VARCHAR(200) NOT NULL,\r\n DESCRIPTION VARCHAR(250) NULL,\r\n JOB_CLASS_NAME VARCHAR(250) NOT NULL, \r\n IS_DURABLE BOOLEAN NOT NULL,\r\n IS_NONCONCURRENT BOOLEAN NOT NULL,\r\n IS_UPDATE_DATA BOOLEAN NOT NULL,\r\n\tREQUESTS_RECOVERY BOOLEAN NOT NULL,\r\n JOB_DATA BLOB NULL,\r\n PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_TRIGGERS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n\tTRIGGER_NAME VARCHAR(200) NOT NULL,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL,\r\n JOB_NAME VARCHAR(200) NOT NULL, \r\n JOB_GROUP VARCHAR(200) NOT NULL,\r\n DESCRIPTION VARCHAR(250) NULL,\r\n NEXT_FIRE_TIME BIGINT(13) NULL,\r\n PREV_FIRE_TIME BIGINT(13) NULL,\r\n PRIORITY INTEGER NULL,\r\n TRIGGER_STATE VARCHAR(16) NOT NULL,\r\n TRIGGER_TYPE VARCHAR(8) NOT NULL,\r\n START_TIME BIGINT(13) NOT NULL,\r\n END_TIME BIGINT(13) NULL,\r\n CALENDAR_NAME VARCHAR(200) NULL,\r\n MISFIRE_INSTR SMALLINT(2) NULL,\r\n JOB_DATA BLOB NULL,\r\n PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),\r\n FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP) \r\n\t\tREFERENCES QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP) \r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_SIMPLE_TRIGGERS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n\tTRIGGER_NAME VARCHAR(200) NOT NULL,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL,\r\n REPEAT_COUNT BIGINT(7) NOT NULL,\r\n REPEAT_INTERVAL BIGINT(12) NOT NULL,\r\n TIMES_TRIGGERED BIGINT(10) NOT NULL,\r\n PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),\r\n FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) \r\n\t\tREFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_SIMPROP_TRIGGERS \r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n TRIGGER_NAME VARCHAR(200) NOT NULL ,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL ,\r\n STR_PROP_1 VARCHAR(512) NULL,\r\n STR_PROP_2 VARCHAR(512) NULL,\r\n STR_PROP_3 VARCHAR(512) NULL,\r\n INT_PROP_1 INT NULL,\r\n INT_PROP_2 INT NULL,\r\n LONG_PROP_1 BIGINT NULL,\r\n LONG_PROP_2 BIGINT NULL,\r\n DEC_PROP_1 NUMERIC(13,4) NULL,\r\n DEC_PROP_2 NUMERIC(13,4) NULL,\r\n BOOL_PROP_1 BOOLEAN NULL,\r\n BOOL_PROP_2 BOOLEAN NULL,\r\n TIME_ZONE_ID VARCHAR(80) NULL,\r\n\tPRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),\r\n FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) \r\n\t\tREFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_CRON_TRIGGERS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n TRIGGER_NAME VARCHAR(200) NOT NULL,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL,\r\n CRON_EXPRESSION VARCHAR(120) NOT NULL,\r\n TIME_ZONE_ID VARCHAR(80),\r\n PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),\r\n FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) \r\n\t\tREFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_BLOB_TRIGGERS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n TRIGGER_NAME VARCHAR(200) NOT NULL,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL,\r\n BLOB_DATA BLOB NULL,\r\n PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),\r\n INDEX (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),\r\n FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP) \r\n\t\tREFERENCES QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_CALENDARS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n CALENDAR_NAME VARCHAR(200) NOT NULL, \r\n CALENDAR BLOB NOT NULL,\r\n PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_PAUSED_TRIGGER_GRPS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL, \r\n PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_FIRED_TRIGGERS \r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n ENTRY_ID VARCHAR(95) NOT NULL,\r\n TRIGGER_NAME VARCHAR(200) NOT NULL,\r\n TRIGGER_GROUP VARCHAR(200) NOT NULL,\r\n INSTANCE_NAME VARCHAR(200) NOT NULL,\r\n FIRED_TIME BIGINT(13) NOT NULL,\r\n\tSCHED_TIME BIGINT(13) NOT NULL,\r\n PRIORITY INTEGER NOT NULL,\r\n STATE VARCHAR(16) NOT NULL,\r\n JOB_NAME VARCHAR(200) NULL,\r\n JOB_GROUP VARCHAR(200) NULL,\r\n IS_NONCONCURRENT BOOLEAN NOT NULL,\r\n REQUESTS_RECOVERY BOOLEAN NULL,\r\n PRIMARY KEY (SCHED_NAME,ENTRY_ID)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_SCHEDULER_STATE \r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n INSTANCE_NAME VARCHAR(200) NOT NULL,\r\n LAST_CHECKIN_TIME BIGINT(13) NOT NULL,\r\n CHECKIN_INTERVAL BIGINT(13) NOT NULL,\r\n PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE TABLE QRTZ_LOCKS\r\n (\r\n SCHED_NAME VARCHAR(120) NOT NULL,\r\n LOCK_NAME VARCHAR(40) NOT NULL, \r\n PRIMARY KEY (SCHED_NAME,LOCK_NAME)\r\n)ENGINE=InnoDB;\r\n\r\nCREATE INDEX IDX_QRTZ_J_REQ_RECOVERY ON QRTZ_JOB_DETAILS(SCHED_NAME,REQUESTS_RECOVERY);\r\nCREATE INDEX IDX_QRTZ_J_GRP ON QRTZ_JOB_DETAILS(SCHED_NAME,JOB_GROUP);\r\nCREATE INDEX IDX_QRTZ_T_J ON QRTZ_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);\r\nCREATE INDEX IDX_QRTZ_T_JG ON QRTZ_TRIGGERS(SCHED_NAME,JOB_GROUP);\r\nCREATE INDEX IDX_QRTZ_T_C ON QRTZ_TRIGGERS(SCHED_NAME,CALENDAR_NAME);\r\nCREATE INDEX IDX_QRTZ_T_G ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);\r\nCREATE INDEX IDX_QRTZ_T_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE);\r\nCREATE INDEX IDX_QRTZ_T_N_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE);\r\nCREATE INDEX IDX_QRTZ_T_N_G_STATE ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE);\r\nCREATE INDEX IDX_QRTZ_T_NEXT_FIRE_TIME ON QRTZ_TRIGGERS(SCHED_NAME,NEXT_FIRE_TIME);\r\nCREATE INDEX IDX_QRTZ_T_NFT_ST ON QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME);\r\nCREATE INDEX IDX_QRTZ_T_NFT_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME);\r\nCREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE);\r\nCREATE INDEX IDX_QRTZ_T_NFT_ST_MISFIRE_GRP ON QRTZ_TRIGGERS(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE);\r\nCREATE INDEX IDX_QRTZ_FT_TRIG_INST_NAME ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME);\r\nCREATE INDEX IDX_QRTZ_FT_INST_JOB_REQ_RCVRY ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY);\r\nCREATE INDEX IDX_QRTZ_FT_J_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_NAME,JOB_GROUP);\r\nCREATE INDEX IDX_QRTZ_FT_JG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,JOB_GROUP);\r\nCREATE INDEX IDX_QRTZ_FT_T_G ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);\r\nCREATE INDEX IDX_QRTZ_FT_TG ON QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);\r\n"); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
_ = migrationBuilder.Sql("DROP TABLE IF EXISTS QRTZ_FIRED_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_PAUSED_TRIGGER_GRPS;\r\nDROP TABLE IF EXISTS QRTZ_SCHEDULER_STATE;\r\nDROP TABLE IF EXISTS QRTZ_LOCKS;\r\nDROP TABLE IF EXISTS QRTZ_SIMPROP_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_SIMPLE_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_CRON_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_BLOB_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_TRIGGERS;\r\nDROP TABLE IF EXISTS QRTZ_JOB_DETAILS;\r\nDROP TABLE IF EXISTS QRTZ_CALENDARS;\r\n"); | ||
} | ||
} | ||
} |
Oops, something went wrong.