Removes sqlite

Way too much of a multithreaded environment to handle this correctly
This commit is contained in:
Cyberboss
2018-09-04 15:58:09 -04:00
parent b90171e917
commit c5b21be9ba
5 changed files with 4 additions and 65 deletions
@@ -12,10 +12,6 @@
/// <summary>
/// Use MySQL/MariaDB
/// </summary>
MySql,
/// <summary>
/// Use SQLite 3
/// </summary>
Sqlite
MySql
}
}
@@ -149,22 +149,19 @@ namespace Tgstation.Server.Host.Core
builder.EnableSensitiveDataLogging();
};
switch (databaseConfiguration?.DatabaseType ?? DatabaseType.Sqlite)
var dbType = databaseConfiguration?.DatabaseType;
switch (dbType)
{
case DatabaseType.MySql:
services.AddDbContext<MySqlDatabaseContext>(ConfigureDatabase);
services.AddScoped<IDatabaseContext>(x => x.GetRequiredService<MySqlDatabaseContext>());
break;
case DatabaseType.Sqlite:
services.AddDbContext<SqliteDatabaseContext>(ConfigureDatabase);
services.AddScoped<IDatabaseContext>(x => x.GetRequiredService<SqliteDatabaseContext>());
break;
case DatabaseType.SqlServer:
services.AddDbContext<SqlServerDatabaseContext>(ConfigureDatabase);
services.AddScoped<IDatabaseContext>(x => x.GetRequiredService<SqlServerDatabaseContext>());
break;
default:
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Invalid {0}!", nameof(DatabaseType)));
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Invalid {0}: {1}!", nameof(DatabaseType), dbType));
}
services.AddScoped<IAuthenticationContextFactory, AuthenticationContextFactory>();
@@ -1,15 +0,0 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Logging;
using Tgstation.Server.Host.Security;
namespace Tgstation.Server.Host.Models.Migrations
{
/// <inheritdoc />
sealed class SqliteDesignTimeDbContextFactory : IDesignTimeDbContextFactory<SqliteDatabaseContext>
{
/// <inheritdoc />
public SqliteDatabaseContext CreateDbContext(string[] args) => new SqliteDatabaseContext(new DbContextOptions<SqliteDatabaseContext>(), DesignTimeDbContextFactoryHelpers.GetDbContextOptions(), new DatabaseSeeder(new CryptographySuite(new PasswordHasher<User>())), new LoggerFactory().CreateLogger<SqliteDatabaseContext>());
}
}
@@ -1,38 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using Tgstation.Server.Host.Configuration;
namespace Tgstation.Server.Host.Models
{
/// <summary>
/// <see cref="DatabaseContext{TParentContext}"/> for Sqlite
/// </summary>
sealed class SqliteDatabaseContext : DatabaseContext<SqliteDatabaseContext>
{
/// <summary>
/// Construct a <see cref="SqliteDatabaseContext"/>
/// </summary>
/// <param name="dbContextOptions">The <see cref="DbContextOptions{TContext}"/> for the <see cref="DatabaseContext{TParentContext}"/></param>
/// <param name="databaseConfiguration">The <see cref="IOptions{TOptions}"/> of <see cref="DatabaseConfiguration"/> for the <see cref="DatabaseContext{TParentContext}"/></param>
/// <param name="databaseSeeder">The <see cref="IDatabaseSeeder"/> for the <see cref="DatabaseContext{TParentContext}"/></param>
/// <param name="logger">The <see cref="ILogger"/> for the <see cref="DatabaseContext{TParentContext}"/></param>
public SqliteDatabaseContext(DbContextOptions<SqliteDatabaseContext> dbContextOptions, IOptions<DatabaseConfiguration> databaseConfiguration, IDatabaseSeeder databaseSeeder, ILogger<SqliteDatabaseContext> logger) : base(dbContextOptions, databaseConfiguration, databaseSeeder, logger)
{ }
/// <inheritdoc />
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
base.OnConfiguring(options);
//on the off chance that connection string is null here we default to a db file next to the executable since this is the default database
if (ConnectionString == null)
{
Logger.LogWarning("No database configured! Defaulting to SQLite in the working directory!");
options.UseSqlite("Data Source=TgsDatabase.db3");
}
else
options.UseSqlite(ConnectionString);
}
}
}
@@ -37,7 +37,6 @@
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.2" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.12" />