//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.Persistence;
using System.Threading;
///
/// Provider for persistence contexts which supports database creation and migration.
/// TODO: find better name?.
///
public interface IMigratableDatabaseContextProvider : IPersistenceContextProvider
{
///
/// Determines if the database exists already, by checking if any migration has been applied.
///
/// The cancellation token.
///
/// True, if the database exists; Otherwise, false.
///
Task DatabaseExistsAsync(CancellationToken cancellationToken = default);
///
/// Determines whether the database schema is up to date.
///
/// The cancellation token.
///
/// true if the database is up to date; otherwise, false.
///
Task IsDatabaseUpToDateAsync(CancellationToken cancellationToken = default);
///
/// Applies all pending updates to the database schema.
///
Task ApplyAllPendingUpdatesAsync();
///
/// Waits until all database updates are applied.
///
/// The cancellation token.
Task WaitForUpdatedDatabaseAsync(CancellationToken cancellationToken = default);
///
/// Determines whether this instance can connect to the database.
///
/// The cancellation token.
///
/// true if this instance can connect to the database; otherwise, false.
///
Task CanConnectToDatabaseAsync(CancellationToken cancellationToken = default);
///
/// Determines whether this instance should do an automatic schema update
/// without asking the user.
///
/// The cancellation token.
///
/// true if this instance should do an automatic schema update
/// without asking the user.; otherwise, false.
///
Task ShouldDoAutoSchemaUpdateAsync(CancellationToken cancellationToken = default);
///
/// Recreates the database by deleting and creating it again.
///
///
/// If (the default), the database is dropped and created again from scratch.
/// If , the existing database is kept and only its schema is built via
/// migrations. Set this to when the database is provisioned externally
/// (e.g. by a Kubernetes operator, infrastructure-as-code, or a managed cloud database) and the
/// connecting role is not permitted to create or drop databases.
///
/// The disposable which should be disposed when the data creation process is finished.
Task ReCreateDatabaseAsync(bool dropExistingDatabase = true);
///
/// Resets the cache of this instance.
///
void ResetCache();
}