|
|
@ -13,11 +13,13 @@ $projectPath = Resolve-Path (Join-Path $PSScriptRoot "..") |
|
|
$dbContexts = @{ |
|
|
$dbContexts = @{ |
|
|
"1" = @{ |
|
|
"1" = @{ |
|
|
Name = "LY.MicroService.Applications.Single.EntityFrameworkCore.MySql" |
|
|
Name = "LY.MicroService.Applications.Single.EntityFrameworkCore.MySql" |
|
|
Factory = "SingleMySqlDbContextFactory" |
|
|
Context = "SingleMigrationsDbContext" |
|
|
|
|
|
Factory = "SingleMigrationsDbContextFactory" |
|
|
} |
|
|
} |
|
|
"2" = @{ |
|
|
"2" = @{ |
|
|
Name = "LY.MicroService.Applications.Single.EntityFrameworkCore.PostgreSql" |
|
|
Name = "LY.MicroService.Applications.Single.EntityFrameworkCore.PostgreSql" |
|
|
Factory = "SinglePostgreSqlDbContextFactory" |
|
|
Context = "SingleMigrationsDbContext" |
|
|
|
|
|
Factory = "SingleMigrationsDbContextFactory" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -76,7 +78,7 @@ function Invoke-DatabaseMigration($dbContext, $migrationName) { |
|
|
# Switch to project directory and execute migration |
|
|
# Switch to project directory and execute migration |
|
|
Push-Location $projectPath |
|
|
Push-Location $projectPath |
|
|
try { |
|
|
try { |
|
|
dotnet ef migrations add $migrationName --project "migrations/$($dbContext.Name)" --context "$($dbContext.Name)DbContext" |
|
|
dotnet ef migrations add $migrationName --project "migrations/$($dbContext.Name)" --context "$($dbContext.Context)" |
|
|
} |
|
|
} |
|
|
finally { |
|
|
finally { |
|
|
Pop-Location |
|
|
Pop-Location |
|
|
@ -87,7 +89,7 @@ function Invoke-DatabaseMigration($dbContext, $migrationName) { |
|
|
function Get-AllMigrations($dbContext) { |
|
|
function Get-AllMigrations($dbContext) { |
|
|
Push-Location $projectPath |
|
|
Push-Location $projectPath |
|
|
try { |
|
|
try { |
|
|
$migrations = @(dotnet ef migrations list --project "migrations/$($dbContext.Name)" --context "$($dbContext.Name)DbContext") |
|
|
$migrations = @(dotnet ef migrations list --project "migrations/$($dbContext.Name)" --context "$($dbContext.Context)") |
|
|
return $migrations | Where-Object { $_ -match '\S' } # Filter empty lines |
|
|
return $migrations | Where-Object { $_ -match '\S' } # Filter empty lines |
|
|
} |
|
|
} |
|
|
finally { |
|
|
finally { |
|
|
@ -170,10 +172,10 @@ function Export-SqlScript($dbContext, $migrationName) { |
|
|
Push-Location $projectPath |
|
|
Push-Location $projectPath |
|
|
try { |
|
|
try { |
|
|
if ($fromMigration) { |
|
|
if ($fromMigration) { |
|
|
dotnet ef migrations script $fromMigration --project "migrations/$($dbContext.Name)" --context "$($dbContext.Name)DbContext" --output $sqlFilePath |
|
|
dotnet ef migrations script $fromMigration --project "migrations/$($dbContext.Name)" --context "$($dbContext.Context)" --output $sqlFilePath |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
dotnet ef migrations script --project "migrations/$($dbContext.Name)" --context "$($dbContext.Name)DbContext" --output $sqlFilePath |
|
|
dotnet ef migrations script --project "migrations/$($dbContext.Name)" --context "$($dbContext.Context)" --output $sqlFilePath |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
finally { |
|
|
finally { |
|
|
|