-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathIModelConfigurator.cs
More file actions
102 lines (84 loc) · 2.99 KB
/
Copy pathIModelConfigurator.cs
File metadata and controls
102 lines (84 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2026 Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Moryx.Model.Configuration;
namespace Moryx.Model;
/// <summary>
/// Result enum for function TestConnection
/// </summary>
public enum TestConnectionResult
{
/// <summary>
/// Anything that belongs to a non-existent or wrong configuration
/// </summary>
ConfigurationError,
/// <summary>
/// Connection could not be established
/// </summary>
ConnectionError,
/// <summary>
/// Connection could be established but database was not found
/// </summary>
ConnectionOkDbDoesNotExist,
/// <summary>
/// Connection to database was ok but the model have pending migrations
/// </summary>
PendingMigrations,
/// <summary>
/// Connection could be established but database was found
/// </summary>
Success
}
/// <summary>
/// Interface for interaction with model
/// </summary>
public interface IModelConfigurator
{
/// <summary>
/// Gets the configuration of the underlying model
/// </summary>
DatabaseConfig Config { get; }
/// <summary>
/// Initializes the model configurator
/// </summary>
void Initialize(Type contextType, DatabaseConfig config, ILogger logger);
/// <summary>
/// Creates a context with internal configuration
/// </summary>
DbContext CreateContext();
/// <summary>
/// Creates a context based on a config
/// </summary>
DbContext CreateContext(DatabaseConfig config);
/// <summary>
/// Creates a context based on `DbContextOptions`
/// </summary>
DbContext CreateContext(Type contextType, DbContextOptions dbContextOptions);
/// <summary>
/// Test connection for config
/// </summary>
Task<TestConnectionResult> TestConnectionAsync(DatabaseConfig config, CancellationToken cancellationToken = default);
/// <summary>
/// Create a new database for this model with given config
/// </summary>
Task<bool> CreateDatabaseAsync(DatabaseConfig config, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves all names of available updates
/// </summary>
/// <returns></returns>
Task<IReadOnlyList<string>> AvailableMigrationsAsync(DatabaseConfig config, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves all names of installed updates
/// </summary>
/// <returns></returns>
Task<IReadOnlyList<string>> AppliedMigrationsAsync(DatabaseConfig config, CancellationToken cancellationToken = default);
/// <summary>
/// Applies all migrations to the database
/// </summary>
Task<DatabaseMigrationSummary> MigrateDatabaseAsync(DatabaseConfig config, CancellationToken cancellationToken = default);
/// <summary>
/// Delete this database
/// </summary>
Task DeleteDatabaseAsync(DatabaseConfig config, CancellationToken cancellationToken = default);
}