mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-23 08:54:20 +01:00
make sure postgres DB is created with C locale
This commit is contained in:
@@ -6,6 +6,11 @@ using System.Threading.Tasks;
|
|||||||
using Hangfire;
|
using Hangfire;
|
||||||
using Hangfire.MemoryStorage;
|
using Hangfire.MemoryStorage;
|
||||||
using Hangfire.PostgreSql;
|
using Hangfire.PostgreSql;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Migrations;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Operations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
||||||
namespace BTCPayServer.Data
|
namespace BTCPayServer.Data
|
||||||
{
|
{
|
||||||
@@ -31,12 +36,56 @@ namespace BTCPayServer.Data
|
|||||||
return new ApplicationDbContext(builder.Options);
|
return new ApplicationDbContext(builder.Options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CustomNpgsqlMigrationsSqlGenerator : NpgsqlMigrationsSqlGenerator
|
||||||
|
{
|
||||||
|
public CustomNpgsqlMigrationsSqlGenerator(MigrationsSqlGeneratorDependencies dependencies) : base(dependencies)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Generate(NpgsqlCreateDatabaseOperation operation, IModel model, MigrationCommandListBuilder builder)
|
||||||
|
{
|
||||||
|
builder
|
||||||
|
.Append("CREATE DATABASE ")
|
||||||
|
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Name));
|
||||||
|
|
||||||
|
// POSTGRES gotcha: Indexed Text column (even if PK) are not used if we are not using C locale
|
||||||
|
builder
|
||||||
|
.Append(" TEMPLATE ")
|
||||||
|
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier("template0"));
|
||||||
|
|
||||||
|
builder
|
||||||
|
.Append(" LC_CTYPE ")
|
||||||
|
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier("C"));
|
||||||
|
|
||||||
|
builder
|
||||||
|
.Append(" LC_COLLATE ")
|
||||||
|
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier("C"));
|
||||||
|
|
||||||
|
builder
|
||||||
|
.Append(" ENCODING ")
|
||||||
|
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier("UTF8"));
|
||||||
|
|
||||||
|
if (operation.Tablespace != null)
|
||||||
|
{
|
||||||
|
builder
|
||||||
|
.Append(" TABLESPACE ")
|
||||||
|
.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(operation.Tablespace));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator);
|
||||||
|
|
||||||
|
EndStatement(builder, suppressTransaction: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ConfigureBuilder(DbContextOptionsBuilder builder)
|
public void ConfigureBuilder(DbContextOptionsBuilder builder)
|
||||||
{
|
{
|
||||||
if (_Type == DatabaseType.Sqlite)
|
if (_Type == DatabaseType.Sqlite)
|
||||||
builder.UseSqlite(_ConnectionString);
|
builder.UseSqlite(_ConnectionString);
|
||||||
else if (_Type == DatabaseType.Postgres)
|
else if (_Type == DatabaseType.Postgres)
|
||||||
builder.UseNpgsql(_ConnectionString);
|
builder
|
||||||
|
.UseNpgsql(_ConnectionString)
|
||||||
|
.ReplaceService<IMigrationsSqlGenerator, CustomNpgsqlMigrationsSqlGenerator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ConfigureHangfireBuilder(IGlobalConfiguration builder)
|
public void ConfigureHangfireBuilder(IGlobalConfiguration builder)
|
||||||
|
|||||||
Reference in New Issue
Block a user