diff --git a/nuget-publish.bat b/nuget-publish.bat index 85316005..87a804d2 100644 --- a/nuget-publish.bat +++ b/nuget-publish.bat @@ -1,9 +1,9 @@ :start ::定义版本 -set EFCORE2=2.3.1.81 -set EFCORE3=3.3.1.81 -set EFCORE5=5.3.1.81 -set EFCORE6=6.3.1.81 +set EFCORE2=2.3.1.82 +set EFCORE3=3.3.1.82 +set EFCORE5=5.3.1.82 +set EFCORE6=6.3.1.82 ::删除所有bin与obj下的文件 @echo off diff --git a/samples/Sample.SqlServerShardingDataSource/Startup.cs b/samples/Sample.SqlServerShardingDataSource/Startup.cs index e6b089e6..2f28cc8d 100644 --- a/samples/Sample.SqlServerShardingDataSource/Startup.cs +++ b/samples/Sample.SqlServerShardingDataSource/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Sample.SqlServerShardingDataSource.VirtualRoutes; using ShardingCore; using System.Collections.Generic; +using ShardingCore.TableExists; namespace Sample.SqlServerShardingDataSource { @@ -38,7 +39,7 @@ namespace Sample.SqlServerShardingDataSource op.AutoTrackEntity = true; //ʹcode-firstѡfalse op.CreateShardingTableOnStart = true; - //ʹcode-first޸Ϊfsle + //ʹcode-first޸Ϊfalse op.EnsureCreatedWithOutShardingTable = true; }).AddShardingTransaction((connection, builder) => { @@ -63,7 +64,8 @@ namespace Sample.SqlServerShardingDataSource { op.AddShardingDatabaseRoute(); op.AddShardingDatabaseRoute(); - }).End(); + }).AddTableEnsureManager(sp=>new SqlServerTableEnsureManager()) + .End(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs b/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs index ba902050..d1215a75 100644 --- a/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs +++ b/src/ShardingCore/DynamicDataSources/DefaultDataSourceInitializer.cs @@ -53,12 +53,17 @@ namespace ShardingCore.DynamicDataSources _logger = logger; } public void InitConfigure(string dataSourceName, string connectionString) + { + InitConfigure(dataSourceName,connectionString, _shardingConfigOption.EnsureCreatedWithOutShardingTable); + } + + public void InitConfigure(string dataSourceName, string connectionString, bool createDatabase) { using (var serviceScope = ShardingContainer.ServiceProvider.CreateScope()) { _virtualDataSource.AddPhysicDataSource(new DefaultPhysicDataSource(dataSourceName, connectionString, false)); using var context = serviceScope.ServiceProvider.GetService(); - if (_shardingConfigOption.EnsureCreatedWithOutShardingTable) + if (createDatabase) EnsureCreated(context, dataSourceName); var tableEnsureManager = ShardingContainer.GetService>(); //获取数据库存在的所有的表 @@ -99,6 +104,7 @@ namespace ShardingCore.DynamicDataSources } } } + private void CreateDataTable(string dataSourceName, IVirtualTable virtualTable, ISet existTables) { var entityMetadata = virtualTable.EntityMetadata; diff --git a/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs b/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs index d03a9c4b..78b9f332 100644 --- a/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs +++ b/src/ShardingCore/DynamicDataSources/IDataSourceInitializer`1.cs @@ -11,5 +11,6 @@ namespace ShardingCore.DynamicDataSources public interface IDataSourceInitializer where TShardingDbContext : DbContext, IShardingDbContext { void InitConfigure(string dataSourceName, string connectionString); + void InitConfigure(string dataSourceName, string connectionString,bool createDatabase); } } diff --git a/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs b/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs index f1da79ae..5647e330 100644 --- a/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs +++ b/src/ShardingCore/VirtualRoutes/Abstractions/AbstractShardingAutoCreateOperatorVirtualTableRoute.cs @@ -43,7 +43,15 @@ namespace ShardingCore.VirtualRoutes.Abstractions /// 显示错误日志 /// public virtual bool DoLogError => false; - + /// + /// 默认会在设置时间后10分钟获取tail + /// + public virtual int IncrementMinutes => 10; + /// + /// 重写改方法后请一起重写IncrementMinutes值,比如你按月分表但是你设置cron表达式为月中的时候建表, + /// 那么会在月中的时候 DateTime.Now.AddMinutes(IncrementMinutes);来获取tail会导致还是当月的所以不会建表 + /// + /// public abstract string[] GetCronExpressions(); public Task ExecuteAsync() { @@ -58,7 +66,7 @@ namespace ShardingCore.VirtualRoutes.Abstractions var entityMetadataManager = (IEntityMetadataManager)ShardingContainer.GetService(typeof(IEntityMetadataManager<>).GetGenericType0(EntityMetadata.ShardingDbContextType)); var virtualDataSource = (IVirtualDataSource)ShardingContainer.GetService(typeof(IVirtualDataSource<>).GetGenericType0(EntityMetadata.ShardingDbContextType)); var tableCreator = (IShardingTableCreator)ShardingContainer.GetService(typeof(IShardingTableCreator<>).GetGenericType0(EntityMetadata.ShardingDbContextType)); - var now = DateTime.Now.AddMinutes(10); + var now = DateTime.Now.AddMinutes(IncrementMinutes); var tail = virtualTable.GetVirtualRoute().ShardingKeyToTail(now); ISet dataSources = new HashSet(); if (entityMetadataManager.IsShardingDataSource(typeof(TEntity)))