mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-23 21:16:52 +01:00
Remove the need for DesignTime config
This commit is contained in:
@@ -34,11 +34,6 @@ namespace Tgstation.Server.Host.Configuration
|
||||
/// </summary>
|
||||
public bool DropDatabase { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Used to indicate that the database is being loaded to generate migrations. Should not be used in production!.
|
||||
/// </summary>
|
||||
public bool DesignTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="string"/> form of the <see cref="global::System.Version"/> of the target server.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace Tgstation.Server.Host.Database.Design
|
||||
{
|
||||
var dbConfig = new DatabaseConfiguration
|
||||
{
|
||||
DesignTime = true,
|
||||
DatabaseType = databaseType,
|
||||
ConnectionString = connectionString,
|
||||
ServerVersion = serverVersion,
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Tgstation.Server.Host.Database.Design
|
||||
/// <inheritdoc />
|
||||
public SqliteDatabaseContext CreateDbContext(string[] args)
|
||||
{
|
||||
SqliteDatabaseContext.DesignTime = true;
|
||||
return new SqliteDatabaseContext(
|
||||
DesignTimeDbContextFactoryHelpers.CreateDatabaseContextOptions<SqliteDatabaseContext>(
|
||||
DatabaseType.Sqlite,
|
||||
"Data Source=tgs_design.sqlite3;Mode=ReadWriteCreate"));
|
||||
"Data Source=tgs_design.sqlite3;Mode=ReadWriteCreate"),
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,21 @@ namespace Tgstation.Server.Host.Database
|
||||
sealed class SqliteDatabaseContext : DatabaseContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Static property to receive the configured value of <see cref="DatabaseConfiguration.DesignTime"/>.
|
||||
/// If the database context is running in design time mode.
|
||||
/// </summary>
|
||||
public static bool DesignTime { get; set; }
|
||||
readonly bool designTime;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SqliteDatabaseContext"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dbContextOptions">The <see cref="DbContextOptions{TContext}"/> for the <see cref="DatabaseContext"/>.</param>
|
||||
public SqliteDatabaseContext(DbContextOptions<SqliteDatabaseContext> dbContextOptions) : base(dbContextOptions)
|
||||
/// <param name="designTime">The value of <see cref="designTime"/>.</param>
|
||||
public SqliteDatabaseContext(
|
||||
DbContextOptions<SqliteDatabaseContext> dbContextOptions,
|
||||
bool designTime = false)
|
||||
: base(dbContextOptions)
|
||||
{
|
||||
this.designTime = designTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +36,9 @@ namespace Tgstation.Server.Host.Database
|
||||
/// </summary>
|
||||
/// <param name="options">The <see cref="DbContextOptionsBuilder"/> to configure.</param>
|
||||
/// <param name="databaseConfiguration">The <see cref="DatabaseConfiguration"/>.</param>
|
||||
public static void ConfigureWith(DbContextOptionsBuilder options, DatabaseConfiguration databaseConfiguration)
|
||||
public static void ConfigureWith(
|
||||
DbContextOptionsBuilder options,
|
||||
DatabaseConfiguration databaseConfiguration)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
ArgumentNullException.ThrowIfNull(databaseConfiguration);
|
||||
@@ -39,7 +46,6 @@ namespace Tgstation.Server.Host.Database
|
||||
if (databaseConfiguration.DatabaseType != DatabaseType.Sqlite)
|
||||
throw new InvalidOperationException($"Invalid DatabaseType for {nameof(SqliteDatabaseContext)}!");
|
||||
|
||||
DesignTime = databaseConfiguration.DesignTime;
|
||||
options.UseSqlite(databaseConfiguration.ConnectionString, sqliteOptions => sqliteOptions.UseQuerySplittingBehavior(QuerySplittingBehavior.SingleQuery));
|
||||
}
|
||||
|
||||
@@ -56,7 +62,7 @@ namespace Tgstation.Server.Host.Database
|
||||
// use the DateTimeOffsetToBinaryConverter
|
||||
// Based on: https://github.com/aspnet/EntityFrameworkCore/issues/10784#issuecomment-415769754
|
||||
// This only supports millisecond precision, but should be sufficient for most use cases.
|
||||
if (!DesignTime)
|
||||
if (!designTime)
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
var properties = entityType
|
||||
|
||||
Reference in New Issue
Block a user