mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-19 03:31:29 +00:00
Make DatabaseFacts migrate database before running
This commit is contained in:
parent
d6b141d1f0
commit
ba85c28041
2 changed files with 9 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using ProjectLighthouse.Types;
|
using ProjectLighthouse.Types;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -6,6 +7,10 @@ namespace ProjectLighthouse.Tests {
|
||||||
public DatabaseFact() {
|
public DatabaseFact() {
|
||||||
ServerSettings.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
|
ServerSettings.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
|
||||||
if(!ServerSettings.DbConnected) Skip = "Database not available";
|
if(!ServerSettings.DbConnected) Skip = "Database not available";
|
||||||
|
else {
|
||||||
|
using Database database = new();
|
||||||
|
database.Database.Migrate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -13,17 +13,18 @@ namespace ProjectLighthouse {
|
||||||
Console.WriteLine("Welcome to Project Lighthouse!");
|
Console.WriteLine("Welcome to Project Lighthouse!");
|
||||||
Console.WriteLine("Determining if the database is available...");
|
Console.WriteLine("Determining if the database is available...");
|
||||||
bool dbConnected = ServerSettings.DbConnected;
|
bool dbConnected = ServerSettings.DbConnected;
|
||||||
Console.WriteLine(dbConnected ? "Connected to the database." : "Database unavailable. Exiting.");
|
Console.WriteLine(dbConnected ? "Connected to the database." : "Database unavailable! Exiting.");
|
||||||
|
|
||||||
if(dbConnected) {
|
if(dbConnected) {
|
||||||
Stopwatch migrationStopwatch = new();
|
Stopwatch migrationStopwatch = new();
|
||||||
migrationStopwatch.Start();
|
migrationStopwatch.Start();
|
||||||
|
|
||||||
Console.WriteLine("Migrating database...");
|
Console.WriteLine("Migrating database...");
|
||||||
new Database().Database.Migrate();
|
using Database database = new();
|
||||||
|
database.Database.Migrate();
|
||||||
|
|
||||||
migrationStopwatch.Stop();
|
migrationStopwatch.Stop();
|
||||||
Console.WriteLine($"Migration took {migrationStopwatch.ElapsedMilliseconds}ms");
|
Console.WriteLine($"Migration took {migrationStopwatch.ElapsedMilliseconds}ms.");
|
||||||
} else Environment.Exit(1);
|
} else Environment.Exit(1);
|
||||||
|
|
||||||
startupStopwatch.Stop();
|
startupStopwatch.Stop();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue