-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFreshMigration.ps1
More file actions
52 lines (40 loc) · 1.6 KB
/
FreshMigration.ps1
File metadata and controls
52 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# This script resets the EF Core database to a fresh state.
$projectPath = "src\OpenRP.Boilerplate"
$migrationsPath = "$projectPath\Migrations"
$buildPath = "src\OpenRP.Boilerplate\Server\gamemode\Debug\net6.0"
$initialMigrationName = "InitialCreate"
Write-Host "Checking for EF Core CLI tool..."
$efInstalled = dotnet tool list -g | Select-String "dotnet-ef"
if (-not $efInstalled) {
Write-Host "EF Core CLI not found. Installing..."
dotnet tool install --global dotnet-ef
} else {
Write-Host "EF Core CLI found. Updating to ensure latest version..."
dotnet tool update --global dotnet-ef
}
# Navigate to the project path
Set-Location -Path $projectPath
# Build the project
Write-Host "Building the project..."
dotnet build --configuration Debug
# Ensure the migrations folder exists inside the project
if (Test-Path $migrationsPath) {
Write-Host "Removing existing migrations..."
Remove-Item -Recurse -Force $migrationsPath
}
New-Item -ItemType Directory -Path $migrationsPath | Out-Null
# Drop the database
Write-Host "Dropping the database..."
dotnet ef database drop --force --verbose
# Ensure no existing migrations interfere
Write-Host "Removing any existing migrations (if any)..."
dotnet ef migrations remove --force
# Create a fresh migration (inside the default project migrations folder)
Write-Host "Creating a new migration..."
dotnet ef migrations add $initialMigrationName
# Apply the migration
Write-Host "Applying migration to recreate the database..."
dotnet ef database update
Write-Host "Database reset complete!"
# Restore original working directory
Set-Location -Path $PSScriptRoot