C
C#2y ago
Indeed

DotnetCLI Get Project Root Path - Database Recreation Script

Set-Location (get-item $PSScriptRoot).Parent.Parent.FullName
dotnet ef database drop --context LogDbContext
dotnet ef migrations remove --context LogDbContext
$dbPath = Join-Path $PSScriptRoot \LogDatabase.sqlite
$dbExists = Test-Path -Path $dbPath -PathType Leaf
if ($($dbExists)) {
(Get-ChildItem $($dbPath)).Delete()
}
dotnet ef migrations add Initial -o ./Logging/Database/Migrations --context LogDbContext
dotnet ef database update --connection "Data Source=$($PSScriptRoot)\LogDatabase.sqlite" --context LogDbContext
Set-Location (get-item $PSScriptRoot).Parent.Parent.FullName
dotnet ef database drop --context LogDbContext
dotnet ef migrations remove --context LogDbContext
$dbPath = Join-Path $PSScriptRoot \LogDatabase.sqlite
$dbExists = Test-Path -Path $dbPath -PathType Leaf
if ($($dbExists)) {
(Get-ChildItem $($dbPath)).Delete()
}
dotnet ef migrations add Initial -o ./Logging/Database/Migrations --context LogDbContext
dotnet ef database update --connection "Data Source=$($PSScriptRoot)\LogDatabase.sqlite" --context LogDbContext
This is my sqlite database recreation script. I would like to change the first line to rather than go two levels up (script rn is in Project/Logging/Database) get somehow the project path (later i'll add the if checks for 2nd and 3rd line)
1 Reply
Indeed
Indeed2y ago
I'll also in the future will be adding the ability to config database name on the first run, and the context And I have to do all that just because EFCore does not have EF6 dropcreateDatabaseAlways