Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
296fed88
IoTSharp
项目概览
IoTSharp
/
IoTSharp
大约 1 年 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
296fed88
编写于
2月 15, 2021
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify fo mysql
上级
0fecf0ab
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
160 addition
and
57 deletion
+160
-57
IoTSharp.Data.MySQL/IoTSharp.Data.MySQL.csproj
IoTSharp.Data.MySQL/IoTSharp.Data.MySQL.csproj
+4
-0
IoTSharp.Data.MySQL/IoTSharpDataBuilderExtensions.cs
IoTSharp.Data.MySQL/IoTSharpDataBuilderExtensions.cs
+4
-0
IoTSharp.Data.MySQL/Migrations/20210214193940_MySQLFirstSchema.Designer.cs
...QL/Migrations/20210214193940_MySQLFirstSchema.Designer.cs
+7
-7
IoTSharp.Data.MySQL/Migrations/20210214193940_MySQLFirstSchema.cs
....Data.MySQL/Migrations/20210214193940_MySQLFirstSchema.cs
+6
-6
IoTSharp.Data.MySQL/Migrations/ApplicationDbContextModelSnapshot.cs
...ata.MySQL/Migrations/ApplicationDbContextModelSnapshot.cs
+6
-6
IoTSharp.Data.MySQL/MySqlModelBuilderOptions.cs
IoTSharp.Data.MySQL/MySqlModelBuilderOptions.cs
+52
-0
IoTSharp.Data.PostgreSQL/IoTSharp.Data.PostgreSQL.csproj
IoTSharp.Data.PostgreSQL/IoTSharp.Data.PostgreSQL.csproj
+1
-0
IoTSharp.Data.PostgreSQL/IoTSharpDataBuilderExtensions.cs
IoTSharp.Data.PostgreSQL/IoTSharpDataBuilderExtensions.cs
+7
-1
IoTSharp.Data.PostgreSQL/NpgsqlModelBuilderOptions.cs
IoTSharp.Data.PostgreSQL/NpgsqlModelBuilderOptions.cs
+52
-0
IoTSharp.Data/ApplicationDbContext.cs
IoTSharp.Data/ApplicationDbContext.cs
+7
-37
IoTSharp.Data/IDataBaseModelBuilderOptions.cs
IoTSharp.Data/IDataBaseModelBuilderOptions.cs
+14
-0
未找到文件。
IoTSharp.Data.MySQL/IoTSharp.Data.MySQL.csproj
浏览文件 @
296fed88
...
...
@@ -20,4 +20,8 @@
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
IoTSharp.Data.MySQL/IoTSharpDataBuilderExtensions.cs
浏览文件 @
296fed88
using
EFCore.Sharding
;
using
IoTSharp.Data
;
using
IoTSharp.Data.MySQL
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
...
...
@@ -11,8 +12,11 @@ namespace Microsoft.Extensions.DependencyInjection
{
public
static
void
ConfigureMySql
(
this
IServiceCollection
services
,
string
connectionString
,
int
poolSize
,
IHealthChecksBuilder
checksBuilder
,
HealthChecksUIBuilder
healthChecksUI
)
{
services
.
AddEntityFrameworkMySql
();
services
.
AddSingleton
<
IDataBaseModelBuilderOptions
>(
c
=>
new
MySqlModelBuilderOptions
());
services
.
AddDbContextPool
<
ApplicationDbContext
>(
builder
=>
{
builder
.
UseInternalServiceProvider
(
services
.
BuildServiceProvider
());
builder
.
UseMySql
(
connectionString
,
ServerVersion
.
AutoDetect
(
connectionString
),
s
=>
s
.
MigrationsAssembly
(
"IoTSharp.Data.MySQL"
));
}
,
poolSize
);
...
...
IoTSharp.Data.MySQL/Migrations/202102141
85821
_MySQLFirstSchema.Designer.cs
→
IoTSharp.Data.MySQL/Migrations/202102141
93940
_MySQLFirstSchema.Designer.cs
浏览文件 @
296fed88
...
...
@@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace
IoTSharp.Data.MySQL.Migrations
{
[
DbContext
(
typeof
(
ApplicationDbContext
))]
[
Migration
(
"202102141
85821
_MySQLFirstSchema"
)]
[
Migration
(
"202102141
93940
_MySQLFirstSchema"
)]
partial
class
MySQLFirstSchema
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
...
...
@@ -26,13 +26,13 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
string
>(
"ActionData"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
string
>(
"ActionName"
)
.
HasColumnType
(
"longtext CHARACTER SET utf8mb4"
);
b
.
Property
<
string
>(
"ActionResult"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
DateTime
>(
"ActiveDateTime"
)
.
HasColumnType
(
"datetime(6)"
);
...
...
@@ -170,7 +170,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"double"
);
b
.
Property
<
string
>(
"Value_Json"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
long
>(
"Value_Long"
)
.
HasColumnType
(
"bigint"
);
...
...
@@ -179,7 +179,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"longtext CHARACTER SET utf8mb4"
);
b
.
Property
<
string
>(
"Value_XML"
)
.
HasColumnType
(
"
xml
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
HasKey
(
"Catalog"
,
"DeviceId"
,
"KeyName"
);
...
...
@@ -322,7 +322,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"double"
);
b
.
Property
<
string
>(
"Value_Json"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
long
>(
"Value_Long"
)
.
HasColumnType
(
"bigint"
);
...
...
@@ -331,7 +331,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"longtext CHARACTER SET utf8mb4"
);
b
.
Property
<
string
>(
"Value_XML"
)
.
HasColumnType
(
"
xml
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
HasKey
(
"DeviceId"
,
"KeyName"
,
"DateTime"
);
...
...
IoTSharp.Data.MySQL/Migrations/202102141
85821
_MySQLFirstSchema.cs
→
IoTSharp.Data.MySQL/Migrations/202102141
93940
_MySQLFirstSchema.cs
浏览文件 @
296fed88
...
...
@@ -62,8 +62,8 @@ namespace IoTSharp.Data.MySQL.Migrations
Value_Long
=
table
.
Column
<
long
>(
type
:
"bigint"
,
nullable
:
false
),
Value_DateTime
=
table
.
Column
<
DateTime
>(
type
:
"timestamp with time zone(6)"
,
nullable
:
false
),
Value_Double
=
table
.
Column
<
double
>(
type
:
"double"
,
nullable
:
false
),
Value_Json
=
table
.
Column
<
string
>(
type
:
"
jsonb
"
,
nullable
:
true
),
Value_XML
=
table
.
Column
<
string
>(
type
:
"
xml
"
,
nullable
:
true
),
Value_Json
=
table
.
Column
<
string
>(
type
:
"
longtext CHARACTER SET utf8mb4
"
,
nullable
:
true
),
Value_XML
=
table
.
Column
<
string
>(
type
:
"
longtext CHARACTER SET utf8mb4
"
,
nullable
:
true
),
Value_Binary
=
table
.
Column
<
byte
[
]>
(
type
:
"longblob"
,
nullable
:
true
)
},
constraints
:
table
=>
...
...
@@ -85,8 +85,8 @@ namespace IoTSharp.Data.MySQL.Migrations
Value_Long
=
table
.
Column
<
long
>(
type
:
"bigint"
,
nullable
:
false
),
Value_DateTime
=
table
.
Column
<
DateTime
>(
type
:
"timestamp with time zone(6)"
,
nullable
:
false
),
Value_Double
=
table
.
Column
<
double
>(
type
:
"double"
,
nullable
:
false
),
Value_Json
=
table
.
Column
<
string
>(
type
:
"
jsonb
"
,
nullable
:
true
),
Value_XML
=
table
.
Column
<
string
>(
type
:
"
xml
"
,
nullable
:
true
),
Value_Json
=
table
.
Column
<
string
>(
type
:
"
longtext CHARACTER SET utf8mb4
"
,
nullable
:
true
),
Value_XML
=
table
.
Column
<
string
>(
type
:
"
longtext CHARACTER SET utf8mb4
"
,
nullable
:
true
),
Value_Binary
=
table
.
Column
<
byte
[
]>
(
type
:
"longblob"
,
nullable
:
true
)
},
constraints
:
table
=>
...
...
@@ -260,8 +260,8 @@ namespace IoTSharp.Data.MySQL.Migrations
ObjectName
=
table
.
Column
<
string
>(
type
:
"longtext CHARACTER SET utf8mb4"
,
nullable
:
true
),
ObjectType
=
table
.
Column
<
int
>(
type
:
"int"
,
nullable
:
false
),
ActionName
=
table
.
Column
<
string
>(
type
:
"longtext CHARACTER SET utf8mb4"
,
nullable
:
true
),
ActionData
=
table
.
Column
<
string
>(
type
:
"
jsonb
"
,
nullable
:
true
),
ActionResult
=
table
.
Column
<
string
>(
type
:
"
jsonb
"
,
nullable
:
true
),
ActionData
=
table
.
Column
<
string
>(
type
:
"
longtext CHARACTER SET utf8mb4
"
,
nullable
:
true
),
ActionResult
=
table
.
Column
<
string
>(
type
:
"
longtext CHARACTER SET utf8mb4
"
,
nullable
:
true
),
ActiveDateTime
=
table
.
Column
<
DateTime
>(
type
:
"datetime(6)"
,
nullable
:
false
)
},
constraints
:
table
=>
...
...
IoTSharp.Data.MySQL/Migrations/ApplicationDbContextModelSnapshot.cs
浏览文件 @
296fed88
...
...
@@ -24,13 +24,13 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"char(36)"
);
b
.
Property
<
string
>(
"ActionData"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
string
>(
"ActionName"
)
.
HasColumnType
(
"longtext CHARACTER SET utf8mb4"
);
b
.
Property
<
string
>(
"ActionResult"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
DateTime
>(
"ActiveDateTime"
)
.
HasColumnType
(
"datetime(6)"
);
...
...
@@ -168,7 +168,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"double"
);
b
.
Property
<
string
>(
"Value_Json"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
long
>(
"Value_Long"
)
.
HasColumnType
(
"bigint"
);
...
...
@@ -177,7 +177,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"longtext CHARACTER SET utf8mb4"
);
b
.
Property
<
string
>(
"Value_XML"
)
.
HasColumnType
(
"
xml
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
HasKey
(
"Catalog"
,
"DeviceId"
,
"KeyName"
);
...
...
@@ -320,7 +320,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"double"
);
b
.
Property
<
string
>(
"Value_Json"
)
.
HasColumnType
(
"
jsonb
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
Property
<
long
>(
"Value_Long"
)
.
HasColumnType
(
"bigint"
);
...
...
@@ -329,7 +329,7 @@ namespace IoTSharp.Data.MySQL.Migrations
.
HasColumnType
(
"longtext CHARACTER SET utf8mb4"
);
b
.
Property
<
string
>(
"Value_XML"
)
.
HasColumnType
(
"
xml
"
);
.
HasColumnType
(
"
longtext CHARACTER SET utf8mb4
"
);
b
.
HasKey
(
"DeviceId"
,
"KeyName"
,
"DateTime"
);
...
...
IoTSharp.Data.MySQL/MySqlModelBuilderOptions.cs
0 → 100644
浏览文件 @
296fed88
using
Microsoft.EntityFrameworkCore
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Data.MySQL
{
public
class
MySqlModelBuilderOptions
:
IDataBaseModelBuilderOptions
{
public
MySqlModelBuilderOptions
()
{
}
public
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
//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");
}
}
}
IoTSharp.Data.PostgreSQL/IoTSharp.Data.PostgreSQL.csproj
浏览文件 @
296fed88
...
...
@@ -8,6 +8,7 @@
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.PostgreSQL.Storage" Version="5.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
...
...
IoTSharp.Data.PostgreSQL/IoTSharpDataBuilderExtensions.cs
浏览文件 @
296fed88
using
EFCore.Sharding
;
using
IoTSharp.Data
;
using
IoTSharp.Data.PostgreSQL
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
...
...
@@ -9,11 +10,16 @@ namespace Microsoft.Extensions.DependencyInjection
{
public
static
class
IoTSharpDataBuilderExtensions
{
public
static
void
ConfigureNpgsql
(
this
IServiceCollection
services
,
string
connectionString
,
int
poolSize
,
IHealthChecksBuilder
checksBuilder
,
HealthChecksUIBuilder
healthChecksUI
)
{
services
.
AddEntityFrameworkNpgsql
();
services
.
AddSingleton
<
IDataBaseModelBuilderOptions
>(
c
=>
new
NpgsqlModelBuilderOptions
());
services
.
AddDbContextPool
<
ApplicationDbContext
>(
builder
=>
{
builder
.
UseNpgsql
(
connectionString
,
s
=>
s
.
MigrationsAssembly
(
"IoTSharp.Data.PostgreSQL"
));
builder
.
UseNpgsql
(
connectionString
,
s
=>
s
.
MigrationsAssembly
(
"IoTSharp.Data.PostgreSQL"
));
builder
.
UseInternalServiceProvider
(
services
.
BuildServiceProvider
());
}
,
poolSize
);
checksBuilder
.
AddNpgSql
(
connectionString
);
...
...
IoTSharp.Data.PostgreSQL/NpgsqlModelBuilderOptions.cs
0 → 100644
浏览文件 @
296fed88
using
Microsoft.EntityFrameworkCore
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Data.PostgreSQL
{
public
class
NpgsqlModelBuilderOptions
:
IDataBaseModelBuilderOptions
{
public
NpgsqlModelBuilderOptions
()
{
}
public
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
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"
);
}
}
}
IoTSharp.Data/ApplicationDbContext.cs
浏览文件 @
296fed88
...
...
@@ -4,15 +4,19 @@ using Microsoft.Extensions.Configuration;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
IoTSharp.Data
{
public
class
ApplicationDbContext
:
IdentityDbContext
{
public
ApplicationDbContext
(
DbContextOptions
<
ApplicationDbContext
>
options
)
:
base
(
options
)
{
if
(
Database
.
GetPendingMigrations
().
Count
()
>
0
)
{
Database
.
Migrate
();
...
...
@@ -38,47 +42,13 @@ namespace IoTSharp.Data
modelBuilder
.
Entity
<
TelemetryLatest
>().
HasDiscriminator
<
DataCatalog
>(
nameof
(
Data
.
DataStorage
.
Catalog
));
modelBuilder
.
Entity
<
Device
>().
HasDiscriminator
<
DeviceType
>(
nameof
(
Data
.
Device
.
DeviceType
)).
HasValue
<
Gateway
>(
DeviceType
.
Gateway
).
HasValue
<
Device
>(
DeviceType
.
Device
);
modelBuilder
.
Entity
<
Gateway
>().
HasDiscriminator
<
DeviceType
>(
nameof
(
Data
.
Device
.
DeviceType
));
ForNpgsql
(
modelBuilder
);
this
.
GetService
<
IDataBaseModelBuilderOptions
>().
OnModelCreating
(
modelBuilder
);
modelBuilder
.
ApplyConfiguration
(
new
TelemetryDataConfiguration
());
base
.
OnModelCreating
(
modelBuilder
);
}
private
void
ForNpgsql
(
ModelBuilder
modelBuilder
)
{
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"
);
}
public
DbSet
<
Tenant
>
Tenant
{
get
;
set
;
}
public
DbSet
<
Customer
>
Customer
{
get
;
set
;
}
...
...
IoTSharp.Data/IDataBaseModelBuilderOptions.cs
0 → 100644
浏览文件 @
296fed88
using
Microsoft.EntityFrameworkCore
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Data
{
public
interface
IDataBaseModelBuilderOptions
{
public
void
OnModelCreating
(
ModelBuilder
modelBuilder
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录