diff --git a/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs b/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs index dfbe9248f..d66ca86c8 100644 --- a/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Domain/ConfigHandler.cs @@ -70,5 +70,9 @@ public abstract class ConfigHandler public abstract string IdeasAuthenticationToken { get; } public abstract string PostgreSQLConnectionString { get; } + + public abstract string MySQLConnectionString { get; } + + public abstract string DbProvider { get; } } } diff --git a/src/AzureIoTHub.Portal.Domain/Shared/Constants/DbProviders.cs b/src/AzureIoTHub.Portal.Domain/Shared/Constants/DbProviders.cs new file mode 100644 index 000000000..e18364170 --- /dev/null +++ b/src/AzureIoTHub.Portal.Domain/Shared/Constants/DbProviders.cs @@ -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"; + } +} diff --git a/src/AzureIoTHub.Portal.Infrastructure/AzureIoTHub.Portal.Infrastructure.csproj b/src/AzureIoTHub.Portal.Infrastructure/AzureIoTHub.Portal.Infrastructure.csproj index cd9bfad5f..adc46d7b3 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/AzureIoTHub.Portal.Infrastructure.csproj +++ b/src/AzureIoTHub.Portal.Infrastructure/AzureIoTHub.Portal.Infrastructure.csproj @@ -134,6 +134,7 @@ + diff --git a/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs b/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs index bf3fdaefc..0b3fc80bf 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/ConfigHandlerBase.cs @@ -16,6 +16,8 @@ internal abstract class ConfigHandlerBase : ConfigHandler internal const string DPSIDScopeKey = "IoTDPS:IDScope"; internal const string UseSecurityHeadersKey = "UseSecurityHeaders"; internal const string PostgreSQLConnectionStringKey = "PostgreSQL:ConnectionString"; + internal const string MySQLConnectionStringKey = "MySQL:ConnectionString"; + internal const string DbProviderKey = "DbProvider"; internal const string OIDCScopeKey = "OIDC:Scope"; internal const string OIDCAuthorityKey = "OIDC:Authority"; diff --git a/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs b/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs index e3e89ddb4..b2b80b6c1 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/DevelopmentConfigHandler.cs @@ -3,6 +3,7 @@ namespace AzureIoTHub.Portal.Infrastructure { + using AzureIoTHub.Portal.Domain.Shared.Constants; using Microsoft.Extensions.Configuration; internal class DevelopmentConfigHandler : ConfigHandlerBase @@ -76,5 +77,9 @@ internal DevelopmentConfigHandler(IConfiguration config) public override string IdeasAuthenticationToken => this.config.GetValue(IdeasAuthenticationTokenKey, string.Empty); public override string PostgreSQLConnectionString => this.config[PostgreSQLConnectionStringKey]; + + public override string MySQLConnectionString => this.config[MySQLConnectionStringKey]; + + public override string DbProvider => this.config.GetValue(DbProviderKey, DbProviders.PostgreSQL); } } diff --git a/src/AzureIoTHub.Portal.Infrastructure/Helpers/DatabaseHelper.cs b/src/AzureIoTHub.Portal.Infrastructure/Helpers/DatabaseHelper.cs new file mode 100644 index 000000000..1904b856b --- /dev/null +++ b/src/AzureIoTHub.Portal.Infrastructure/Helpers/DatabaseHelper.cs @@ -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)); + } + } + } +} diff --git a/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs b/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs index 5eb85a7de..15f21963a 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/ProductionConfigHandler.cs @@ -3,6 +3,7 @@ namespace AzureIoTHub.Portal.Infrastructure { + using AzureIoTHub.Portal.Domain.Shared.Constants; using Microsoft.Extensions.Configuration; internal class ProductionConfigHandler : ConfigHandlerBase @@ -38,6 +39,10 @@ internal ProductionConfigHandler(IConfiguration config) public override string PostgreSQLConnectionString => this.config.GetConnectionString(PostgreSQLConnectionStringKey); + public override string MySQLConnectionString => this.config.GetConnectionString(MySQLConnectionStringKey); + + public override string DbProvider => this.config.GetValue(DbProviderKey, DbProviders.PostgreSQL); + public override int StorageAccountDeviceModelImageMaxAge => this.config.GetValue(StorageAccountDeviceModelImageMaxAgeKey, 86400); public override bool UseSecurityHeaders => this.config.GetValue(UseSecurityHeadersKey, true); diff --git a/src/AzureIoTHub.Portal.Infrastructure/Startup/IServiceCollectionExtension.cs b/src/AzureIoTHub.Portal.Infrastructure/Startup/IServiceCollectionExtension.cs index ee4e2dbdf..e25c42ead 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Startup/IServiceCollectionExtension.cs +++ b/src/AzureIoTHub.Portal.Infrastructure/Startup/IServiceCollectionExtension.cs @@ -14,7 +14,9 @@ namespace AzureIoTHub.Portal.Infrastructure.Startup using AzureIoTHub.Portal.Domain; using AzureIoTHub.Portal.Domain.Options; using AzureIoTHub.Portal.Domain.Repositories; + using AzureIoTHub.Portal.Domain.Shared.Constants; using AzureIoTHub.Portal.Infrastructure.Extensions; + using AzureIoTHub.Portal.Infrastructure.Helpers; using AzureIoTHub.Portal.Infrastructure.Jobs; using AzureIoTHub.Portal.Infrastructure.Managers; using AzureIoTHub.Portal.Infrastructure.Mappers; @@ -102,23 +104,45 @@ private static IServiceCollection ConfigureDeviceRegstryDependencies(this IServi private static IServiceCollection ConfigureDatabase(this IServiceCollection services, ConfigHandler configuration) { - _ = services - .AddDbContextPool(opts => - { - _ = opts.UseNpgsql(configuration.PostgreSQLConnectionString); - _ = opts.UseExceptionProcessor(); - }); + var dbContextOptions = new DbContextOptionsBuilder(); - if (string.IsNullOrEmpty(configuration.PostgreSQLConnectionString)) - return services; + switch (configuration.DbProvider) + { + case DbProviders.PostgreSQL: + if (string.IsNullOrEmpty(configuration.PostgreSQLConnectionString)) + { + return services; + } + _ = services.AddDbContextPool(opts => + { + _ = opts.UseNpgsql(configuration.PostgreSQLConnectionString, x => x.MigrationsAssembly("AzureIoTHub.Portal.Postgres")); + _ = opts.UseExceptionProcessor(); + }); + _ = dbContextOptions.UseNpgsql(configuration.PostgreSQLConnectionString, x => x.MigrationsAssembly("AzureIoTHub.Portal.Postgres")); + break; + case DbProviders.MySQL: + if (string.IsNullOrEmpty(configuration.MySQLConnectionString)) + { + return services; + } + _ = services.AddDbContextPool(opts => + { + _ = opts.UseMySql(configuration.MySQLConnectionString, DatabaseHelper.GetMySqlServerVersion(configuration.MySQLConnectionString), x => x.MigrationsAssembly("AzureIoTHub.Portal.MySql")); + _ = opts.UseExceptionProcessor(); + }); + _ = dbContextOptions.UseMySql(configuration.MySQLConnectionString, DatabaseHelper.GetMySqlServerVersion(configuration.MySQLConnectionString), x => x.MigrationsAssembly("AzureIoTHub.Portal.MySql")); + break; + default: + return services; + } _ = services.AddScoped>(); - var dbContextOptions = new DbContextOptionsBuilder(); - _ = dbContextOptions.UseNpgsql(configuration.PostgreSQLConnectionString); - - using var ctx = new PortalDbContext(dbContextOptions.Options); - ctx.Database.Migrate(); + using var portalDbContext = new PortalDbContext(dbContextOptions.Options); + if (portalDbContext.Database.CanConnect()) + { + portalDbContext.Database.Migrate(); + } return services; } diff --git a/src/AzureIoTHub.Portal.MySql/AzureIoTHub.Portal.MySql.csproj b/src/AzureIoTHub.Portal.MySql/AzureIoTHub.Portal.MySql.csproj new file mode 100644 index 000000000..bcf5eaf31 --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/AzureIoTHub.Portal.MySql.csproj @@ -0,0 +1,22 @@ + + + + net7.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220903171411_Initial Create.Designer.cs b/src/AzureIoTHub.Portal.MySql/Migrations/20220903171411_Initial Create.Designer.cs similarity index 91% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220903171411_Initial Create.Designer.cs rename to src/AzureIoTHub.Portal.MySql/Migrations/20220903171411_Initial Create.Designer.cs index e25e391f5..3441adee9 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220903171411_Initial Create.Designer.cs +++ b/src/AzureIoTHub.Portal.MySql/Migrations/20220903171411_Initial Create.Designer.cs @@ -1,4 +1,4 @@ -// +// using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -8,7 +8,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.MySql.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220903171411_Initial Create")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220903171411_Initial Create.cs b/src/AzureIoTHub.Portal.MySql/Migrations/20220903171411_Initial Create.cs similarity index 89% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220903171411_Initial Create.cs rename to src/AzureIoTHub.Portal.MySql/Migrations/20220903171411_Initial Create.cs index 578f8d336..a4833ed7d 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220903171411_Initial Create.cs +++ b/src/AzureIoTHub.Portal.MySql/Migrations/20220903171411_Initial Create.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.MySql.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs b/src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs new file mode 100644 index 000000000..bb6d836cd --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs @@ -0,0 +1,24 @@ +// +using AzureIoTHub.Portal.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace AzureIoTHub.Portal.MySql.Migrations +{ + [DbContext(typeof(PortalDbContext))] + [Migration("20220910143007_Add Quartz .NET tables")] + partial class AddQuartzNETtables + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + +#pragma warning restore 612, 618 + } + } +} diff --git a/src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.cs b/src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.cs new file mode 100644 index 000000000..778ee3949 --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/Migrations/20220910143007_Add Quartz .NET tables.cs @@ -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"); + } + } +} diff --git a/src/AzureIoTHub.Portal.MySql/Migrations/20230127211555_InitDatabase.Designer.cs b/src/AzureIoTHub.Portal.MySql/Migrations/20230127211555_InitDatabase.Designer.cs new file mode 100644 index 000000000..54fdfb063 --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/Migrations/20230127211555_InitDatabase.Designer.cs @@ -0,0 +1,584 @@ +// +using System; +using AzureIoTHub.Portal.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AzureIoTHub.Portal.MySql.Migrations +{ + [DbContext(typeof(PortalDbContext))] + [Migration("20230127211555_InitDatabase")] + partial class InitDatabase + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Concentrator", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ClientThumbprint") + .HasColumnType("longtext"); + + b.Property("DeviceType") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsConnected") + .HasColumnType("tinyint(1)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LoraRegion") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Concentrators"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("DeviceModelId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("IsConnected") + .HasColumnType("tinyint(1)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StatusUpdatedTime") + .HasColumnType("datetime(6)"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DeviceModelId"); + + b.ToTable("Devices", (string)null); + + b.UseTptMappingStrategy(); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModel", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ABPRelaxMode") + .HasColumnType("tinyint(1)"); + + b.Property("AppEUI") + .HasColumnType("longtext"); + + b.Property("ClassType") + .HasColumnType("int"); + + b.Property("Deduplication") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Downlink") + .HasColumnType("tinyint(1)"); + + b.Property("IsBuiltin") + .HasColumnType("tinyint(1)"); + + b.Property("KeepAliveTimeout") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PreferredWindow") + .HasColumnType("int"); + + b.Property("RXDelay") + .HasColumnType("int"); + + b.Property("SensorDecoder") + .HasColumnType("longtext"); + + b.Property("SupportLoRaFeatures") + .HasColumnType("tinyint(1)"); + + b.Property("UseOTAA") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("DeviceModels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModelCommand", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Confirmed") + .HasColumnType("tinyint(1)"); + + b.Property("DeviceModelId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Frame") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsBuiltin") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Port") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("DeviceModelCommands"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModelProperty", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsWritable") + .HasColumnType("tinyint(1)"); + + b.Property("ModelId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("PropertyType") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("DeviceModelProperties"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTag", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Label") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Required") + .HasColumnType("tinyint(1)"); + + b.Property("Searchable") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("DeviceTags"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTagValue", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("DeviceId") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceId") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("DeviceId"); + + b.HasIndex("EdgeDeviceId"); + + b.ToTable("DeviceTagValues"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ConnectionState") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DeviceModelId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NbDevices") + .HasColumnType("int"); + + b.Property("NbModules") + .HasColumnType("int"); + + b.Property("Scope") + .HasColumnType("longtext"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DeviceModelId"); + + b.ToTable("EdgeDevices"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("EdgeDeviceModels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModelCommand", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceModelId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ModuleName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("EdgeDeviceModelCommands"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Label", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Color") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DeviceId") + .HasColumnType("varchar(255)"); + + b.Property("DeviceModelId") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceId") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceModelId") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("DeviceId"); + + b.HasIndex("DeviceModelId"); + + b.HasIndex("EdgeDeviceId"); + + b.HasIndex("EdgeDeviceModelId"); + + b.ToTable("Labels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LoRaDeviceTelemetry", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("EnqueuedTime") + .HasColumnType("datetime(6)"); + + b.Property("LorawanDeviceId") + .HasColumnType("varchar(255)"); + + b.Property("Telemetry") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("LorawanDeviceId"); + + b.ToTable("LoRaDeviceTelemetry"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b => + { + b.HasBaseType("AzureIoTHub.Portal.Domain.Entities.Device"); + + b.Property("ABPRelaxMode") + .HasColumnType("tinyint(1)"); + + b.Property("AlreadyLoggedInOnce") + .HasColumnType("tinyint(1)"); + + b.Property("AppEUI") + .HasColumnType("longtext"); + + b.Property("AppKey") + .HasColumnType("longtext"); + + b.Property("AppSKey") + .HasColumnType("longtext"); + + b.Property("ClassType") + .HasColumnType("int"); + + b.Property("DataRate") + .HasColumnType("longtext"); + + b.Property("Deduplication") + .HasColumnType("int"); + + b.Property("DevAddr") + .HasColumnType("longtext"); + + b.Property("Downlink") + .HasColumnType("tinyint(1)"); + + b.Property("FCntDownStart") + .HasColumnType("int"); + + b.Property("FCntResetCounter") + .HasColumnType("int"); + + b.Property("FCntUpStart") + .HasColumnType("int"); + + b.Property("GatewayID") + .HasColumnType("longtext"); + + b.Property("KeepAliveTimeout") + .HasColumnType("int"); + + b.Property("NbRep") + .HasColumnType("longtext"); + + b.Property("NwkSKey") + .HasColumnType("longtext"); + + b.Property("PreferredWindow") + .HasColumnType("int"); + + b.Property("RX1DROffset") + .HasColumnType("int"); + + b.Property("RX2DataRate") + .HasColumnType("int"); + + b.Property("RXDelay") + .HasColumnType("int"); + + b.Property("ReportedRX1DROffset") + .HasColumnType("longtext"); + + b.Property("ReportedRX2DataRate") + .HasColumnType("longtext"); + + b.Property("ReportedRXDelay") + .HasColumnType("longtext"); + + b.Property("SensorDecoder") + .HasColumnType("longtext"); + + b.Property("Supports32BitFCnt") + .HasColumnType("tinyint(1)"); + + b.Property("TxPower") + .HasColumnType("longtext"); + + b.Property("UseOTAA") + .HasColumnType("tinyint(1)"); + + b.ToTable("LorawanDevices", (string)null); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.DeviceModel", "DeviceModel") + .WithMany() + .HasForeignKey("DeviceModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DeviceModel"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTagValue", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null) + .WithMany("Tags") + .HasForeignKey("DeviceId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", null) + .WithMany("Tags") + .HasForeignKey("EdgeDeviceId"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", "DeviceModel") + .WithMany() + .HasForeignKey("DeviceModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DeviceModel"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Label", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null) + .WithMany("Labels") + .HasForeignKey("DeviceId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.DeviceModel", null) + .WithMany("Labels") + .HasForeignKey("DeviceModelId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", null) + .WithMany("Labels") + .HasForeignKey("EdgeDeviceId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", null) + .WithMany("Labels") + .HasForeignKey("EdgeDeviceModelId"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LoRaDeviceTelemetry", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", null) + .WithMany("Telemetry") + .HasForeignKey("LorawanDeviceId"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null) + .WithOne() + .HasForeignKey("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", "Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b => + { + b.Navigation("Labels"); + + b.Navigation("Tags"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModel", b => + { + b.Navigation("Labels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", b => + { + b.Navigation("Labels"); + + b.Navigation("Tags"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", b => + { + b.Navigation("Labels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b => + { + b.Navigation("Telemetry"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/AzureIoTHub.Portal.MySql/Migrations/20230127211555_InitDatabase.cs b/src/AzureIoTHub.Portal.MySql/Migrations/20230127211555_InitDatabase.cs new file mode 100644 index 000000000..b739f8dfd --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/Migrations/20230127211555_InitDatabase.cs @@ -0,0 +1,478 @@ +// 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 System; + using Microsoft.EntityFrameworkCore.Migrations; + + /// + public partial class InitDatabase : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + _ = migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "Concentrators", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + LoraRegion = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DeviceType = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ClientThumbprint = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + IsConnected = table.Column(type: "tinyint(1)", nullable: false), + IsEnabled = table.Column(type: "tinyint(1)", nullable: false), + Version = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + _ = table.PrimaryKey("PK_Concentrators", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "DeviceModelCommands", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Frame = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Confirmed = table.Column(type: "tinyint(1)", nullable: false), + Port = table.Column(type: "int", nullable: false), + IsBuiltin = table.Column(type: "tinyint(1)", nullable: false), + DeviceModelId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_DeviceModelCommands", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "DeviceModelProperties", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DisplayName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsWritable = table.Column(type: "tinyint(1)", nullable: false), + Order = table.Column(type: "int", nullable: false), + PropertyType = table.Column(type: "int", nullable: false), + ModelId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_DeviceModelProperties", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "DeviceModels", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + IsBuiltin = table.Column(type: "tinyint(1)", nullable: false), + SupportLoRaFeatures = table.Column(type: "tinyint(1)", nullable: false), + UseOTAA = table.Column(type: "tinyint(1)", nullable: true), + PreferredWindow = table.Column(type: "int", nullable: true), + Deduplication = table.Column(type: "int", nullable: true), + ClassType = table.Column(type: "int", nullable: false), + ABPRelaxMode = table.Column(type: "tinyint(1)", nullable: true), + Downlink = table.Column(type: "tinyint(1)", nullable: true), + KeepAliveTimeout = table.Column(type: "int", nullable: true), + RXDelay = table.Column(type: "int", nullable: true), + SensorDecoder = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + AppEUI = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_DeviceModels", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "DeviceTags", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Label = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Required = table.Column(type: "tinyint(1)", nullable: false), + Searchable = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + _ = table.PrimaryKey("PK_DeviceTags", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "EdgeDeviceModelCommands", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + EdgeDeviceModelId = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ModuleName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_EdgeDeviceModelCommands", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "EdgeDeviceModels", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_EdgeDeviceModels", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "Devices", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DeviceModelId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsConnected = table.Column(type: "tinyint(1)", nullable: false), + IsEnabled = table.Column(type: "tinyint(1)", nullable: false), + StatusUpdatedTime = table.Column(type: "datetime(6)", nullable: false), + Version = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + _ = table.PrimaryKey("PK_Devices", x => x.Id); + _ = table.ForeignKey( + name: "FK_Devices_DeviceModels_DeviceModelId", + column: x => x.DeviceModelId, + principalTable: "DeviceModels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "EdgeDevices", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DeviceModelId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Version = table.Column(type: "int", nullable: false), + ConnectionState = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + IsEnabled = table.Column(type: "tinyint(1)", nullable: false), + Scope = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + NbDevices = table.Column(type: "int", nullable: false), + NbModules = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + _ = table.PrimaryKey("PK_EdgeDevices", x => x.Id); + _ = table.ForeignKey( + name: "FK_EdgeDevices_EdgeDeviceModels_DeviceModelId", + column: x => x.DeviceModelId, + principalTable: "EdgeDeviceModels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "LorawanDevices", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + UseOTAA = table.Column(type: "tinyint(1)", nullable: false), + AppKey = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + AppEUI = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + AppSKey = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + NwkSKey = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + DevAddr = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + AlreadyLoggedInOnce = table.Column(type: "tinyint(1)", nullable: false), + DataRate = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + TxPower = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + NbRep = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ReportedRX2DataRate = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ReportedRX1DROffset = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ReportedRXDelay = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + GatewayID = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Downlink = table.Column(type: "tinyint(1)", nullable: true), + ClassType = table.Column(type: "int", nullable: false), + PreferredWindow = table.Column(type: "int", nullable: false), + Deduplication = table.Column(type: "int", nullable: false), + RX1DROffset = table.Column(type: "int", nullable: true), + RX2DataRate = table.Column(type: "int", nullable: true), + RXDelay = table.Column(type: "int", nullable: true), + ABPRelaxMode = table.Column(type: "tinyint(1)", nullable: true), + FCntUpStart = table.Column(type: "int", nullable: true), + FCntDownStart = table.Column(type: "int", nullable: true), + FCntResetCounter = table.Column(type: "int", nullable: true), + Supports32BitFCnt = table.Column(type: "tinyint(1)", nullable: true), + KeepAliveTimeout = table.Column(type: "int", nullable: true), + SensorDecoder = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_LorawanDevices", x => x.Id); + _ = table.ForeignKey( + name: "FK_LorawanDevices_Devices_Id", + column: x => x.Id, + principalTable: "Devices", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "DeviceTagValues", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Value = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DeviceId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + EdgeDeviceId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_DeviceTagValues", x => x.Id); + _ = table.ForeignKey( + name: "FK_DeviceTagValues_Devices_DeviceId", + column: x => x.DeviceId, + principalTable: "Devices", + principalColumn: "Id"); + _ = table.ForeignKey( + name: "FK_DeviceTagValues_EdgeDevices_EdgeDeviceId", + column: x => x.EdgeDeviceId, + principalTable: "EdgeDevices", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "Labels", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Name = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Color = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DeviceId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + DeviceModelId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + EdgeDeviceId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + EdgeDeviceModelId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_Labels", x => x.Id); + _ = table.ForeignKey( + name: "FK_Labels_DeviceModels_DeviceModelId", + column: x => x.DeviceModelId, + principalTable: "DeviceModels", + principalColumn: "Id"); + _ = table.ForeignKey( + name: "FK_Labels_Devices_DeviceId", + column: x => x.DeviceId, + principalTable: "Devices", + principalColumn: "Id"); + _ = table.ForeignKey( + name: "FK_Labels_EdgeDeviceModels_EdgeDeviceModelId", + column: x => x.EdgeDeviceModelId, + principalTable: "EdgeDeviceModels", + principalColumn: "Id"); + _ = table.ForeignKey( + name: "FK_Labels_EdgeDevices_EdgeDeviceId", + column: x => x.EdgeDeviceId, + principalTable: "EdgeDevices", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateTable( + name: "LoRaDeviceTelemetry", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + EnqueuedTime = table.Column(type: "datetime(6)", nullable: false), + Telemetry = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + LorawanDeviceId = table.Column(type: "varchar(255)", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + _ = table.PrimaryKey("PK_LoRaDeviceTelemetry", x => x.Id); + _ = table.ForeignKey( + name: "FK_LoRaDeviceTelemetry_LorawanDevices_LorawanDeviceId", + column: x => x.LorawanDeviceId, + principalTable: "LorawanDevices", + principalColumn: "Id"); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + _ = migrationBuilder.CreateIndex( + name: "IX_Devices_DeviceModelId", + table: "Devices", + column: "DeviceModelId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_DeviceTagValues_DeviceId", + table: "DeviceTagValues", + column: "DeviceId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_DeviceTagValues_EdgeDeviceId", + table: "DeviceTagValues", + column: "EdgeDeviceId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_EdgeDevices_DeviceModelId", + table: "EdgeDevices", + column: "DeviceModelId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_Labels_DeviceId", + table: "Labels", + column: "DeviceId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_Labels_DeviceModelId", + table: "Labels", + column: "DeviceModelId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_Labels_EdgeDeviceId", + table: "Labels", + column: "EdgeDeviceId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_Labels_EdgeDeviceModelId", + table: "Labels", + column: "EdgeDeviceModelId"); + + _ = migrationBuilder.CreateIndex( + name: "IX_LoRaDeviceTelemetry_LorawanDeviceId", + table: "LoRaDeviceTelemetry", + column: "LorawanDeviceId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + _ = migrationBuilder.DropTable( + name: "Concentrators"); + + _ = migrationBuilder.DropTable( + name: "DeviceModelCommands"); + + _ = migrationBuilder.DropTable( + name: "DeviceModelProperties"); + + _ = migrationBuilder.DropTable( + name: "DeviceTags"); + + _ = migrationBuilder.DropTable( + name: "DeviceTagValues"); + + _ = migrationBuilder.DropTable( + name: "EdgeDeviceModelCommands"); + + _ = migrationBuilder.DropTable( + name: "Labels"); + + _ = migrationBuilder.DropTable( + name: "LoRaDeviceTelemetry"); + + _ = migrationBuilder.DropTable( + name: "EdgeDevices"); + + _ = migrationBuilder.DropTable( + name: "LorawanDevices"); + + _ = migrationBuilder.DropTable( + name: "EdgeDeviceModels"); + + _ = migrationBuilder.DropTable( + name: "Devices"); + + _ = migrationBuilder.DropTable( + name: "DeviceModels"); + } + } +} diff --git a/src/AzureIoTHub.Portal.MySql/Migrations/PortalDbContextModelSnapshot.cs b/src/AzureIoTHub.Portal.MySql/Migrations/PortalDbContextModelSnapshot.cs new file mode 100644 index 000000000..dc3f31c7a --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/Migrations/PortalDbContextModelSnapshot.cs @@ -0,0 +1,581 @@ +// +using System; +using AzureIoTHub.Portal.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AzureIoTHub.Portal.MySql.Migrations +{ + [DbContext(typeof(PortalDbContext))] + partial class PortalDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.2") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Concentrator", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ClientThumbprint") + .HasColumnType("longtext"); + + b.Property("DeviceType") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsConnected") + .HasColumnType("tinyint(1)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LoraRegion") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Concentrators"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("DeviceModelId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("IsConnected") + .HasColumnType("tinyint(1)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("StatusUpdatedTime") + .HasColumnType("datetime(6)"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DeviceModelId"); + + b.ToTable("Devices", (string)null); + + b.UseTptMappingStrategy(); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModel", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ABPRelaxMode") + .HasColumnType("tinyint(1)"); + + b.Property("AppEUI") + .HasColumnType("longtext"); + + b.Property("ClassType") + .HasColumnType("int"); + + b.Property("Deduplication") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Downlink") + .HasColumnType("tinyint(1)"); + + b.Property("IsBuiltin") + .HasColumnType("tinyint(1)"); + + b.Property("KeepAliveTimeout") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PreferredWindow") + .HasColumnType("int"); + + b.Property("RXDelay") + .HasColumnType("int"); + + b.Property("SensorDecoder") + .HasColumnType("longtext"); + + b.Property("SupportLoRaFeatures") + .HasColumnType("tinyint(1)"); + + b.Property("UseOTAA") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("DeviceModels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModelCommand", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Confirmed") + .HasColumnType("tinyint(1)"); + + b.Property("DeviceModelId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Frame") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsBuiltin") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Port") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("DeviceModelCommands"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModelProperty", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IsWritable") + .HasColumnType("tinyint(1)"); + + b.Property("ModelId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Order") + .HasColumnType("int"); + + b.Property("PropertyType") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("DeviceModelProperties"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTag", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Label") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Required") + .HasColumnType("tinyint(1)"); + + b.Property("Searchable") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.ToTable("DeviceTags"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTagValue", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("DeviceId") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceId") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Value") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("DeviceId"); + + b.HasIndex("EdgeDeviceId"); + + b.ToTable("DeviceTagValues"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ConnectionState") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DeviceModelId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("IsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("NbDevices") + .HasColumnType("int"); + + b.Property("NbModules") + .HasColumnType("int"); + + b.Property("Scope") + .HasColumnType("longtext"); + + b.Property("Version") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DeviceModelId"); + + b.ToTable("EdgeDevices"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("EdgeDeviceModels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModelCommand", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceModelId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ModuleName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("EdgeDeviceModelCommands"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Label", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Color") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DeviceId") + .HasColumnType("varchar(255)"); + + b.Property("DeviceModelId") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceId") + .HasColumnType("varchar(255)"); + + b.Property("EdgeDeviceModelId") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("DeviceId"); + + b.HasIndex("DeviceModelId"); + + b.HasIndex("EdgeDeviceId"); + + b.HasIndex("EdgeDeviceModelId"); + + b.ToTable("Labels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LoRaDeviceTelemetry", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("EnqueuedTime") + .HasColumnType("datetime(6)"); + + b.Property("LorawanDeviceId") + .HasColumnType("varchar(255)"); + + b.Property("Telemetry") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("LorawanDeviceId"); + + b.ToTable("LoRaDeviceTelemetry"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b => + { + b.HasBaseType("AzureIoTHub.Portal.Domain.Entities.Device"); + + b.Property("ABPRelaxMode") + .HasColumnType("tinyint(1)"); + + b.Property("AlreadyLoggedInOnce") + .HasColumnType("tinyint(1)"); + + b.Property("AppEUI") + .HasColumnType("longtext"); + + b.Property("AppKey") + .HasColumnType("longtext"); + + b.Property("AppSKey") + .HasColumnType("longtext"); + + b.Property("ClassType") + .HasColumnType("int"); + + b.Property("DataRate") + .HasColumnType("longtext"); + + b.Property("Deduplication") + .HasColumnType("int"); + + b.Property("DevAddr") + .HasColumnType("longtext"); + + b.Property("Downlink") + .HasColumnType("tinyint(1)"); + + b.Property("FCntDownStart") + .HasColumnType("int"); + + b.Property("FCntResetCounter") + .HasColumnType("int"); + + b.Property("FCntUpStart") + .HasColumnType("int"); + + b.Property("GatewayID") + .HasColumnType("longtext"); + + b.Property("KeepAliveTimeout") + .HasColumnType("int"); + + b.Property("NbRep") + .HasColumnType("longtext"); + + b.Property("NwkSKey") + .HasColumnType("longtext"); + + b.Property("PreferredWindow") + .HasColumnType("int"); + + b.Property("RX1DROffset") + .HasColumnType("int"); + + b.Property("RX2DataRate") + .HasColumnType("int"); + + b.Property("RXDelay") + .HasColumnType("int"); + + b.Property("ReportedRX1DROffset") + .HasColumnType("longtext"); + + b.Property("ReportedRX2DataRate") + .HasColumnType("longtext"); + + b.Property("ReportedRXDelay") + .HasColumnType("longtext"); + + b.Property("SensorDecoder") + .HasColumnType("longtext"); + + b.Property("Supports32BitFCnt") + .HasColumnType("tinyint(1)"); + + b.Property("TxPower") + .HasColumnType("longtext"); + + b.Property("UseOTAA") + .HasColumnType("tinyint(1)"); + + b.ToTable("LorawanDevices", (string)null); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.DeviceModel", "DeviceModel") + .WithMany() + .HasForeignKey("DeviceModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DeviceModel"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceTagValue", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null) + .WithMany("Tags") + .HasForeignKey("DeviceId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", null) + .WithMany("Tags") + .HasForeignKey("EdgeDeviceId"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", "DeviceModel") + .WithMany() + .HasForeignKey("DeviceModelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DeviceModel"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Label", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null) + .WithMany("Labels") + .HasForeignKey("DeviceId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.DeviceModel", null) + .WithMany("Labels") + .HasForeignKey("DeviceModelId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", null) + .WithMany("Labels") + .HasForeignKey("EdgeDeviceId"); + + b.HasOne("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", null) + .WithMany("Labels") + .HasForeignKey("EdgeDeviceModelId"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LoRaDeviceTelemetry", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", null) + .WithMany("Telemetry") + .HasForeignKey("LorawanDeviceId"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b => + { + b.HasOne("AzureIoTHub.Portal.Domain.Entities.Device", null) + .WithOne() + .HasForeignKey("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", "Id") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.Device", b => + { + b.Navigation("Labels"); + + b.Navigation("Tags"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.DeviceModel", b => + { + b.Navigation("Labels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDevice", b => + { + b.Navigation("Labels"); + + b.Navigation("Tags"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.EdgeDeviceModel", b => + { + b.Navigation("Labels"); + }); + + modelBuilder.Entity("AzureIoTHub.Portal.Domain.Entities.LorawanDevice", b => + { + b.Navigation("Telemetry"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/AzureIoTHub.Portal.MySql/PortalDbContextFactory.cs b/src/AzureIoTHub.Portal.MySql/PortalDbContextFactory.cs new file mode 100644 index 000000000..a6ecea14c --- /dev/null +++ b/src/AzureIoTHub.Portal.MySql/PortalDbContextFactory.cs @@ -0,0 +1,23 @@ +// 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.MySql +{ + using AzureIoTHub.Portal.Infrastructure; + using AzureIoTHub.Portal.Infrastructure.Helpers; + using Microsoft.EntityFrameworkCore; + using Microsoft.EntityFrameworkCore.Design; + + public class PortalDbContextFactory : IDesignTimeDbContextFactory + { + public PortalDbContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder(); + + var connectionString = "server=localhost;database=cgigeiotdemo;user=root;password=pass"; + _ = optionsBuilder.UseMySql(connectionString, DatabaseHelper.GetMySqlServerVersion(connectionString), x => x.MigrationsAssembly("AzureIoTHub.Portal.MySql")); + + return new PortalDbContext(optionsBuilder.Options); + } + } +} diff --git a/src/AzureIoTHub.Portal.Postgres/AzureIoTHub.Portal.Postgres.csproj b/src/AzureIoTHub.Portal.Postgres/AzureIoTHub.Portal.Postgres.csproj new file mode 100644 index 000000000..56c13d2fb --- /dev/null +++ b/src/AzureIoTHub.Portal.Postgres/AzureIoTHub.Portal.Postgres.csproj @@ -0,0 +1,22 @@ + + + + net7.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/src/AzureIoTHub.Portal.Postgres/Migrations/20220903171411_Initial Create.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220903171411_Initial Create.Designer.cs new file mode 100644 index 000000000..67aa6bf55 --- /dev/null +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220903171411_Initial Create.Designer.cs @@ -0,0 +1,28 @@ +// +using AzureIoTHub.Portal.Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace AzureIoTHub.Portal.Postgres.Migrations +{ + [DbContext(typeof(PortalDbContext))] + [Migration("20220903171411_Initial Create")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/AzureIoTHub.Portal.Postgres/Migrations/20220903171411_Initial Create.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220903171411_Initial Create.cs new file mode 100644 index 000000000..99c0b1527 --- /dev/null +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220903171411_Initial Create.cs @@ -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.Postgres.Migrations +{ + using Microsoft.EntityFrameworkCore.Migrations; + + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220904153232_Add DeviceModelProperty support.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220904153232_Add DeviceModelProperty support.Designer.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220904153232_Add DeviceModelProperty support.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220904153232_Add DeviceModelProperty support.Designer.cs index 9819bdc97..9261e468a 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220904153232_Add DeviceModelProperty support.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220904153232_Add DeviceModelProperty support.Designer.cs @@ -1,11 +1,12 @@ // +using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220904153232_Add DeviceModelProperty support")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220904153232_Add DeviceModelProperty support.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220904153232_Add DeviceModelProperty support.cs similarity index 96% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220904153232_Add DeviceModelProperty support.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220904153232_Add DeviceModelProperty support.cs index c1871a884..9f92c6433 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220904153232_Add DeviceModelProperty support.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220904153232_Add DeviceModelProperty support.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs index 389820eec..2a2ab5493 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220910143007_Add Quartz .NET tables.Designer.cs @@ -1,4 +1,4 @@ -// +// using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -8,7 +8,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220910143007_Add Quartz .NET tables")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220910143007_Add Quartz .NET tables.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220910143007_Add Quartz .NET tables.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220910143007_Add Quartz .NET tables.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220910143007_Add Quartz .NET tables.cs index dd8d7ad63..07e4e2476 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220910143007_Add Quartz .NET tables.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220910143007_Add Quartz .NET tables.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911135612_Add DeviceTag.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911135612_Add DeviceTag.Designer.cs similarity index 96% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911135612_Add DeviceTag.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911135612_Add DeviceTag.Designer.cs index ce9d74c45..9d49eb066 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911135612_Add DeviceTag.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911135612_Add DeviceTag.Designer.cs @@ -1,4 +1,4 @@ -// +// using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -8,7 +8,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220911135612_Add DeviceTag")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911135612_Add DeviceTag.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911135612_Add DeviceTag.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911135612_Add DeviceTag.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911135612_Add DeviceTag.cs index 1219a391a..8bb5a7949 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911135612_Add DeviceTag.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911135612_Add DeviceTag.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs similarity index 97% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs index 5ca71cec6..47b299f49 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs @@ -1,4 +1,4 @@ -// +// using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -8,7 +8,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220911150200_Add DeviceModelCommand")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911150200_Add DeviceModelCommand.cs similarity index 96% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911150200_Add DeviceModelCommand.cs index 9ffe3abd0..0292ec1ff 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911150200_Add DeviceModelCommand.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911161906_Add DeviceModel.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911161906_Add DeviceModel.Designer.cs similarity index 97% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911161906_Add DeviceModel.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911161906_Add DeviceModel.Designer.cs index 79fc50599..7f8181f53 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911161906_Add DeviceModel.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911161906_Add DeviceModel.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220911161906_Add DeviceModel")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911161906_Add DeviceModel.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911161906_Add DeviceModel.cs similarity index 97% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911161906_Add DeviceModel.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911161906_Add DeviceModel.cs index ffd5c634b..fdee5c850 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911161906_Add DeviceModel.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911161906_Add DeviceModel.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911182352_Add EdgeDeviceModelCommand.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911182352_Add EdgeDeviceModelCommand.Designer.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911182352_Add EdgeDeviceModelCommand.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911182352_Add EdgeDeviceModelCommand.Designer.cs index 1547edc13..8dd66ac35 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911182352_Add EdgeDeviceModelCommand.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911182352_Add EdgeDeviceModelCommand.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220911182352_Add EdgeDeviceModelCommand")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911182352_Add EdgeDeviceModelCommand.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911182352_Add EdgeDeviceModelCommand.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911182352_Add EdgeDeviceModelCommand.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911182352_Add EdgeDeviceModelCommand.cs index c87f7e897..49d1d36a2 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911182352_Add EdgeDeviceModelCommand.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911182352_Add EdgeDeviceModelCommand.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; public partial class AddEdgeDeviceModelCommand : Migration diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911190829_Add EdgeDeviceModel.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911190829_Add EdgeDeviceModel.Designer.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911190829_Add EdgeDeviceModel.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911190829_Add EdgeDeviceModel.Designer.cs index 77a5efdaf..c1014546c 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911190829_Add EdgeDeviceModel.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911190829_Add EdgeDeviceModel.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220911190829_Add EdgeDeviceModel")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911190829_Add EdgeDeviceModel.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911190829_Add EdgeDeviceModel.cs similarity index 94% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911190829_Add EdgeDeviceModel.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220911190829_Add EdgeDeviceModel.cs index 4e63348c6..5c13e5221 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911190829_Add EdgeDeviceModel.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220911190829_Add EdgeDeviceModel.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; public partial class AddEdgeDeviceModel : Migration diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220915075056_Add Description Property on EdgeModel.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220915075056_Add Description Property on EdgeModel.Designer.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220915075056_Add Description Property on EdgeModel.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220915075056_Add Description Property on EdgeModel.Designer.cs index faba233ab..3a0c9bbf4 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220915075056_Add Description Property on EdgeModel.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220915075056_Add Description Property on EdgeModel.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220915075056_Add Description Property on EdgeModel")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220915075056_Add Description Property on EdgeModel.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220915075056_Add Description Property on EdgeModel.cs similarity index 93% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220915075056_Add Description Property on EdgeModel.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220915075056_Add Description Property on EdgeModel.cs index a10ac4101..6d21294e0 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220915075056_Add Description Property on EdgeModel.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220915075056_Add Description Property on EdgeModel.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.Designer.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.Designer.cs index 0161325e0..f5cb70c4d 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220921080852_Add ModuleName Property on EdgeDeviceModelCommand")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.cs similarity index 94% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.cs index 8d2041935..d565b9507 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220921080852_Add ModuleName Property on EdgeDeviceModelCommand.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; public partial class AddModuleNamePropertyonEdgeDeviceModelCommand : Migration diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220922124300_Add Device and LorawanDevice.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220922124300_Add Device and LorawanDevice.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220922124300_Add Device and LorawanDevice.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220922124300_Add Device and LorawanDevice.Designer.cs index b2db44d9c..115a95aed 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220922124300_Add Device and LorawanDevice.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220922124300_Add Device and LorawanDevice.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220922124300_Add Device and LorawanDevice")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220922124300_Add Device and LorawanDevice.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220922124300_Add Device and LorawanDevice.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220922124300_Add Device and LorawanDevice.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220922124300_Add Device and LorawanDevice.cs index b12375418..f33d0a3c7 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220922124300_Add Device and LorawanDevice.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220922124300_Add Device and LorawanDevice.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using System; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220927114351_Add support for ClassType in device model.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220927114351_Add support for ClassType in device model.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220927114351_Add support for ClassType in device model.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220927114351_Add support for ClassType in device model.Designer.cs index 209f723dc..69dbb8295 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220927114351_Add support for ClassType in device model.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220927114351_Add support for ClassType in device model.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220927114351_Add support for ClassType in device model")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220927114351_Add support for ClassType in device model.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220927114351_Add support for ClassType in device model.cs similarity index 94% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220927114351_Add support for ClassType in device model.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220927114351_Add support for ClassType in device model.cs index b0606425a..3b675c248 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220927114351_Add support for ClassType in device model.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220927114351_Add support for ClassType in device model.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using AzureIoTHub.Portal.Models.v10.LoRaWAN; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220929174657_Add DeviceTagValue.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220929174657_Add DeviceTagValue.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220929174657_Add DeviceTagValue.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220929174657_Add DeviceTagValue.Designer.cs index 7e266d273..65e18de9e 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220929174657_Add DeviceTagValue.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220929174657_Add DeviceTagValue.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20220929174657_Add DeviceTagValue")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220929174657_Add DeviceTagValue.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20220929174657_Add DeviceTagValue.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20220929174657_Add DeviceTagValue.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20220929174657_Add DeviceTagValue.cs index d08fdef88..8c97c2420 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20220929174657_Add DeviceTagValue.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20220929174657_Add DeviceTagValue.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221004121605_Add EdgeDevice.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221004121605_Add EdgeDevice.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221004121605_Add EdgeDevice.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221004121605_Add EdgeDevice.Designer.cs index 4f65ac584..bc4332ab3 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221004121605_Add EdgeDevice.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221004121605_Add EdgeDevice.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221004121605_Add EdgeDevice")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221004121605_Add EdgeDevice.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221004121605_Add EdgeDevice.cs similarity index 97% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221004121605_Add EdgeDevice.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221004121605_Add EdgeDevice.cs index 4c2117adf..c6016138b 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221004121605_Add EdgeDevice.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221004121605_Add EdgeDevice.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221005134349_Add Concentrator.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221005134349_Add Concentrator.Designer.cs index 72a712257..1c48b826b 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221005134349_Add Concentrator.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221005134349_Add Concentrator")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221005134349_Add Concentrator.cs similarity index 96% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221005134349_Add Concentrator.cs index 426cbddea..7f910548c 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221005134349_Add Concentrator.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221005134349_Add Concentrator.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221023142147_Make Edge Device Scope nullable.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221023142147_Make Edge Device Scope nullable.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221023142147_Make Edge Device Scope nullable.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221023142147_Make Edge Device Scope nullable.Designer.cs index 440dcdc42..d4a45e883 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221023142147_Make Edge Device Scope nullable.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221023142147_Make Edge Device Scope nullable.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221023142147_Make Edge Device Scope nullable")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221023142147_Make Edge Device Scope nullable.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221023142147_Make Edge Device Scope nullable.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221023142147_Make Edge Device Scope nullable.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221023142147_Make Edge Device Scope nullable.cs index 739f08235..f9a193cfa 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221023142147_Make Edge Device Scope nullable.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221023142147_Make Edge Device Scope nullable.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221027123259_Add LoRaWAN command names.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221027123259_Add LoRaWAN command names.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221027123259_Add LoRaWAN command names.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221027123259_Add LoRaWAN command names.Designer.cs index e2ec98ac4..a49f45e1c 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221027123259_Add LoRaWAN command names.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221027123259_Add LoRaWAN command names.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221027123259_Add LoRaWAN command names")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221027123259_Add LoRaWAN command names.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221027123259_Add LoRaWAN command names.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221027123259_Add LoRaWAN command names.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221027123259_Add LoRaWAN command names.cs index a38f62cbf..254df4607 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221027123259_Add LoRaWAN command names.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221027123259_Add LoRaWAN command names.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221028152842_Store edge device connection state.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221028152842_Store edge device connection state.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221028152842_Store edge device connection state.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221028152842_Store edge device connection state.Designer.cs index de4d0f86f..c8a9bf356 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221028152842_Store edge device connection state.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221028152842_Store edge device connection state.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221028152842_Store edge device connection state")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221028152842_Store edge device connection state.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221028152842_Store edge device connection state.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221028152842_Store edge device connection state.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221028152842_Store edge device connection state.cs index 98551339b..d32261744 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221028152842_Store edge device connection state.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221028152842_Store edge device connection state.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221115105521_Set ClientThumbprint as nullable.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221115105521_Set ClientThumbprint as nullable.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221115105521_Set ClientThumbprint as nullable.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221115105521_Set ClientThumbprint as nullable.Designer.cs index 0c5ddc8e8..96dc61f67 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221115105521_Set ClientThumbprint as nullable.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221115105521_Set ClientThumbprint as nullable.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221115105521_Set ClientThumbprint as nullable")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221115105521_Set ClientThumbprint as nullable.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221115105521_Set ClientThumbprint as nullable.cs similarity index 95% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221115105521_Set ClientThumbprint as nullable.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221115105521_Set ClientThumbprint as nullable.cs index 1c1fdee5c..12be85dc1 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221115105521_Set ClientThumbprint as nullable.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221115105521_Set ClientThumbprint as nullable.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221119214219_Add LoRaDeviceTelemetry.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221119214219_Add LoRaDeviceTelemetry.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221119214219_Add LoRaDeviceTelemetry.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221119214219_Add LoRaDeviceTelemetry.Designer.cs index 2fe2d283d..b0dae1d24 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221119214219_Add LoRaDeviceTelemetry.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221119214219_Add LoRaDeviceTelemetry.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221119214219_Add LoRaDeviceTelemetry")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221119214219_Add LoRaDeviceTelemetry.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221119214219_Add LoRaDeviceTelemetry.cs similarity index 96% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221119214219_Add LoRaDeviceTelemetry.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221119214219_Add LoRaDeviceTelemetry.cs index 68fe8c25a..41e38401d 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221119214219_Add LoRaDeviceTelemetry.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221119214219_Add LoRaDeviceTelemetry.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using System; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.Designer.cs index b022738d9..566cc75bf 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221128175823_Add DeviceModel FK on Device and LoRaDevice")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.cs similarity index 97% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.cs index 55d993e25..ec9ef2854 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128175823_Add DeviceModel FK on Device and LoRaDevice.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.Designer.cs index fbe662084..ede68fd98 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221128225921_Add EdgeDeviceModel FK On Edge Device")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.cs similarity index 96% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.cs index 15eb33073..7873722d0 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221128225921_Add EdgeDeviceModel FK On Edge Device.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221129203917_Add Label.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221129203917_Add Label.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221129203917_Add Label.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221129203917_Add Label.Designer.cs index ca2c0aeb5..093b89de9 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221129203917_Add Label.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221129203917_Add Label.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221129203917_Add Label")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221129203917_Add Label.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221129203917_Add Label.cs similarity index 98% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221129203917_Add Label.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221129203917_Add Label.cs index f9bc0f6db..2ddee5ae3 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221129203917_Add Label.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221129203917_Add Label.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221205101458_Introduce DeviceBase Entity.Designer.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221205101458_Introduce DeviceBase Entity.Designer.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221205101458_Introduce DeviceBase Entity.Designer.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221205101458_Introduce DeviceBase Entity.Designer.cs index f7ba148ae..e9adfb35f 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221205101458_Introduce DeviceBase Entity.Designer.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221205101458_Introduce DeviceBase Entity.Designer.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -9,7 +9,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] [Migration("20221205101458_Introduce DeviceBase Entity")] diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221205101458_Introduce DeviceBase Entity.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/20221205101458_Introduce DeviceBase Entity.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/20221205101458_Introduce DeviceBase Entity.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/20221205101458_Introduce DeviceBase Entity.cs index 2966ff5a9..b47a3cc4b 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/20221205101458_Introduce DeviceBase Entity.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/20221205101458_Introduce DeviceBase Entity.cs @@ -3,7 +3,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { using System; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs b/src/AzureIoTHub.Portal.Postgres/Migrations/PortalDbContextModelSnapshot.cs similarity index 99% rename from src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs rename to src/AzureIoTHub.Portal.Postgres/Migrations/PortalDbContextModelSnapshot.cs index f8169ce67..380de6799 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/Migrations/PortalDbContextModelSnapshot.cs +++ b/src/AzureIoTHub.Portal.Postgres/Migrations/PortalDbContextModelSnapshot.cs @@ -1,4 +1,4 @@ -// +// using System; using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; @@ -8,7 +8,7 @@ #nullable disable -namespace AzureIoTHub.Portal.Infrastructure.Migrations +namespace AzureIoTHub.Portal.Postgres.Migrations { [DbContext(typeof(PortalDbContext))] partial class PortalDbContextModelSnapshot : ModelSnapshot diff --git a/src/AzureIoTHub.Portal.Infrastructure/PortalDbContextFactory.cs b/src/AzureIoTHub.Portal.Postgres/PortalDbContextFactory.cs similarity index 60% rename from src/AzureIoTHub.Portal.Infrastructure/PortalDbContextFactory.cs rename to src/AzureIoTHub.Portal.Postgres/PortalDbContextFactory.cs index 479ff60df..ad8ca3903 100644 --- a/src/AzureIoTHub.Portal.Infrastructure/PortalDbContextFactory.cs +++ b/src/AzureIoTHub.Portal.Postgres/PortalDbContextFactory.cs @@ -1,8 +1,9 @@ // 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 +namespace AzureIoTHub.Portal.Postgres { + using AzureIoTHub.Portal.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; @@ -12,7 +13,8 @@ public PortalDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder(); - _ = optionsBuilder.UseNpgsql("Server=database;Database=cgigeiotdemo;Port=5432;User Id=postgres;Password=postgrePassword;Pooling=true;Connection Lifetime=0;Command Timeout=0;"); + var connectionString = "Server=database;Database=cgigeiotdemo;Port=5432;User Id=postgres;Password=postgrePassword;Pooling=true;Connection Lifetime=0;Command Timeout=0;"; + _ = optionsBuilder.UseNpgsql(connectionString, x => x.MigrationsAssembly("AzureIoTHub.Portal.Postgres")); return new PortalDbContext(optionsBuilder.Options); } diff --git a/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj b/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj index 8e681120a..a7ccd6dec 100644 --- a/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj +++ b/src/AzureIoTHub.Portal.Server/AzureIoTHub.Portal.Server.csproj @@ -27,6 +27,8 @@ + + diff --git a/src/AzureIoTHub.Portal.Server/Startup.cs b/src/AzureIoTHub.Portal.Server/Startup.cs index 4462a8def..c62e5a606 100644 --- a/src/AzureIoTHub.Portal.Server/Startup.cs +++ b/src/AzureIoTHub.Portal.Server/Startup.cs @@ -9,6 +9,7 @@ namespace AzureIoTHub.Portal.Server using AzureIoTHub.Portal.Application.Managers; using AzureIoTHub.Portal.Application.Services; using AzureIoTHub.Portal.Application.Startup; + using AzureIoTHub.Portal.Domain.Shared.Constants; using AzureIoTHub.Portal.Infrastructure.ServicesHealthCheck; using AzureIoTHub.Portal.Infrastructure.Startup; using Domain; @@ -39,6 +40,7 @@ namespace AzureIoTHub.Portal.Server using MudBlazor.Services; using Prometheus; using Quartz; + using Quartz.Impl.AdoJobStore.Common; using Services; using Shared.Models.v1._0; @@ -261,10 +263,39 @@ Specify the authorization token got from your IDP as a header. opts.UseClustering(); opts.UseProperties = true; - opts.UsePostgres(c => + switch (configuration.DbProvider) { - c.ConnectionString = configuration.PostgreSQLConnectionString; - }); + case DbProviders.PostgreSQL: + opts.UsePostgres(c => + { + c.ConnectionString = configuration.PostgreSQLConnectionString; + }); + break; + case DbProviders.MySQL: + DbProvider.RegisterDbMetadata("IotHubPortalQuartzMySqlConnector", new DbMetadata() + { + ProductName = "MySQL, MySqlConnector provider", + AssemblyName = "MySqlConnector", + ConnectionType = Type.GetType("MySqlConnector.MySqlConnection, MySqlConnector"), + CommandType = Type.GetType("MySqlConnector.MySqlCommand, MySqlConnector"), + ParameterType = Type.GetType("MySqlConnector.MySqlParameter, MySqlConnector"), + ParameterDbType = Type.GetType("MySqlConnector.MySqlDbType, MySqlConnector"), + ParameterDbTypePropertyName = "MySqlDbType", + ParameterNamePrefix = "?", + ExceptionType = Type.GetType("MySqlConnector.MySqlException, MySqlConnector"), + UseParameterNamePrefixInParameterCollection = true, + BindByName = true, + DbBinaryTypeName = "Blob" + }); + + opts.UseGenericDatabase("IotHubPortalQuartzMySqlConnector", c => + { + c.ConnectionString = configuration.MySQLConnectionString; + }); + break; + default: + break; + } }); }); diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs index 7f5509ea0..830c4c66e 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/DevelopmentConfigHandlerTests.cs @@ -5,6 +5,7 @@ namespace AzureIoTHub.Portal.Tests.Unit.Infrastructure { using System; using System.Globalization; + using AzureIoTHub.Portal.Domain.Shared.Constants; using AzureIoTHub.Portal.Infrastructure; using FluentAssertions; using Microsoft.Extensions.Configuration; @@ -46,6 +47,7 @@ private DevelopmentConfigHandler CreateDevelopmentConfigHandler() [TestCase(ConfigHandlerBase.DPSConnectionStringKey, nameof(ConfigHandlerBase.DPSConnectionString))] [TestCase(ConfigHandlerBase.StorageAccountConnectionStringKey, nameof(ConfigHandlerBase.StorageAccountConnectionString))] [TestCase(ConfigHandlerBase.PostgreSQLConnectionStringKey, nameof(ConfigHandlerBase.PostgreSQLConnectionString))] + [TestCase(ConfigHandlerBase.MySQLConnectionStringKey, nameof(ConfigHandlerBase.MySQLConnectionString))] public void SettingsShouldGetValueFromAppSettings(string configKey, string configPropertyName) { // Arrange @@ -258,5 +260,15 @@ public void IoTHubEventHubConsumerGroup_GetDefaultValue_ReturnsExpectedDefaultVa // Assert _ = developmentConfigHandler.IoTHubEventHubConsumerGroup.Should().Be("iothub-portal"); } + + [Test] + public void DbProviderKeyShouldBeExpectedDefaultValue() + { + // Arrange + var developmentConfigHandler = new DevelopmentConfigHandler(new ConfigurationManager()); + + // Assert + _ = developmentConfigHandler.DbProvider.Should().Be(DbProviders.PostgreSQL); + } } } diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/Helpers/DatabaseHelperTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/Helpers/DatabaseHelperTests.cs new file mode 100644 index 000000000..a6baa760a --- /dev/null +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/Helpers/DatabaseHelperTests.cs @@ -0,0 +1,28 @@ +// 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.Tests.Unit.Infrastructure.Helpers +{ + using System; + using AzureIoTHub.Portal.Infrastructure.Helpers; + using Microsoft.EntityFrameworkCore; + using NUnit.Framework; + + [TestFixture] + public class DatabaseHelperTests + { + [Test] + public void GetMySqlServerVersion_InvalidConnectionString_ReturnsDefaultMySqlServerVersion() + { + // Arrange + var expectedsqlserverversion = new MySqlServerVersion(new Version(8, 0, 32)); + var mysqlConnectionString = Guid.NewGuid().ToString(); + + // Act + var result = DatabaseHelper.GetMySqlServerVersion(mysqlConnectionString); + + // Assert + Assert.AreEqual(expectedsqlserverversion, result); + } + } +} diff --git a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs index 04374b179..49aeb9999 100644 --- a/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs +++ b/src/AzureIoTHub.Portal.Tests.Unit/Infrastructure/ProductionConfigHandlerTests.cs @@ -10,6 +10,7 @@ namespace AzureIoTHub.Portal.Tests.Unit.Infrastructure using Moq; using NUnit.Framework; using AzureIoTHub.Portal.Infrastructure; + using AzureIoTHub.Portal.Domain.Shared.Constants; [TestFixture] public class ProductionConfigHandlerTests @@ -36,6 +37,7 @@ private ProductionConfigHandler CreateProductionConfigHandler() [TestCase(ConfigHandlerBase.StorageAccountConnectionStringKey, nameof(ConfigHandlerBase.StorageAccountConnectionString))] [TestCase(ConfigHandlerBase.LoRaKeyManagementCodeKey, nameof(ConfigHandlerBase.LoRaKeyManagementCode))] [TestCase(ConfigHandlerBase.PostgreSQLConnectionStringKey, nameof(ConfigHandlerBase.PostgreSQLConnectionString))] + [TestCase(ConfigHandlerBase.MySQLConnectionStringKey, nameof(ConfigHandlerBase.MySQLConnectionString))] [TestCase(ConfigHandlerBase.IoTHubEventHubEndpointKey, nameof(ConfigHandlerBase.IoTHubEventHubEndpoint))] public void SecretsShouldGetValueFromConnectionStrings(string configKey, string configPropertyName) { @@ -273,5 +275,15 @@ public void IoTHubEventHubConsumerGroup_GetDefaultValue_ReturnsExpectedDefaultVa // Assert _ = productionConfigHandler.IoTHubEventHubConsumerGroup.Should().Be("iothub-portal"); } + + [Test] + public void DbProviderKeyShouldBeExpectedDefaultValue() + { + // Arrange + var productionConfigHandler = new ProductionConfigHandler(new ConfigurationManager()); + + // Assert + _ = productionConfigHandler.DbProvider.Should().Be(DbProviders.PostgreSQL); + } } } diff --git a/src/AzureIoTHub.Portal.sln b/src/AzureIoTHub.Portal.sln index c33ced6e4..e21414688 100644 --- a/src/AzureIoTHub.Portal.sln +++ b/src/AzureIoTHub.Portal.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.1.31911.260 @@ -69,6 +69,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureIoTHub.Portal.Applicat EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureIoTHub.Portal.Crosscutting", "AzureIoTHub.Portal.Crosscutting\AzureIoTHub.Portal.Crosscutting.csproj", "{3523EAFD-81F3-4FC3-BC49-65D3ECE94E4D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureIoTHub.Portal.MySql", "AzureIoTHub.Portal.MySql\AzureIoTHub.Portal.MySql.csproj", "{6F4A8F36-51C5-405C-B701-F3DC7A7B8436}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureIoTHub.Portal.Postgres", "AzureIoTHub.Portal.Postgres\AzureIoTHub.Portal.Postgres.csproj", "{3195668B-D3D9-4E5A-894C-A56C9F913E99}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -111,6 +115,14 @@ Global {3523EAFD-81F3-4FC3-BC49-65D3ECE94E4D}.Debug|Any CPU.Build.0 = Debug|Any CPU {3523EAFD-81F3-4FC3-BC49-65D3ECE94E4D}.Release|Any CPU.ActiveCfg = Release|Any CPU {3523EAFD-81F3-4FC3-BC49-65D3ECE94E4D}.Release|Any CPU.Build.0 = Release|Any CPU + {6F4A8F36-51C5-405C-B701-F3DC7A7B8436}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6F4A8F36-51C5-405C-B701-F3DC7A7B8436}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6F4A8F36-51C5-405C-B701-F3DC7A7B8436}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6F4A8F36-51C5-405C-B701-F3DC7A7B8436}.Release|Any CPU.Build.0 = Release|Any CPU + {3195668B-D3D9-4E5A-894C-A56C9F913E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3195668B-D3D9-4E5A-894C-A56C9F913E99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3195668B-D3D9-4E5A-894C-A56C9F913E99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3195668B-D3D9-4E5A-894C-A56C9F913E99}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 5126d7d6a..46a53eea5 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -10,6 +10,16 @@ services: - 5432:5432 volumes: - pgdata:/var/lib/postgresql/data + mysql: + image: mysql:8-debian + # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password + # (this is just an example, not intended to be a production configuration) + command: --default-authentication-plugin=mysql_native_password + environment: + MYSQL_ROOT_PASSWORD: pass + MYSQL_DATABASE: cgigeiotdemo + ports: + - 3306:3306 pgadmin: image: dpage/pgadmin4 environment: