mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-30 16:39:21 +01:00
Fix Sqlite migration generation
This commit is contained in:
@@ -34,6 +34,11 @@ 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 a target MySQL/MariaDB server
|
||||
/// </summary>
|
||||
|
||||
@@ -34,7 +34,9 @@ namespace Tgstation.Server.Host.Database.Design
|
||||
builder.AddJsonFile(RootJson);
|
||||
builder.AddJsonFile(DevJson);
|
||||
var configuration = builder.Build();
|
||||
return Options.Create(configuration.GetSection(DatabaseConfiguration.Section).Get<DatabaseConfiguration>());
|
||||
var dbConfig = configuration.GetSection(DatabaseConfiguration.Section).Get<DatabaseConfiguration>();
|
||||
dbConfig.DesignTime = true;
|
||||
return Options.Create(dbConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,18 +43,19 @@ 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.
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
var properties = entityType
|
||||
.ClrType
|
||||
.GetProperties()
|
||||
.Where(p => p.PropertyType == typeof(DateTimeOffset) || p.PropertyType == typeof(DateTimeOffset?));
|
||||
foreach (var property in properties)
|
||||
modelBuilder
|
||||
.Entity(entityType.Name)
|
||||
.Property(property.Name)
|
||||
.HasConversion(new DateTimeOffsetToBinaryConverter());
|
||||
}
|
||||
if (!DatabaseConfiguration.DesignTime)
|
||||
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
|
||||
{
|
||||
var properties = entityType
|
||||
.ClrType
|
||||
.GetProperties()
|
||||
.Where(p => p.PropertyType == typeof(DateTimeOffset) || p.PropertyType == typeof(DateTimeOffset?));
|
||||
foreach (var property in properties)
|
||||
modelBuilder
|
||||
.Entity(entityType.Name)
|
||||
.Property(property.Name)
|
||||
.HasConversion(new DateTimeOffsetToBinaryConverter());
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user