From 47b5552dc6209d46d3fbf89857d18ac8491ee301 Mon Sep 17 00:00:00 2001 From: wzh425 Date: Fri, 6 Dec 2024 17:51:10 +0800 Subject: [PATCH] feat: Support PostgreSQL (#362) --- Directory.Build.props | 5 +- Masa.Alert.sln | 22 + .../AlertPostgreSqlDbContextFactory.cs | 20 + ...lert.EntityFrameworkCore.PostgreSql.csproj | 26 + .../20241206085425_InitialCreate.Designer.cs | 645 ++++++++++++++++++ .../20241206085425_InitialCreate.cs | 334 +++++++++ .../Migrations/AlertDbContextModelSnapshot.cs | 643 +++++++++++++++++ .../_Imports.cs | 4 + .../appsettings.PostgreSql.json | 5 + .../AlertSqlServerDbContextFactory.cs} | 13 +- ...Alert.EntityFrameworkCore.SqlServer.csproj | 25 + .../20221220025715_Init.Designer.cs | 0 .../Migrations/20221220025715_Init.cs | 0 ...0518034305_IntegrationEventLog.Designer.cs | 0 .../20230518034305_IntegrationEventLog.cs | 0 ...0912020558_20240913_sourceshow.Designer.cs | 0 .../20240912020558_20240913_sourceshow.cs | 0 .../Migrations/AlertDbContextModelSnapshot.cs | 0 .../_Imports.cs | 5 + .../appsettings.SqlServer.json | 5 + .../AlertDbContext.cs | 8 + .../Masa.Alert.EntityFrameworkCore.csproj | 5 - .../_Imports.cs | 3 +- .../MasaDbContextBuilderExtensions.cs | 23 + .../Internal/MasaStackConfigExtensions.cs | 14 + .../Masa.Alert.Service.Admin.csproj | 12 +- src/Services/Masa.Alert.Service/Program.cs | 4 +- .../Properties/launchSettings.json | 4 +- src/Services/Masa.Alert.Service/_Imports.cs | 5 +- .../appsettings.Development.json | 3 - 30 files changed, 1801 insertions(+), 32 deletions(-) create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/AlertPostgreSqlDbContextFactory.cs create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Masa.Alert.EntityFrameworkCore.PostgreSql.csproj create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.Designer.cs create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.cs create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/AlertDbContextModelSnapshot.cs create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/_Imports.cs create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/appsettings.PostgreSql.json rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore/AlertDbContextFactory.cs => Masa.Alert.EntityFrameworkCore.SqlServer/AlertSqlServerDbContextFactory.cs} (62%) create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Masa.Alert.EntityFrameworkCore.SqlServer.csproj rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/20221220025715_Init.Designer.cs (100%) rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/20221220025715_Init.cs (100%) rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/20230518034305_IntegrationEventLog.Designer.cs (100%) rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/20230518034305_IntegrationEventLog.cs (100%) rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/20240912020558_20240913_sourceshow.Designer.cs (100%) rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/20240912020558_20240913_sourceshow.cs (100%) rename src/Infrastructure/{Masa.Alert.EntityFrameworkCore => Masa.Alert.EntityFrameworkCore.SqlServer}/Migrations/AlertDbContextModelSnapshot.cs (100%) create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/_Imports.cs create mode 100644 src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/appsettings.SqlServer.json create mode 100644 src/Services/Masa.Alert.Service/Internal/MasaDbContextBuilderExtensions.cs create mode 100644 src/Services/Masa.Alert.Service/Internal/MasaStackConfigExtensions.cs diff --git a/Directory.Build.props b/Directory.Build.props index a01ad887..a333c18f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,7 @@ - 1.2.0-preview.2 - 1.2.1-preview.4 + 1.2.0-preview.5 + 1.2.1-preview.8 + 6.0.8 diff --git a/Masa.Alert.sln b/Masa.Alert.sln index 503eba1f..69def93a 100644 --- a/Masa.Alert.sln +++ b/Masa.Alert.sln @@ -70,6 +70,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Alert.NotificationServ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Alert.Infrastructure.Constants", "src\Infrastructure\Masa.Alert.Infrastructure.Constants\Masa.Alert.Infrastructure.Constants.csproj", "{AFF871EB-653E-460D-9A64-C1944E8F76B3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Alert.EntityFrameworkCore.SqlServer", "src\Infrastructure\Masa.Alert.EntityFrameworkCore.SqlServer\Masa.Alert.EntityFrameworkCore.SqlServer.csproj", "{4557C624-8748-44FC-9795-7E0A9E7E4CF7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Alert.EntityFrameworkCore.PostgreSql", "src\Infrastructure\Masa.Alert.EntityFrameworkCore.PostgreSql\Masa.Alert.EntityFrameworkCore.PostgreSql.csproj", "{27A5AB4D-4447-47B0-9A44-E6511F58AA68}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -222,6 +226,22 @@ Global {AFF871EB-653E-460D-9A64-C1944E8F76B3}.Release|Any CPU.Build.0 = Release|Any CPU {AFF871EB-653E-460D-9A64-C1944E8F76B3}.Release|x86.ActiveCfg = Release|Any CPU {AFF871EB-653E-460D-9A64-C1944E8F76B3}.Release|x86.Build.0 = Release|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Debug|x86.ActiveCfg = Debug|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Debug|x86.Build.0 = Debug|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Release|Any CPU.Build.0 = Release|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Release|x86.ActiveCfg = Release|Any CPU + {4557C624-8748-44FC-9795-7E0A9E7E4CF7}.Release|x86.Build.0 = Release|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Debug|Any CPU.Build.0 = Debug|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Debug|x86.ActiveCfg = Debug|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Debug|x86.Build.0 = Debug|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Release|Any CPU.ActiveCfg = Release|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Release|Any CPU.Build.0 = Release|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Release|x86.ActiveCfg = Release|Any CPU + {27A5AB4D-4447-47B0-9A44-E6511F58AA68}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -252,6 +272,8 @@ Global {45550B8B-17A9-45D5-BA03-F2C9905E353D} = {BE3519B8-A573-4C5D-B48C-1FA3CE1E4473} {603BEBB8-1563-4286-9CF1-73BC07749AD9} = {4660010F-BB9B-4C8E-B4F7-34AF77080EA0} {AFF871EB-653E-460D-9A64-C1944E8F76B3} = {4660010F-BB9B-4C8E-B4F7-34AF77080EA0} + {4557C624-8748-44FC-9795-7E0A9E7E4CF7} = {4660010F-BB9B-4C8E-B4F7-34AF77080EA0} + {27A5AB4D-4447-47B0-9A44-E6511F58AA68} = {4660010F-BB9B-4C8E-B4F7-34AF77080EA0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B83BA2BA-19E5-41FB-A92A-16A03DA229E4} diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/AlertPostgreSqlDbContextFactory.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/AlertPostgreSqlDbContextFactory.cs new file mode 100644 index 00000000..320bb1e6 --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/AlertPostgreSqlDbContextFactory.cs @@ -0,0 +1,20 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Alert.EntityFrameworkCore; + +public class AlertPostgreSqlDbContextFactory : IDesignTimeDbContextFactory +{ + public AlertDbContext CreateDbContext(string[] args) + { + AlertDbContext.RegisterAssembly(typeof(AlertPostgreSqlDbContextFactory).Assembly); + var optionsBuilder = new MasaDbContextOptionsBuilder(); + var configurationBuilder = new ConfigurationBuilder(); + var configuration = configurationBuilder + .AddJsonFile("appsettings.PostgreSql.json") + .Build(); + optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection")!, b => b.MigrationsAssembly("Masa.Alert.EntityFrameworkCore.PostgreSql")); + + return new AlertDbContext(optionsBuilder.MasaOptions); + } +} diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Masa.Alert.EntityFrameworkCore.PostgreSql.csproj b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Masa.Alert.EntityFrameworkCore.PostgreSql.csproj new file mode 100644 index 00000000..35df1965 --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Masa.Alert.EntityFrameworkCore.PostgreSql.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + PreserveNewest + + + + diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.Designer.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.Designer.cs new file mode 100644 index 00000000..367f062d --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.Designer.cs @@ -0,0 +1,645 @@ +// +using System; +using Masa.Alert.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Masa.Alert.EntityFrameworkCore.PostgreSql.Migrations +{ + [DbContext(typeof(AlertDbContext))] + [Migration("20241206085425_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.12") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AlarmCount") + .HasColumnType("integer"); + + b.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b.Property("AlertSeverity") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Duration") + .HasColumnType("bigint"); + + b.Property("FirstAlarmTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsNotification") + .HasColumnType("boolean"); + + b.Property("LastAlarmTime") + .HasColumnType("timestamp with time zone"); + + b.Property("LastNotificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("RecoveryTime") + .HasColumnType("timestamp with time zone"); + + b.Property("RuleResultItems") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AlarmHistorys", "alert"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AppIdentity") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ChartYAxisUnit") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ContinuousTriggerThreshold") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("IsGetTotal") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("ProjectIdentity") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("SchedulerJobId") + .HasColumnType("uuid"); + + b.Property("Show") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("Source") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasDefaultValue(""); + + b.Property("TotalVariable") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("WhereExpression") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AlarmRules", "alert"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRuleRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AggregateResult") + .IsRequired() + .HasColumnType("text"); + + b.Property("AlarmHistoryId") + .HasColumnType("uuid"); + + b.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b.Property("ConsecutiveCount") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("ExcuteTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsTrigger") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("RuleResultItems") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AlarmRuleRecords", "alert"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.WebHooks.Aggregates.WebHook", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("SecretKey") + .IsRequired() + .HasColumnType("text"); + + b.Property("Url") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("WebHooks", "alert"); + }); + + modelBuilder.Entity("Masa.BuildingBlocks.Dispatcher.IntegrationEvents.Logs.IntegrationEventLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("EventId") + .HasColumnType("uuid"); + + b.Property("EventTypeName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ExpandContent") + .IsRequired() + .HasColumnType("text"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .HasMaxLength(36) + .HasColumnType("character varying(36)") + .HasColumnName("RowVersion"); + + b.Property("State") + .HasColumnType("integer"); + + b.Property("TimesSent") + .HasColumnType("integer"); + + b.Property("TransactionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "EventId", "RowVersion" }, "IX_EventId_Version"); + + b.HasIndex(new[] { "State", "ModificationTime" }, "IX_State_MTime"); + + b.HasIndex(new[] { "State", "TimesSent", "ModificationTime" }, "IX_State_TimesSent_MTime"); + + b.ToTable("IntegrationEventLog", (string)null); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHistory", b => + { + b.OwnsOne("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHandle", "Handle", b1 => + { + b1.Property("AlarmHistoryId") + .HasColumnType("uuid"); + + b1.Property("Handler") + .HasColumnType("uuid") + .HasColumnName("Handler"); + + b1.Property("IsHandleNotice") + .HasColumnType("boolean") + .HasColumnName("IsHandleNotice"); + + b1.Property("NotificationConfig") + .IsRequired() + .HasColumnType("text") + .HasColumnName("HandleNotificationConfig"); + + b1.Property("Status") + .HasColumnType("integer") + .HasColumnName("HandleStatus"); + + b1.Property("WebHookId") + .HasColumnType("uuid") + .HasColumnName("WebHookId"); + + b1.HasKey("AlarmHistoryId"); + + b1.ToTable("AlarmHistorys", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmHistoryId"); + }); + + b.OwnsMany("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHandleStatusCommit", "HandleStatusCommits", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AlarmHistoryId") + .HasColumnType("uuid"); + + b1.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b1.Property("Remarks") + .IsRequired() + .HasColumnType("text"); + + b1.Property("Status") + .HasColumnType("integer"); + + b1.Property("UserId") + .HasColumnType("uuid"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmHistoryId"); + + b1.ToTable("AlarmHandleStatusCommits", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmHistoryId"); + }); + + b.Navigation("Handle") + .IsRequired(); + + b.Navigation("HandleStatusCommits"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRule", b => + { + b.OwnsMany("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRuleItem", "Items", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("AlertSeverity") + .HasColumnType("integer"); + + b1.Property("Expression") + .IsRequired() + .HasColumnType("text"); + + b1.Property("IsNotification") + .HasColumnType("boolean"); + + b1.Property("IsRecoveryNotification") + .HasColumnType("boolean"); + + b1.Property("NotificationConfig") + .IsRequired() + .HasColumnType("text"); + + b1.Property("RecoveryNotificationConfig") + .IsRequired() + .HasColumnType("text"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmRuleId"); + + b1.ToTable("AlarmRuleItems", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + }); + + b.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.CheckFrequency", "CheckFrequency", b1 => + { + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("CronExpression") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)") + .HasColumnName("CheckFrequencyCron"); + + b1.Property("Type") + .HasColumnType("integer") + .HasColumnName("CheckFrequencyType"); + + b1.HasKey("AlarmRuleId"); + + b1.ToTable("AlarmRules", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + + b1.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.TimeInterval", "FixedInterval", b2 => + { + b2.Property("CheckFrequencyAlarmRuleId") + .HasColumnType("uuid"); + + b2.Property("IntervalTime") + .HasColumnType("integer") + .HasColumnName("CheckFrequencyIntervalTime"); + + b2.Property("IntervalTimeType") + .HasColumnType("integer") + .HasColumnName("CheckFrequencyIntervalTimeType"); + + b2.HasKey("CheckFrequencyAlarmRuleId"); + + b2.ToTable("AlarmRules", "alert"); + + b2.WithOwner() + .HasForeignKey("CheckFrequencyAlarmRuleId"); + }); + + b1.Navigation("FixedInterval") + .IsRequired(); + }); + + b.OwnsMany("Masa.Alert.Domain.AlarmRules.Aggregates.LogMonitorItem", "LogMonitorItems", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AggregationType") + .HasColumnType("integer"); + + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("Alias") + .IsRequired() + .HasColumnType("text"); + + b1.Property("Field") + .IsRequired() + .HasColumnType("text"); + + b1.Property("IsOffset") + .HasColumnType("boolean"); + + b1.Property("OffsetPeriod") + .HasColumnType("integer"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmRuleId"); + + b1.ToTable("AlarmRuleLogMonitors", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + }); + + b.OwnsMany("Masa.Alert.Domain.AlarmRules.Aggregates.MetricMonitorItem", "MetricMonitorItems", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("Alias") + .IsRequired() + .HasColumnType("text"); + + b1.Property("Expression") + .IsRequired() + .HasColumnType("text"); + + b1.Property("IsExpression") + .HasColumnType("boolean"); + + b1.Property("IsOffset") + .HasColumnType("boolean"); + + b1.Property("OffsetPeriod") + .HasColumnType("integer"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmRuleId"); + + b1.ToTable("AlarmRuleMetricMonitors", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + + b1.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.MetricAggregation", "Aggregation", b2 => + { + b2.Property("MetricMonitorItemId") + .HasColumnType("uuid"); + + b2.Property("AggregationType") + .HasColumnType("integer") + .HasColumnName("AggregationType"); + + b2.Property("ComparisonOperator") + .HasColumnType("integer") + .HasColumnName("ComparisonOperator"); + + b2.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Name"); + + b2.Property("Tag") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Tag"); + + b2.Property("Value") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Value"); + + b2.HasKey("MetricMonitorItemId"); + + b2.ToTable("AlarmRuleMetricMonitors", "alert"); + + b2.WithOwner() + .HasForeignKey("MetricMonitorItemId"); + }); + + b1.Navigation("Aggregation") + .IsRequired(); + }); + + b.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.SilenceCycle", "SilenceCycle", b1 => + { + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("SilenceCycleValue") + .HasColumnType("integer") + .HasColumnName("SilenceCycleValue"); + + b1.Property("Type") + .HasColumnType("integer") + .HasColumnName("SilenceCycleType"); + + b1.HasKey("AlarmRuleId"); + + b1.ToTable("AlarmRules", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + + b1.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.TimeInterval", "TimeInterval", b2 => + { + b2.Property("SilenceCycleAlarmRuleId") + .HasColumnType("uuid"); + + b2.Property("IntervalTime") + .HasColumnType("integer") + .HasColumnName("SilenceCycleIntervalTime"); + + b2.Property("IntervalTimeType") + .HasColumnType("integer") + .HasColumnName("SilenceCycleIntervalTimeType"); + + b2.HasKey("SilenceCycleAlarmRuleId"); + + b2.ToTable("AlarmRules", "alert"); + + b2.WithOwner() + .HasForeignKey("SilenceCycleAlarmRuleId"); + }); + + b1.Navigation("TimeInterval") + .IsRequired(); + }); + + b.Navigation("CheckFrequency") + .IsRequired(); + + b.Navigation("Items"); + + b.Navigation("LogMonitorItems"); + + b.Navigation("MetricMonitorItems"); + + b.Navigation("SilenceCycle") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.cs new file mode 100644 index 00000000..f91d3139 --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/20241206085425_InitialCreate.cs @@ -0,0 +1,334 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Masa.Alert.EntityFrameworkCore.PostgreSql.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "alert"); + + migrationBuilder.CreateTable( + name: "AlarmHistorys", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + AlarmRuleId = table.Column(type: "uuid", nullable: false), + AlertSeverity = table.Column(type: "integer", nullable: false), + FirstAlarmTime = table.Column(type: "timestamp with time zone", nullable: false), + AlarmCount = table.Column(type: "integer", nullable: false), + LastAlarmTime = table.Column(type: "timestamp with time zone", nullable: false), + RecoveryTime = table.Column(type: "timestamp with time zone", nullable: true), + LastNotificationTime = table.Column(type: "timestamp with time zone", nullable: true), + Duration = table.Column(type: "bigint", nullable: false), + IsNotification = table.Column(type: "boolean", nullable: false), + RuleResultItems = table.Column(type: "text", nullable: false), + Handler = table.Column(type: "uuid", nullable: false), + WebHookId = table.Column(type: "uuid", nullable: false), + HandleStatus = table.Column(type: "integer", nullable: false), + IsHandleNotice = table.Column(type: "boolean", nullable: false), + HandleNotificationConfig = table.Column(type: "text", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmHistorys", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AlarmRuleRecords", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + AlarmRuleId = table.Column(type: "uuid", nullable: false), + AlarmHistoryId = table.Column(type: "uuid", nullable: false), + AggregateResult = table.Column(type: "text", nullable: false), + IsTrigger = table.Column(type: "boolean", nullable: false), + ConsecutiveCount = table.Column(type: "integer", nullable: false), + ExcuteTime = table.Column(type: "timestamp with time zone", nullable: false), + RuleResultItems = table.Column(type: "text", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmRuleRecords", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AlarmRules", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DisplayName = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + Type = table.Column(type: "integer", nullable: false), + ProjectIdentity = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + AppIdentity = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + IsEnabled = table.Column(type: "boolean", nullable: false), + ChartYAxisUnit = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + CheckFrequencyType = table.Column(type: "integer", nullable: false), + CheckFrequencyIntervalTime = table.Column(type: "integer", nullable: false), + CheckFrequencyIntervalTimeType = table.Column(type: "integer", nullable: false), + CheckFrequencyCron = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), + IsGetTotal = table.Column(type: "boolean", nullable: false), + TotalVariable = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), + WhereExpression = table.Column(type: "text", nullable: false), + ContinuousTriggerThreshold = table.Column(type: "integer", nullable: false), + SilenceCycleType = table.Column(type: "integer", nullable: false), + SilenceCycleIntervalTime = table.Column(type: "integer", nullable: false), + SilenceCycleIntervalTimeType = table.Column(type: "integer", nullable: false), + SilenceCycleValue = table.Column(type: "integer", nullable: false), + SchedulerJobId = table.Column(type: "uuid", nullable: false), + Source = table.Column(type: "character varying(40)", maxLength: 40, nullable: false, defaultValue: ""), + Show = table.Column(type: "boolean", nullable: false, defaultValue: true), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmRules", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "IntegrationEventLog", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + EventId = table.Column(type: "uuid", nullable: false), + EventTypeName = table.Column(type: "text", nullable: false), + State = table.Column(type: "integer", nullable: false), + TimesSent = table.Column(type: "integer", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + Content = table.Column(type: "text", nullable: false), + ExpandContent = table.Column(type: "text", nullable: false), + TransactionId = table.Column(type: "uuid", nullable: false), + RowVersion = table.Column(type: "character varying(36)", maxLength: 36, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IntegrationEventLog", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "WebHooks", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + DisplayName = table.Column(type: "text", nullable: false), + Url = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + SecretKey = table.Column(type: "text", nullable: false), + Creator = table.Column(type: "uuid", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + Modifier = table.Column(type: "uuid", nullable: false), + ModificationTime = table.Column(type: "timestamp with time zone", nullable: false), + IsDeleted = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_WebHooks", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AlarmHandleStatusCommits", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Status = table.Column(type: "integer", nullable: false), + CreationTime = table.Column(type: "timestamp with time zone", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), + Remarks = table.Column(type: "text", nullable: false), + AlarmHistoryId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmHandleStatusCommits", x => x.Id); + table.ForeignKey( + name: "FK_AlarmHandleStatusCommits_AlarmHistorys_AlarmHistoryId", + column: x => x.AlarmHistoryId, + principalSchema: "alert", + principalTable: "AlarmHistorys", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AlarmRuleItems", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + AlarmRuleId = table.Column(type: "uuid", nullable: false), + Expression = table.Column(type: "text", nullable: false), + AlertSeverity = table.Column(type: "integer", nullable: false), + IsRecoveryNotification = table.Column(type: "boolean", nullable: false), + IsNotification = table.Column(type: "boolean", nullable: false), + RecoveryNotificationConfig = table.Column(type: "text", nullable: false), + NotificationConfig = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmRuleItems", x => x.Id); + table.ForeignKey( + name: "FK_AlarmRuleItems_AlarmRules_AlarmRuleId", + column: x => x.AlarmRuleId, + principalSchema: "alert", + principalTable: "AlarmRules", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AlarmRuleLogMonitors", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Field = table.Column(type: "text", nullable: false), + AggregationType = table.Column(type: "integer", nullable: false), + Alias = table.Column(type: "text", nullable: false), + IsOffset = table.Column(type: "boolean", nullable: false), + OffsetPeriod = table.Column(type: "integer", nullable: false), + AlarmRuleId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmRuleLogMonitors", x => x.Id); + table.ForeignKey( + name: "FK_AlarmRuleLogMonitors_AlarmRules_AlarmRuleId", + column: x => x.AlarmRuleId, + principalSchema: "alert", + principalTable: "AlarmRules", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AlarmRuleMetricMonitors", + schema: "alert", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + IsExpression = table.Column(type: "boolean", nullable: false), + Expression = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Tag = table.Column(type: "text", nullable: false), + ComparisonOperator = table.Column(type: "integer", nullable: false), + Value = table.Column(type: "text", nullable: false), + AggregationType = table.Column(type: "integer", nullable: false), + Alias = table.Column(type: "text", nullable: false), + IsOffset = table.Column(type: "boolean", nullable: false), + OffsetPeriod = table.Column(type: "integer", nullable: false), + AlarmRuleId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AlarmRuleMetricMonitors", x => x.Id); + table.ForeignKey( + name: "FK_AlarmRuleMetricMonitors_AlarmRules_AlarmRuleId", + column: x => x.AlarmRuleId, + principalSchema: "alert", + principalTable: "AlarmRules", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AlarmHandleStatusCommits_AlarmHistoryId", + schema: "alert", + table: "AlarmHandleStatusCommits", + column: "AlarmHistoryId"); + + migrationBuilder.CreateIndex( + name: "IX_AlarmRuleItems_AlarmRuleId", + schema: "alert", + table: "AlarmRuleItems", + column: "AlarmRuleId"); + + migrationBuilder.CreateIndex( + name: "IX_AlarmRuleLogMonitors_AlarmRuleId", + schema: "alert", + table: "AlarmRuleLogMonitors", + column: "AlarmRuleId"); + + migrationBuilder.CreateIndex( + name: "IX_AlarmRuleMetricMonitors_AlarmRuleId", + schema: "alert", + table: "AlarmRuleMetricMonitors", + column: "AlarmRuleId"); + + migrationBuilder.CreateIndex( + name: "IX_EventId_Version", + table: "IntegrationEventLog", + columns: new[] { "EventId", "RowVersion" }); + + migrationBuilder.CreateIndex( + name: "IX_State_MTime", + table: "IntegrationEventLog", + columns: new[] { "State", "ModificationTime" }); + + migrationBuilder.CreateIndex( + name: "IX_State_TimesSent_MTime", + table: "IntegrationEventLog", + columns: new[] { "State", "TimesSent", "ModificationTime" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AlarmHandleStatusCommits", + schema: "alert"); + + migrationBuilder.DropTable( + name: "AlarmRuleItems", + schema: "alert"); + + migrationBuilder.DropTable( + name: "AlarmRuleLogMonitors", + schema: "alert"); + + migrationBuilder.DropTable( + name: "AlarmRuleMetricMonitors", + schema: "alert"); + + migrationBuilder.DropTable( + name: "AlarmRuleRecords", + schema: "alert"); + + migrationBuilder.DropTable( + name: "IntegrationEventLog"); + + migrationBuilder.DropTable( + name: "WebHooks", + schema: "alert"); + + migrationBuilder.DropTable( + name: "AlarmHistorys", + schema: "alert"); + + migrationBuilder.DropTable( + name: "AlarmRules", + schema: "alert"); + } + } +} diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/AlertDbContextModelSnapshot.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/AlertDbContextModelSnapshot.cs new file mode 100644 index 00000000..482506b7 --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/Migrations/AlertDbContextModelSnapshot.cs @@ -0,0 +1,643 @@ +// +using System; +using Masa.Alert.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Masa.Alert.EntityFrameworkCore.PostgreSql.Migrations +{ + [DbContext(typeof(AlertDbContext))] + partial class AlertDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.12") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHistory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AlarmCount") + .HasColumnType("integer"); + + b.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b.Property("AlertSeverity") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Duration") + .HasColumnType("bigint"); + + b.Property("FirstAlarmTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsNotification") + .HasColumnType("boolean"); + + b.Property("LastAlarmTime") + .HasColumnType("timestamp with time zone"); + + b.Property("LastNotificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("RecoveryTime") + .HasColumnType("timestamp with time zone"); + + b.Property("RuleResultItems") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AlarmHistorys", "alert"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AppIdentity") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ChartYAxisUnit") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ContinuousTriggerThreshold") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("IsGetTotal") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("ProjectIdentity") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("SchedulerJobId") + .HasColumnType("uuid"); + + b.Property("Show") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("Source") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasDefaultValue(""); + + b.Property("TotalVariable") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Type") + .HasColumnType("integer"); + + b.Property("WhereExpression") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AlarmRules", "alert"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRuleRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AggregateResult") + .IsRequired() + .HasColumnType("text"); + + b.Property("AlarmHistoryId") + .HasColumnType("uuid"); + + b.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b.Property("ConsecutiveCount") + .HasColumnType("integer"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("ExcuteTime") + .HasColumnType("timestamp with time zone"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("IsTrigger") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("RuleResultItems") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("AlarmRuleRecords", "alert"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.WebHooks.Aggregates.WebHook", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Creator") + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("DisplayName") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsDeleted") + .HasColumnType("boolean"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Modifier") + .HasColumnType("uuid"); + + b.Property("SecretKey") + .IsRequired() + .HasColumnType("text"); + + b.Property("Url") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("WebHooks", "alert"); + }); + + modelBuilder.Entity("Masa.BuildingBlocks.Dispatcher.IntegrationEvents.Logs.IntegrationEventLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("EventId") + .HasColumnType("uuid"); + + b.Property("EventTypeName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ExpandContent") + .IsRequired() + .HasColumnType("text"); + + b.Property("ModificationTime") + .HasColumnType("timestamp with time zone"); + + b.Property("RowVersion") + .IsConcurrencyToken() + .IsRequired() + .HasMaxLength(36) + .HasColumnType("character varying(36)") + .HasColumnName("RowVersion"); + + b.Property("State") + .HasColumnType("integer"); + + b.Property("TimesSent") + .HasColumnType("integer"); + + b.Property("TransactionId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "EventId", "RowVersion" }, "IX_EventId_Version"); + + b.HasIndex(new[] { "State", "ModificationTime" }, "IX_State_MTime"); + + b.HasIndex(new[] { "State", "TimesSent", "ModificationTime" }, "IX_State_TimesSent_MTime"); + + b.ToTable("IntegrationEventLog", (string)null); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHistory", b => + { + b.OwnsOne("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHandle", "Handle", b1 => + { + b1.Property("AlarmHistoryId") + .HasColumnType("uuid"); + + b1.Property("Handler") + .HasColumnType("uuid") + .HasColumnName("Handler"); + + b1.Property("IsHandleNotice") + .HasColumnType("boolean") + .HasColumnName("IsHandleNotice"); + + b1.Property("NotificationConfig") + .IsRequired() + .HasColumnType("text") + .HasColumnName("HandleNotificationConfig"); + + b1.Property("Status") + .HasColumnType("integer") + .HasColumnName("HandleStatus"); + + b1.Property("WebHookId") + .HasColumnType("uuid") + .HasColumnName("WebHookId"); + + b1.HasKey("AlarmHistoryId"); + + b1.ToTable("AlarmHistorys", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmHistoryId"); + }); + + b.OwnsMany("Masa.Alert.Domain.AlarmHistories.Aggregates.AlarmHandleStatusCommit", "HandleStatusCommits", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AlarmHistoryId") + .HasColumnType("uuid"); + + b1.Property("CreationTime") + .HasColumnType("timestamp with time zone"); + + b1.Property("Remarks") + .IsRequired() + .HasColumnType("text"); + + b1.Property("Status") + .HasColumnType("integer"); + + b1.Property("UserId") + .HasColumnType("uuid"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmHistoryId"); + + b1.ToTable("AlarmHandleStatusCommits", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmHistoryId"); + }); + + b.Navigation("Handle") + .IsRequired(); + + b.Navigation("HandleStatusCommits"); + }); + + modelBuilder.Entity("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRule", b => + { + b.OwnsMany("Masa.Alert.Domain.AlarmRules.Aggregates.AlarmRuleItem", "Items", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("AlertSeverity") + .HasColumnType("integer"); + + b1.Property("Expression") + .IsRequired() + .HasColumnType("text"); + + b1.Property("IsNotification") + .HasColumnType("boolean"); + + b1.Property("IsRecoveryNotification") + .HasColumnType("boolean"); + + b1.Property("NotificationConfig") + .IsRequired() + .HasColumnType("text"); + + b1.Property("RecoveryNotificationConfig") + .IsRequired() + .HasColumnType("text"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmRuleId"); + + b1.ToTable("AlarmRuleItems", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + }); + + b.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.CheckFrequency", "CheckFrequency", b1 => + { + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("CronExpression") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)") + .HasColumnName("CheckFrequencyCron"); + + b1.Property("Type") + .HasColumnType("integer") + .HasColumnName("CheckFrequencyType"); + + b1.HasKey("AlarmRuleId"); + + b1.ToTable("AlarmRules", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + + b1.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.TimeInterval", "FixedInterval", b2 => + { + b2.Property("CheckFrequencyAlarmRuleId") + .HasColumnType("uuid"); + + b2.Property("IntervalTime") + .HasColumnType("integer") + .HasColumnName("CheckFrequencyIntervalTime"); + + b2.Property("IntervalTimeType") + .HasColumnType("integer") + .HasColumnName("CheckFrequencyIntervalTimeType"); + + b2.HasKey("CheckFrequencyAlarmRuleId"); + + b2.ToTable("AlarmRules", "alert"); + + b2.WithOwner() + .HasForeignKey("CheckFrequencyAlarmRuleId"); + }); + + b1.Navigation("FixedInterval") + .IsRequired(); + }); + + b.OwnsMany("Masa.Alert.Domain.AlarmRules.Aggregates.LogMonitorItem", "LogMonitorItems", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AggregationType") + .HasColumnType("integer"); + + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("Alias") + .IsRequired() + .HasColumnType("text"); + + b1.Property("Field") + .IsRequired() + .HasColumnType("text"); + + b1.Property("IsOffset") + .HasColumnType("boolean"); + + b1.Property("OffsetPeriod") + .HasColumnType("integer"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmRuleId"); + + b1.ToTable("AlarmRuleLogMonitors", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + }); + + b.OwnsMany("Masa.Alert.Domain.AlarmRules.Aggregates.MetricMonitorItem", "MetricMonitorItems", b1 => + { + b1.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("Alias") + .IsRequired() + .HasColumnType("text"); + + b1.Property("Expression") + .IsRequired() + .HasColumnType("text"); + + b1.Property("IsExpression") + .HasColumnType("boolean"); + + b1.Property("IsOffset") + .HasColumnType("boolean"); + + b1.Property("OffsetPeriod") + .HasColumnType("integer"); + + b1.HasKey("Id"); + + b1.HasIndex("AlarmRuleId"); + + b1.ToTable("AlarmRuleMetricMonitors", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + + b1.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.MetricAggregation", "Aggregation", b2 => + { + b2.Property("MetricMonitorItemId") + .HasColumnType("uuid"); + + b2.Property("AggregationType") + .HasColumnType("integer") + .HasColumnName("AggregationType"); + + b2.Property("ComparisonOperator") + .HasColumnType("integer") + .HasColumnName("ComparisonOperator"); + + b2.Property("Name") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Name"); + + b2.Property("Tag") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Tag"); + + b2.Property("Value") + .IsRequired() + .HasColumnType("text") + .HasColumnName("Value"); + + b2.HasKey("MetricMonitorItemId"); + + b2.ToTable("AlarmRuleMetricMonitors", "alert"); + + b2.WithOwner() + .HasForeignKey("MetricMonitorItemId"); + }); + + b1.Navigation("Aggregation") + .IsRequired(); + }); + + b.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.SilenceCycle", "SilenceCycle", b1 => + { + b1.Property("AlarmRuleId") + .HasColumnType("uuid"); + + b1.Property("SilenceCycleValue") + .HasColumnType("integer") + .HasColumnName("SilenceCycleValue"); + + b1.Property("Type") + .HasColumnType("integer") + .HasColumnName("SilenceCycleType"); + + b1.HasKey("AlarmRuleId"); + + b1.ToTable("AlarmRules", "alert"); + + b1.WithOwner() + .HasForeignKey("AlarmRuleId"); + + b1.OwnsOne("Masa.Alert.Domain.AlarmRules.Aggregates.TimeInterval", "TimeInterval", b2 => + { + b2.Property("SilenceCycleAlarmRuleId") + .HasColumnType("uuid"); + + b2.Property("IntervalTime") + .HasColumnType("integer") + .HasColumnName("SilenceCycleIntervalTime"); + + b2.Property("IntervalTimeType") + .HasColumnType("integer") + .HasColumnName("SilenceCycleIntervalTimeType"); + + b2.HasKey("SilenceCycleAlarmRuleId"); + + b2.ToTable("AlarmRules", "alert"); + + b2.WithOwner() + .HasForeignKey("SilenceCycleAlarmRuleId"); + }); + + b1.Navigation("TimeInterval") + .IsRequired(); + }); + + b.Navigation("CheckFrequency") + .IsRequired(); + + b.Navigation("Items"); + + b.Navigation("LogMonitorItems"); + + b.Navigation("MetricMonitorItems"); + + b.Navigation("SilenceCycle") + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/_Imports.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/_Imports.cs new file mode 100644 index 00000000..17d1c01f --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/_Imports.cs @@ -0,0 +1,4 @@ +global using Microsoft.EntityFrameworkCore; +global using Microsoft.EntityFrameworkCore.Design; +global using Microsoft.Extensions.Configuration; +global using Masa.Alert.EntityFrameworkCore; \ No newline at end of file diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/appsettings.PostgreSql.json b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/appsettings.PostgreSql.json new file mode 100644 index 00000000..2c4670b6 --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.PostgreSql/appsettings.PostgreSql.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=10.130.0.19;Port=3815;User Id=ss;Password=Lsd@2023;Database=alert_dev;" + } +} \ No newline at end of file diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContextFactory.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/AlertSqlServerDbContextFactory.cs similarity index 62% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContextFactory.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/AlertSqlServerDbContextFactory.cs index c09dfb30..4322d2f0 100644 --- a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContextFactory.cs +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/AlertSqlServerDbContextFactory.cs @@ -3,20 +3,17 @@ namespace Masa.Alert.EntityFrameworkCore; -public class AlertDbContextFactory : IDesignTimeDbContextFactory +public class AlertSqlServerDbContextFactory : IDesignTimeDbContextFactory { public AlertDbContext CreateDbContext(string[] args) { - var optionsBuilder = new MasaDbContextOptionsBuilder() - { - }; - + AlertDbContext.RegisterAssembly(typeof(AlertSqlServerDbContextFactory).Assembly); + var optionsBuilder = new MasaDbContextOptionsBuilder(); var configurationBuilder = new ConfigurationBuilder(); var configuration = configurationBuilder - .AddJsonFile("appsettings.json") - .AddJsonFile("appsettings.Development.json") + .AddJsonFile("appsettings.SqlServer.json") .Build(); - optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection")); + optionsBuilder.UseSqlServer(configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Masa.Alert.EntityFrameworkCore.SqlServer")); return new AlertDbContext(optionsBuilder.MasaOptions); } diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Masa.Alert.EntityFrameworkCore.SqlServer.csproj b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Masa.Alert.EntityFrameworkCore.SqlServer.csproj new file mode 100644 index 00000000..f312e34c --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Masa.Alert.EntityFrameworkCore.SqlServer.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + PreserveNewest + + + + diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20221220025715_Init.Designer.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20221220025715_Init.Designer.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20221220025715_Init.Designer.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20221220025715_Init.Designer.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20221220025715_Init.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20221220025715_Init.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20221220025715_Init.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20221220025715_Init.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20230518034305_IntegrationEventLog.Designer.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20230518034305_IntegrationEventLog.Designer.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20230518034305_IntegrationEventLog.Designer.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20230518034305_IntegrationEventLog.Designer.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20230518034305_IntegrationEventLog.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20230518034305_IntegrationEventLog.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20230518034305_IntegrationEventLog.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20230518034305_IntegrationEventLog.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20240912020558_20240913_sourceshow.Designer.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20240912020558_20240913_sourceshow.Designer.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20240912020558_20240913_sourceshow.Designer.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20240912020558_20240913_sourceshow.Designer.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20240912020558_20240913_sourceshow.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20240912020558_20240913_sourceshow.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/20240912020558_20240913_sourceshow.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/20240912020558_20240913_sourceshow.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/AlertDbContextModelSnapshot.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/AlertDbContextModelSnapshot.cs similarity index 100% rename from src/Infrastructure/Masa.Alert.EntityFrameworkCore/Migrations/AlertDbContextModelSnapshot.cs rename to src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/Migrations/AlertDbContextModelSnapshot.cs diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/_Imports.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/_Imports.cs new file mode 100644 index 00000000..73439b1b --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/_Imports.cs @@ -0,0 +1,5 @@ +global using Microsoft.EntityFrameworkCore; +global using Microsoft.EntityFrameworkCore.Metadata.Builders; +global using Masa.BuildingBlocks.Data.Contracts; +global using Microsoft.EntityFrameworkCore.Design; +global using Microsoft.Extensions.Configuration; \ No newline at end of file diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/appsettings.SqlServer.json b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/appsettings.SqlServer.json new file mode 100644 index 00000000..9dc4db49 --- /dev/null +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore.SqlServer/appsettings.SqlServer.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=10.130.0.19,2415;Database=alert_dev;User Id=ss;Password=Hzss@123;" + } +} \ No newline at end of file diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContext.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContext.cs index 969f60ec..d39a087f 100644 --- a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContext.cs +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore/AlertDbContext.cs @@ -2,6 +2,8 @@ public class AlertDbContext : MasaDbContext { + internal static Assembly Assembly = typeof(AlertDbContext).Assembly; + public AlertDbContext(MasaDbContextOptions options) : base(options) { base.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll; @@ -11,6 +13,7 @@ protected override void OnModelCreatingExecuting(ModelBuilder builder) { builder.ApplyConfigurationsFromAssembly(GetType().Assembly); builder.ApplyConfigurationsFromAssembly(typeof(Masa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCore.IntegrationEventLogModelCreatingProvider).Assembly); + builder.ApplyConfigurationsFromAssembly(Assembly); base.OnModelCreatingExecuting(builder); } @@ -21,4 +24,9 @@ protected override void OnConfiguring(MasaDbContextOptionsBuilder optionsBuilder .EnableSensitiveDataLogging() .EnableDetailedErrors(); } + + public static void RegisterAssembly(Assembly assembly) + { + Assembly = assembly; + } } diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Masa.Alert.EntityFrameworkCore.csproj b/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Masa.Alert.EntityFrameworkCore.csproj index d215735a..b66ba90b 100644 --- a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Masa.Alert.EntityFrameworkCore.csproj +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore/Masa.Alert.EntityFrameworkCore.csproj @@ -12,11 +12,6 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/_Imports.cs b/src/Infrastructure/Masa.Alert.EntityFrameworkCore/_Imports.cs index 85a16d9b..5a13a640 100644 --- a/src/Infrastructure/Masa.Alert.EntityFrameworkCore/_Imports.cs +++ b/src/Infrastructure/Masa.Alert.EntityFrameworkCore/_Imports.cs @@ -21,4 +21,5 @@ global using Microsoft.EntityFrameworkCore.Metadata.Builders; global using Microsoft.Extensions.Logging; global using Microsoft.EntityFrameworkCore.Design; -global using Microsoft.Extensions.Configuration; \ No newline at end of file +global using Microsoft.Extensions.Configuration; +global using System.Reflection; \ No newline at end of file diff --git a/src/Services/Masa.Alert.Service/Internal/MasaDbContextBuilderExtensions.cs b/src/Services/Masa.Alert.Service/Internal/MasaDbContextBuilderExtensions.cs new file mode 100644 index 00000000..86d9009a --- /dev/null +++ b/src/Services/Masa.Alert.Service/Internal/MasaDbContextBuilderExtensions.cs @@ -0,0 +1,23 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Alert.Service.Admin.Infrastructure.Extensions; + +public static class MasaDbContextBuilderExtensions +{ + public static MasaDbContextBuilder UseDbSql(this MasaDbContextBuilder builder, string dbType) + { + switch (dbType) + { + case "PostgreSql": + AlertDbContext.RegisterAssembly(typeof(AlertPostgreSqlDbContextFactory).Assembly); + builder.UseNpgsql(b => b.MigrationsAssembly("Masa.Alert.EntityFrameworkCore.PostgreSql")); + break; + default: + AlertDbContext.RegisterAssembly(typeof(AlertSqlServerDbContextFactory).Assembly); + builder.UseSqlServer(b => b.MigrationsAssembly("Masa.Alert.EntityFrameworkCore.SqlServer")); + break; + } + return builder; + } +} diff --git a/src/Services/Masa.Alert.Service/Internal/MasaStackConfigExtensions.cs b/src/Services/Masa.Alert.Service/Internal/MasaStackConfigExtensions.cs new file mode 100644 index 00000000..c1548606 --- /dev/null +++ b/src/Services/Masa.Alert.Service/Internal/MasaStackConfigExtensions.cs @@ -0,0 +1,14 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the Apache License. See LICENSE.txt in the project root for license information. + +namespace Masa.Alert.Service.Admin.Infrastructure.Extensions; + +public static class MasaStackConfigExtensions +{ + public static string GetDbType(this IMasaStackConfig masaStackConfig) + { + var connStr = masaStackConfig.GetValue(MasaStackConfigConstant.CONNECTIONSTRING); + var dbModel = JsonSerializer.Deserialize(connStr); + return dbModel?.DbType ?? string.Empty; + } +} diff --git a/src/Services/Masa.Alert.Service/Masa.Alert.Service.Admin.csproj b/src/Services/Masa.Alert.Service/Masa.Alert.Service.Admin.csproj index 50d36cbf..e5fa4021 100644 --- a/src/Services/Masa.Alert.Service/Masa.Alert.Service.Admin.csproj +++ b/src/Services/Masa.Alert.Service/Masa.Alert.Service.Admin.csproj @@ -19,7 +19,6 @@ - @@ -39,19 +38,16 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - + + diff --git a/src/Services/Masa.Alert.Service/Program.cs b/src/Services/Masa.Alert.Service/Program.cs index 6cb7a608..208c364d 100644 --- a/src/Services/Masa.Alert.Service/Program.cs +++ b/src/Services/Masa.Alert.Service/Program.cs @@ -132,12 +132,12 @@ .AddValidatorsFromAssemblies(assemblies) .AddMasaDbContext(builder => { - builder.UseSqlServer(); + builder.UseDbSql(masaStackConfig.GetDbType()); builder.UseFilter(options => options.EnableSoftDelete = true); }) .AddMasaDbContext(builder => { - builder.UseSqlServer(); + builder.UseDbSql(masaStackConfig.GetDbType()); builder.UseFilter(options => options.EnableSoftDelete = true); }) .AddScoped() diff --git a/src/Services/Masa.Alert.Service/Properties/launchSettings.json b/src/Services/Masa.Alert.Service/Properties/launchSettings.json index 3812a813..7e681c57 100644 --- a/src/Services/Masa.Alert.Service/Properties/launchSettings.json +++ b/src/Services/Masa.Alert.Service/Properties/launchSettings.json @@ -15,7 +15,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DAPR_GRPC_PORT": "3601", - "DAPR_HTTP_PORT": "3600", + "DAPR_HTTP_PORT": "3600", "MASA_CLUSTER": "Default", "DCC_SECRET": "masastack.com", "ADMIN_PWD": "admin123", @@ -27,7 +27,7 @@ "OTLP_URL": "http://otel-collector.masastack:9013", "ELASTIC": "{\"Nodes\": [\"http://es-ydy-new.lonsid.cn:9200\"],\"Index\": \"auth_user_development\"}", "REDIS": "{\"RedisHost\": \"10.130.0.19\", \"RedisPort\": 2135, \"RedisDb\": 3,\"RedisPassword\": \"Hzss@123\"}", - "CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 2415,\"Database\":\"\",\"UserId\": \"ss\",\"Password\":\"Hzss@123\"}", + "CONNECTIONSTRING": "{\"Server\": \"10.130.0.19\", \"Port\": 3815,\"Database\":\"pm-dev\",\"UserId\": \"ss\",\"Password\":\"Lsd@2023\",\"DbType\":\"PostgreSql\"}", "MASA_STACK": "[{\"id\":\"pm\",\"service\":{\"id\":\"pm-service-dev\",\"domain\":\"http://pm-service-dev.masastack.com\"},\"web\":{\"id\":\"pm-web-dev\",\"domain\":\"https://pm-dev.masastack.com\"}},{\"id\":\"dcc\",\"service\":{\"id\":\"dcc-service-dev\",\"domain\":\"http://dcc-service-dev.masastack.com\"},\"web\":{\"id\":\"dcc-web-dev\",\"domain\":\"https://dcc-dev.masastack.com\"}},{\"id\":\"tsc\",\"service\":{\"id\":\"tsc-service-dev\",\"domain\":\"http://tsc-service-dev.masastack.com\"},\"web\":{\"id\":\"tsc-web-dev\",\"domain\":\"https://tsc-dev.masastack.com\"}},{\"id\":\"alert\",\"service\":{\"id\":\"alert-service-dev\",\"domain\":\"http://alert-service-dev.masastack.com\"},\"web\":{\"id\":\"alert-web-dev\",\"domain\":\"https://alert-dev.masastack.com\"}},{\"id\":\"scheduler\",\"service\":{\"id\":\"scheduler-service-dev\",\"domain\":\"http://scheduler-service-dev.masastack.com\"},\"worker\":{\"id\":\"scheduler-worker-dev\",\"domain\":\"http://scheduler-worker-dev.masastack.com\"},\"web\":{\"id\":\"scheduler-web-dev\",\"domain\":\"https://scheduler-dev.masastack.com\"}},{\"id\":\"mc\",\"service\":{\"id\":\"mc-service-dev\",\"domain\":\"http://mc-service-dev.masastack.com\"},\"web\":{\"id\":\"mc-web-dev\",\"domain\":\"https://mc-dev.masastack.com\"}},{\"id\":\"auth\",\"service\":{\"id\":\"auth-service-dev\",\"domain\":\"http://auth-service-dev.masastack.com\"},\"web\":{\"id\":\"auth-web-dev\",\"domain\":\"https://auth-dev.masastack.com\"},\"sso\":{\"id\":\"auth-sso-dev\",\"domain\":\"https://auth-sso-dev.masastack.com\"}}]", "MASA_ENVIRONMENT": "Development", "SUFFIX_IDENTITY": "dev" diff --git a/src/Services/Masa.Alert.Service/_Imports.cs b/src/Services/Masa.Alert.Service/_Imports.cs index 93e1b55d..cb7c1784 100644 --- a/src/Services/Masa.Alert.Service/_Imports.cs +++ b/src/Services/Masa.Alert.Service/_Imports.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License. See LICENSE.txt in the project root for license information. global using System.Diagnostics; -global using System.Linq; +global using System.Text.Json; global using System.Text.RegularExpressions; global using FluentValidation; global using Mapster; @@ -19,6 +19,7 @@ global using Masa.Alert.Application.WebHooks.Queries; global using Masa.Alert.Domain.NotificationService; global using Masa.Alert.EntityFrameworkCore; +global using Masa.Alert.Service.Admin.Infrastructure.Extensions; global using Masa.Alert.Infrastructure.Common.Extensions; global using Masa.Alert.Infrastructure.Ddd.Application.Contracts.Dtos; global using Masa.Alert.Infrastructure.Middleware; @@ -31,7 +32,9 @@ global using Masa.BuildingBlocks.Extensions.BackgroundJobs; global using Masa.BuildingBlocks.RulesEngine; global using Masa.BuildingBlocks.StackSdks.Auth.Contracts; +global using Masa.BuildingBlocks.StackSdks.Config; global using Masa.BuildingBlocks.StackSdks.Config.Consts; +global using Masa.BuildingBlocks.StackSdks.Config.Models; global using Masa.Contrib.Caching.Distributed.StackExchangeRedis; global using Masa.Contrib.Configuration.ConfigurationApi.Dcc; global using Masa.Contrib.Dispatcher.IntegrationEvents.EventLogs.EFCore; diff --git a/src/Services/Masa.Alert.Service/appsettings.Development.json b/src/Services/Masa.Alert.Service/appsettings.Development.json index 393bc747..8b3c036a 100644 --- a/src/Services/Masa.Alert.Service/appsettings.Development.json +++ b/src/Services/Masa.Alert.Service/appsettings.Development.json @@ -1,7 +1,4 @@ { - "ConnectionStrings": { - "DefaultConnection": "Server=10.130.0.19,2415;Database=alert_dev;User Id=ss;Password=Hzss@123;" - }, "Logging": { "LogLevel": { "Default": "Error"