Migrations and proper database providers.

This commit is contained in:
Karolis2011
2019-06-18 19:37:59 +03:00
parent 94c92a47dc
commit 915a770175
2 changed files with 7 additions and 8 deletions

View File

@@ -25,7 +25,7 @@ namespace EventBot
services.GetRequiredService<CommandService>().Log += LogAsync; services.GetRequiredService<CommandService>().Log += LogAsync;
services.GetRequiredService<CommandHandlingService>().Log += LogAsync; services.GetRequiredService<CommandHandlingService>().Log += LogAsync;
services.GetRequiredService<DatabaseService>(); await services.GetRequiredService<DatabaseService>().InitializeAsync();
// Tokens should be considered secret data and never hard-coded. // Tokens should be considered secret data and never hard-coded.
// We can read from the environment variable to avoid hardcoding. // We can read from the environment variable to avoid hardcoding.

View File

@@ -40,14 +40,13 @@ namespace EventBot.Services
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseLazyLoadingProxies(); optionsBuilder.UseLazyLoadingProxies();
#if DEBUG
optionsBuilder.UseSqlite("Data Source=blogging.db");
#else
optionsBuilder.UseMySql(Environment.GetEnvironmentVariable("dbconnection"));
#endif
} }
public async Task InitializeAsync()
{
await Database.MigrateAsync();
}
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {