Skip to content

Commit

Permalink
Updating yessql (#3099)
Browse files Browse the repository at this point in the history
Fixes #3028
Fixes #3029
  • Loading branch information
sebastienros authored Jan 30, 2019
1 parent a119fc0 commit 5721dac
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 114 deletions.
4 changes: 2 additions & 2 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<!--<add key="OrchardCore" value="https://www.myget.org/F/orchardcore-dev/api/v3/index.json" />-->
<add key="OrchardCore" value="https://www.myget.org/F/orchardcore-dev/api/v3/index.json" />
</packageSources>
<disabledPackageSources />
</configuration>
12 changes: 6 additions & 6 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<PackageManagement Include="xunit" Version="2.4.0" />
<PackageManagement Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageManagement Include="YamlDotNet" Version="5.3.0" />
<PackageManagement Include="YesSql.Abstractions" Version="2.0.0-beta-1285" />
<PackageManagement Include="YesSql.Core" Version="2.0.0-beta-1285" />
<PackageManagement Include="YesSql.Provider.MySql" Version="1.0.0-beta-1285" />
<PackageManagement Include="YesSql.Provider.PostgreSql" Version="1.0.0-beta-1285" />
<PackageManagement Include="YesSql.Provider.SqLite" Version="1.0.0-beta-1285" />
<PackageManagement Include="YesSql.Provider.SqlServer" Version="1.0.0-beta-1285" />
<PackageManagement Include="YesSql.Abstractions" Version="2.0.0-beta-1322" />
<PackageManagement Include="YesSql.Core" Version="2.0.0-beta-1322" />
<PackageManagement Include="YesSql.Provider.MySql" Version="1.0.0-beta-1322" />
<PackageManagement Include="YesSql.Provider.PostgreSql" Version="1.0.0-beta-1322" />
<PackageManagement Include="YesSql.Provider.SqLite" Version="1.0.0-beta-1322" />
<PackageManagement Include="YesSql.Provider.SqlServer" Version="1.0.0-beta-1322" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Data;
using System.Data.Common;
using StackExchange.Profiling.Data;
using YesSql;
Expand All @@ -18,18 +17,10 @@ public MiniProfilerConnectionFactory(IConnectionFactory factory)
_factory = factory;
}

public void CloseConnection(IDbConnection connection)
{
if (connection is ProfiledDbConnection profiledConnection)
{
_factory.CloseConnection(profiledConnection.WrappedConnection);
}
}

public IDbConnection CreateConnection()
public DbConnection CreateConnection()
{
// Forward the call to the actual factory
var connection = (DbConnection)_factory.CreateConnection();
var connection = _factory.CreateConnection();

// Reuse the actual dialect if not already defined
if (!SqlDialectFactory.SqlDialects.ContainsKey(ConnectionName))
Expand All @@ -39,10 +30,5 @@ public IDbConnection CreateConnection()

return new ProfiledDbConnection(connection, new CurrentDbProfiler(() => StackExchange.Profiling.MiniProfiler.Current));
}

public void Dispose()
{
_factory.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using YesSql.Sql;
using YesSql.Sql;

namespace OrchardCore.Data.Migration
{
public abstract class DataMigration : IDataMigration
{
public SchemaBuilder SchemaBuilder { get; set; }
public ISchemaBuilder SchemaBuilder { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using YesSql.Sql;
using YesSql.Sql;

namespace OrchardCore.Data.Migration
{
public interface IDataMigration
{
SchemaBuilder SchemaBuilder { get; set; }
ISchemaBuilder SchemaBuilder { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public async Task UpdateAsync(string featureId)
// apply update methods to each migration class for the module
foreach (var migration in migrations)
{
var schemaBuilder = new SchemaBuilder(_session);
var schemaBuilder = new SchemaBuilder(_store.Configuration, await _session.DemandAsync());
migration.SchemaBuilder = schemaBuilder;

// copy the object for the Linq query
Expand Down
22 changes: 15 additions & 7 deletions src/OrchardCore/OrchardCore.Data/OrchardCoreBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,45 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder)
return null;
}

var storeConfiguration = new YesSql.Configuration();
IConfiguration storeConfiguration = new YesSql.Configuration();

switch (shellSettings["DatabaseProvider"])
{
case "SqlConnection":
storeConfiguration.UseSqlServer(shellSettings["ConnectionString"], IsolationLevel.ReadUncommitted);
storeConfiguration
.UseSqlServer(shellSettings["ConnectionString"], IsolationLevel.ReadUncommitted)
.UseBlockIdGenerator();
break;
case "Sqlite":
var shellOptions = sp.GetService<IOptions<ShellOptions>>();
var option = shellOptions.Value;
var databaseFolder = Path.Combine(option.ShellsApplicationDataPath, option.ShellsContainerName, shellSettings.Name);
var databaseFile = Path.Combine(databaseFolder, "yessql.db");
Directory.CreateDirectory(databaseFolder);
storeConfiguration.UseSqLite($"Data Source={databaseFile};Cache=Shared", IsolationLevel.ReadUncommitted);
storeConfiguration
.UseSqLite($"Data Source={databaseFile};Cache=Shared", IsolationLevel.ReadUncommitted)
.UseDefaultIdGenerator(shellSettings.Name);
break;
case "MySql":
storeConfiguration.UseMySql(shellSettings["ConnectionString"], IsolationLevel.ReadUncommitted);
storeConfiguration
.UseMySql(shellSettings["ConnectionString"], IsolationLevel.ReadUncommitted)
.UseBlockIdGenerator();
break;
case "Postgres":
storeConfiguration.UsePostgreSql(shellSettings["ConnectionString"], IsolationLevel.ReadUncommitted);
storeConfiguration
.UsePostgreSql(shellSettings["ConnectionString"], IsolationLevel.ReadUncommitted)
.UseBlockIdGenerator();
break;
default:
throw new ArgumentException("Unknown database provider: " + shellSettings["DatabaseProvider"]);
}

if (!string.IsNullOrWhiteSpace(shellSettings["TablePrefix"]))
{
storeConfiguration.TablePrefix = shellSettings["TablePrefix"] + "_";
storeConfiguration = storeConfiguration.SetTablePrefix(shellSettings["TablePrefix"] + "_");
}

var store = new Store(storeConfiguration);
var store = StoreFactory.CreateAsync(storeConfiguration).GetAwaiter().GetResult();
var indexes = sp.GetServices<IIndexProvider>();

store.RegisterIndexes(indexes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
Expand Down Expand Up @@ -128,7 +129,7 @@ private async Task UpgradeFromBeta2()

var connectionAccessor = _serviceProvider.GetRequiredService<IDbConnectionAccessor>();

var connection = await connectionAccessor.GetConnectionAsync();
var connection = await connectionAccessor.GetConnectionAsync() as DbConnection;
var dialect = SqlDialectFactory.For(connection);
var tablePrefix = _shellSettings["TablePrefix"];

Expand Down
1 change: 0 additions & 1 deletion src/OrchardCore/OrchardCore.Setup.Core/SetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public async Task<string> SetupInternalAsync(SetupContext context)
try
{
store = scope.ServiceProvider.GetRequiredService<IStore>();
await store.InitializeAsync();
}
catch (Exception e)
{
Expand Down
Loading

0 comments on commit 5721dac

Please sign in to comment.