提交 9350745e 编写于 作者: 麦壳饼's avatar 麦壳饼

针对sqlserver测试完成

上级 fed32198
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="5.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.SqlServer.Storage" Version="5.0.1" />
<PackageReference Include="EFCore.Sharding.SqlServer" Version="5.0.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>

using EFCore.Sharding;
using IoTSharp.Data;
using IoTSharp.Data.SqlServer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Microsoft.Extensions.DependencyInjection
{
public static class IoTSharpDataBuilderExtensions
{
public static void ConfigureSqlServer(this IServiceCollection services, string connectionString, int poolSize, IHealthChecksBuilder checksBuilder, HealthChecksUIBuilder healthChecksUI)
{
services.AddEntityFrameworkSqlServer();
services.AddSingleton<IDataBaseModelBuilderOptions>( c=> new MsSqlModelBuilderOptions());
services.AddDbContextPool<ApplicationDbContext>(builder =>
{
builder.UseSqlServer(connectionString, s => s.MigrationsAssembly("IoTSharp.Data.SqlServer"));
builder.UseInternalServiceProvider(services.BuildServiceProvider());
}
, poolSize);
checksBuilder.AddSqlServer(connectionString);
healthChecksUI.AddSqlServerStorage(connectionString);
}
public static void UseSqlServerToSharding(this IShardingBuilder builder, string connectionString, ExpandByDateMode expandBy)
{
builder.AddDataSource(connectionString, ReadWriteType.Read | ReadWriteType.Write, DatabaseType.SqlServer);
builder.SetDateSharding<TelemetryData>(nameof(TelemetryData.DateTime), expandBy, DateTime.Now);
}
}
}
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
namespace IoTSharp.Data.SqlServer
{
public class MsSqlModelBuilderOptions : IDataBaseModelBuilderOptions
{
public MsSqlModelBuilderOptions()
{
}
public IInfrastructure<IServiceProvider> Infrastructure { get; set; }
public void OnModelCreating(ModelBuilder modelBuilder)
{
//modelBuilder.Entity<TelemetryData>()
//.Property(b => b.DateTime)
//.HasColumnType("timestamp with time zone");
//modelBuilder.Entity<TelemetryData>()
//.Property(b => b.Value_DateTime)
//.HasColumnType("timestamp with time zone");
//modelBuilder.Entity<TelemetryLatest>()
//.Property(b => b.DateTime)
//.HasColumnType("timestamp with time zone");
//modelBuilder.Entity<TelemetryLatest>()
//.Property(b => b.Value_DateTime)
//.HasColumnType("timestamp with time zone");
//modelBuilder.Entity<AttributeLatest>()
//.Property(b => b.DateTime)
//.HasColumnType("timestamp with time zone");
//modelBuilder.Entity<AttributeLatest>()
//.Property(b => b.Value_DateTime)
//.HasColumnType("timestamp with time zone");
//modelBuilder.Entity<TelemetryData>()
//.Property(b => b.Value_Json)
//.HasColumnType("jsonb");
//modelBuilder.Entity<TelemetryData>()
//.Property(b => b.Value_XML)
//.HasColumnType("xml");
//modelBuilder.Entity<AttributeLatest>()
//.Property(b => b.Value_Json)
//.HasColumnType("jsonb");
//modelBuilder.Entity<AttributeLatest>()
//.Property(b => b.Value_XML)
//.HasColumnType("xml");
//modelBuilder.Entity<TelemetryLatest>()
//.Property(b => b.Value_Json)
//.HasColumnType("jsonb");
//modelBuilder.Entity<TelemetryLatest>()
//.Property(b => b.Value_XML)
//.HasColumnType("xml");
//modelBuilder.Entity<AuditLog>()
//.Property(b => b.ActionData)
//.HasColumnType("jsonb");
//modelBuilder.Entity<AuditLog>()
//.Property(b => b.ActionResult)
//.HasColumnType("jsonb");
}
}
}
\ No newline at end of file
......@@ -47,7 +47,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.PostgreSQL",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data", "IoTSharp.Data\IoTSharp.Data.csproj", "{522B2676-EB0E-4191-ACBC-EDC86DD2351D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data.MySQL", "IoTSharp.Data.MySQL\IoTSharp.Data.MySQL.csproj", "{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.MySQL", "IoTSharp.Data.MySQL\IoTSharp.Data.MySQL.csproj", "{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data.SqlServer", "IoTSharp.Data.SqlServer\IoTSharp.Data.SqlServer.csproj", "{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -298,6 +300,26 @@ Global
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x64.Build.0 = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x86.ActiveCfg = Release|Any CPU
{233F2C8D-DD4C-49B7-99A2-F3DB5620DEFB}.Release|x86.Build.0 = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM.ActiveCfg = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM.Build.0 = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|ARM64.Build.0 = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x64.ActiveCfg = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x64.Build.0 = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x86.ActiveCfg = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Debug|x86.Build.0 = Debug|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|Any CPU.Build.0 = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM.ActiveCfg = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM.Build.0 = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM64.ActiveCfg = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|ARM64.Build.0 = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x64.ActiveCfg = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x64.Build.0 = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x86.ActiveCfg = Release|Any CPU
{1B3287BE-4FC5-45C7-BA45-D6A3A92D30C8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -140,6 +140,7 @@
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data.MySQL\IoTSharp.Data.MySQL.csproj" />
<ProjectReference Include="..\IoTSharp.Data.PostgreSQL\IoTSharp.Data.PostgreSQL.csproj" />
<ProjectReference Include="..\IoTSharp.Data.SqlServer\IoTSharp.Data.SqlServer.csproj" />
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -95,6 +95,9 @@ namespace IoTSharp
case DataBaseType.MySql:
services.ConfigureMySql(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI);
break;
case DataBaseType.SqlServer:
services.ConfigureSqlServer(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI);
break;
case DataBaseType.PostgreSql:
default:
services.ConfigureNpgsql(Configuration.GetConnectionString("IoTSharp"), settings.DbContextPoolSize, healthChecks, healthChecksUI);
......@@ -200,6 +203,9 @@ namespace IoTSharp
case DataBaseType.MySql:
config.UseMySqlToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode);
break;
case DataBaseType.SqlServer:
config.UseSqlServerToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode);
break;
case DataBaseType.PostgreSql:
default:
config.UseNpgsqlToSharding(Configuration.GetConnectionString("TelemetryStorage"), settings.Sharding.ExpandByDateMode);
......
......@@ -8,12 +8,10 @@
},
"DataBase": "MySql",
"ConnectionStrings": {
//pgsql "IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;",
"IoTSharp": "server=localhost;user=root;password=kissme;database=IoTSharp",
"EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
//"TelemetryStorage": "http://localhost:8086/?org=iotsharp&bucket=iotsharp-bucket&token=iotsharp-token&&latest=-72h"
},
"JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme",
"JwtExpireHours": 24,
......
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"DataBase": "MySql",
"ConnectionStrings": {
"IoTSharp": "server=localhost;user=root;password=kissme;database=IoTSharp",
"EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
},
"JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme",
"JwtExpireHours": 24,
"JwtIssuer": "IoTSharp.Net",
"JwtAudience": "IoTSharp.Net",
"EventBusStore": "InMemory",
"EventBusMQ": "InMemory",
"TelemetryStorage": "Sharding"
}
\ No newline at end of file
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"DataBase": "PostgreSql",
"ConnectionStrings": {
"IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;",
"EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
},
"JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme",
"JwtExpireHours": 24,
"JwtIssuer": "IoTSharp.Net",
"JwtAudience": "IoTSharp.Net",
"EventBusStore": "InMemory",
"EventBusMQ": "InMemory",
"TelemetryStorage": "Sharding"
}
\ No newline at end of file
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"DataBase": "SQLServer",
"ConnectionStrings": {
"IoTSharp": "Data Source=.;Initial Catalog=IoTSharp;Persist Security Info=True;User ID=sa;Password=future",
"EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "Data Source=.;Initial Catalog=IoTSharp;Persist Security Info=True;User ID=sa;Password=future",
"EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
},
"JwtKey": "kissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissmekissme",
"JwtExpireHours": 24,
"JwtIssuer": "IoTSharp.Net",
"JwtAudience": "IoTSharp.Net",
"EventBusStore": "InMemory",
"EventBusMQ": "InMemory",
"TelemetryStorage": "Sharding"
}
\ No newline at end of file
cd IoTSharp.Data.PostgreSQL
dotnet ef migrations add %1 --context IoTSharp.Data.ApplicationDbContext --startup-project ..\IoTSharp\IoTSharp.csproj
\ No newline at end of file
echo Add a migration name is %2 to IoTSharp.Data.%1
cd IoTSharp.Data.%1
set ASPNETCORE_ENVIRONMENT=%1
dotnet ef migrations add %2 --context IoTSharp.Data.ApplicationDbContext --startup-project ..\IoTSharp\IoTSharp.csproj --project ..\IoTSharp.Data.%1\IoTSharp.Data.%1.csproj
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册