mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
28 changed files with 563 additions and 71 deletions
@ -0,0 +1,22 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Squidex.Infrastructure; |
|||
|
|||
internal static partial class LogMessages |
|||
{ |
|||
[LoggerMessage(Level = LogLevel.Error, Message = "Insufficient privileges to apply the migrations of {context}. Ask an administrator to execute the following script manually and restart the application. Execute it as the application user with temporarily elevated privileges, so that the application remains the owner of the created objects:\n{sql}")] |
|||
public static partial void LogMigrationPrivilegesMissing(ILogger logger, Exception exception, string context, string sql); |
|||
|
|||
[LoggerMessage(Level = LogLevel.Error, Message = "Failed to apply the migrations of {context}. If the problem cannot be solved, ask an administrator to execute the following script manually and restart the application:\n{sql}")] |
|||
public static partial void LogMigrationFailed(ILogger logger, Exception exception, string context, string sql); |
|||
|
|||
[LoggerMessage(Level = LogLevel.Warning, Message = "Insufficient privileges to create index {name}. Ask an administrator to execute the following statements manually:\n{sql}")] |
|||
public static partial void LogIndexPrivilegesMissing(ILogger logger, Exception exception, string name, string sql); |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.EntityFrameworkCore.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Migrations.Operations; |
|||
using Microsoft.EntityFrameworkCore.Update; |
|||
using Microting.EntityFrameworkCore.MySql.Infrastructure.Internal; |
|||
using Microting.EntityFrameworkCore.MySql.Migrations; |
|||
|
|||
#pragma warning disable EF1001 // Internal EF Core API usage.
|
|||
|
|||
namespace Squidex.Providers.MySql; |
|||
|
|||
public sealed class MySqlScriptMigrationsSqlGenerator( |
|||
MigrationsSqlGeneratorDependencies dependencies, |
|||
ICommandBatchPreparer commandBatchPreparer, |
|||
IMySqlOptions options) |
|||
: MySqlMigrationsSqlGenerator(dependencies, commandBatchPreparer, options) |
|||
{ |
|||
protected override void Generate(SqlOperation operation, IModel? model, MigrationCommandListBuilder builder) |
|||
{ |
|||
if (!Options.HasFlag(MigrationsSqlGenerationOptions.Script)) |
|||
{ |
|||
base.Generate(operation, model, builder); |
|||
return; |
|||
} |
|||
|
|||
// Raw statements like functions contain semicolons and are not terminated, therefore the script would not run in MySQL clients.
|
|||
builder |
|||
.AppendLine("DELIMITER //") |
|||
.Append(operation.Sql) |
|||
.AppendLine(" //") |
|||
.AppendLine("DELIMITER ;"); |
|||
|
|||
EndStatement(builder, operation.SuppressTransaction); |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.EntityFrameworkCore.Metadata; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
using Microsoft.EntityFrameworkCore.Migrations.Operations; |
|||
using Microsoft.EntityFrameworkCore.Update; |
|||
|
|||
namespace Squidex.Providers.SqlServer; |
|||
|
|||
public sealed class SqlServerScriptMigrationsSqlGenerator( |
|||
MigrationsSqlGeneratorDependencies dependencies, |
|||
ICommandBatchPreparer commandBatchPreparer) |
|||
: SqlServerMigrationsSqlGenerator(dependencies, commandBatchPreparer) |
|||
{ |
|||
protected override void Generate(SqlOperation operation, IModel? model, MigrationCommandListBuilder builder) |
|||
{ |
|||
if (!Options.HasFlag(MigrationsSqlGenerationOptions.Script)) |
|||
{ |
|||
base.Generate(operation, model, builder); |
|||
return; |
|||
} |
|||
|
|||
// Raw statements like functions must be the first statement in a batch, therefore the script would not run in SQL Server clients.
|
|||
builder |
|||
.AppendLine("GO") |
|||
.AppendLine(operation.Sql) |
|||
.AppendLine("GO"); |
|||
|
|||
EndStatement(builder, operation.SuppressTransaction); |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace Squidex.EntityFramework.TestHelpers; |
|||
|
|||
public sealed class TestLogger<T> : ILogger<T> |
|||
{ |
|||
public List<string> Messages { get; } = []; |
|||
|
|||
public IDisposable? BeginScope<TState>(TState state) |
|||
where TState : notnull |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
public bool IsEnabled(LogLevel logLevel) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) |
|||
{ |
|||
Messages.Add(formatter(state, exception)); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue