mirror of https://github.com/Squidex/squidex.git
Browse Source
- Test fixtures now use the same code path as production (MigrateAsync) - DatabaseCreator and SqlDialectInitializer are no longer needed and deleted - Functions are created via the AddJsonFunctions migration, not at every startuppull/1313/head
5 changed files with 9 additions and 80 deletions
@ -1,42 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using Microsoft.EntityFrameworkCore; |
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
||||
using Microsoft.EntityFrameworkCore.Storage; |
|
||||
using Squidex.Hosting; |
|
||||
|
|
||||
#pragma warning disable RECS0108 // Warns about static fields in generic types
|
|
||||
|
|
||||
namespace Squidex.Infrastructure.Migrations; |
|
||||
|
|
||||
public sealed class DatabaseCreator<TContext>(IDbContextFactory<TContext> dbContextFactory) : IInitializable |
|
||||
where TContext : DbContext |
|
||||
{ |
|
||||
private static readonly TimeSpan WaitTime = TimeSpan.FromSeconds(30); |
|
||||
|
|
||||
public int Order => -1000; |
|
||||
|
|
||||
public async Task InitializeAsync( |
|
||||
CancellationToken ct) |
|
||||
{ |
|
||||
await using var dbContext = await dbContextFactory.CreateDbContextAsync(ct); |
|
||||
|
|
||||
using var cts = new CancellationTokenSource(WaitTime); |
|
||||
while (!await dbContext.Database.CanConnectAsync(cts.Token)) |
|
||||
{ |
|
||||
await Task.Delay(100, cts.Token); |
|
||||
} |
|
||||
|
|
||||
if (dbContext.Database.GetService<IDatabaseCreator>() is not RelationalDatabaseCreator relationalDatabaseCreator) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
await relationalDatabaseCreator.EnsureCreatedAsync(ct); |
|
||||
} |
|
||||
} |
|
||||
@ -1,26 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using Microsoft.EntityFrameworkCore; |
|
||||
using Squidex.Hosting; |
|
||||
|
|
||||
namespace Squidex.Infrastructure.Queries; |
|
||||
|
|
||||
public sealed class SqlDialectInitializer<TContext>(IDbContextFactory<TContext> dbContextFactory) |
|
||||
: IInitializable where TContext : DbContext |
|
||||
{ |
|
||||
public async Task InitializeAsync(CancellationToken ct) |
|
||||
{ |
|
||||
await using var dbContext = await dbContextFactory.CreateDbContextAsync(ct); |
|
||||
if (dbContext is not IDbContextWithDialect withDialect) |
|
||||
{ |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
await withDialect.Dialect.InitializeAsync(dbContext, ct); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue