2021-10-13 19:30:03 +02:00
|
|
|
#!/usr/bin/env pwsh
|
|
|
|
# Creates the vault_dev database, and runs all the migrations.
|
|
|
|
|
2021-11-24 19:08:36 +01:00
|
|
|
# Due to azure-edge-sql not containing the mssql-tools on ARM, we manually use
|
2024-03-13 00:25:20 +01:00
|
|
|
# the mssql-tools container which runs under x86_64.
|
2021-11-24 19:08:36 +01:00
|
|
|
|
2023-01-31 19:41:11 +01:00
|
|
|
param(
|
2024-03-13 00:25:20 +01:00
|
|
|
[switch]$all,
|
|
|
|
[switch]$postgres,
|
|
|
|
[switch]$mysql,
|
|
|
|
[switch]$mssql,
|
|
|
|
[switch]$sqlite,
|
|
|
|
[switch]$selfhost
|
2023-01-31 19:41:11 +01:00
|
|
|
)
|
2022-10-21 18:32:10 +02:00
|
|
|
|
2024-03-13 00:25:20 +01:00
|
|
|
# Abort on any error
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
2023-01-12 14:59:00 +01:00
|
|
|
if (!$all -and !$postgres -and !$mysql -and !$sqlite) {
|
2022-10-21 18:32:10 +02:00
|
|
|
$mssql = $true;
|
|
|
|
}
|
|
|
|
|
2023-01-12 14:59:00 +01:00
|
|
|
if ($all -or $postgres -or $mysql -or $sqlite) {
|
2022-10-21 18:32:10 +02:00
|
|
|
dotnet ef *> $null
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
|
|
Write-Host "Entity Framework Core tools were not found in the dotnet global tools. Attempting to install"
|
|
|
|
dotnet tool install dotnet-ef -g
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($all -or $mssql) {
|
2024-03-13 00:25:20 +01:00
|
|
|
function Get-UserSecrets {
|
|
|
|
return dotnet user-secrets list --json --project ../src/Api | ConvertFrom-Json
|
|
|
|
}
|
|
|
|
|
2023-01-31 19:41:11 +01:00
|
|
|
if ($selfhost) {
|
2024-03-13 00:25:20 +01:00
|
|
|
$msSqlConnectionString = $(Get-UserSecrets).'dev:selfHostOverride:globalSettings:sqlServer:connectionString'
|
|
|
|
$envName = "self-host"
|
|
|
|
|
|
|
|
Write-Output "Migrating your migrations to use MsSqlMigratorUtility (if needed)"
|
|
|
|
./migrate_migration_record.ps1 -s
|
|
|
|
} else {
|
|
|
|
$msSqlConnectionString = $(Get-UserSecrets).'globalSettings:sqlServer:connectionString'
|
|
|
|
$envName = "cloud"
|
|
|
|
|
|
|
|
Write-Output "Migrating your migrations to use MsSqlMigratorUtility (if needed)"
|
|
|
|
./migrate_migration_record.ps1
|
2023-01-31 19:41:11 +01:00
|
|
|
}
|
|
|
|
|
2024-03-13 00:25:20 +01:00
|
|
|
Write-Host "Starting Microsoft SQL Server Migrations for $envName"
|
|
|
|
|
|
|
|
dotnet run --project ../util/MsSqlMigratorUtility/ "$msSqlConnectionString"
|
2022-10-21 18:32:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$currentDir = Get-Location
|
|
|
|
|
2023-01-12 14:59:00 +01:00
|
|
|
Foreach ($item in @(@($mysql, "MySQL", "MySqlMigrations"), @($postgres, "PostgreSQL", "PostgresMigrations"), @($sqlite, "SQLite", "SqliteMigrations"))) {
|
|
|
|
if (!$item[0] -and !$all) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Starting $($item[1]) Migrations"
|
|
|
|
Set-Location "$currentDir/../util/$($item[2])/"
|
2022-10-21 18:32:10 +02:00
|
|
|
dotnet ef database update
|
|
|
|
}
|
|
|
|
|
|
|
|
Set-Location "$currentDir"
|