1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00
bitwarden-server/dev/migrate.ps1

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.7 KiB
PowerShell
Raw Normal View History

#!/usr/bin/env pwsh
# Creates the vault_dev database, and runs all the migrations.
param(
[switch]$all,
[switch]$postgres,
[switch]$mysql,
[switch]$mssql,
[switch]$sqlite,
[switch]$selfhost
)
# Abort on any error
$ErrorActionPreference = "Stop"
2023-01-12 14:59:00 +01:00
if (!$all -and !$postgres -and !$mysql -and !$sqlite) {
$mssql = $true;
}
2023-01-12 14:59:00 +01:00
if ($all -or $postgres -or $mysql -or $sqlite) {
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) {
function Get-UserSecrets {
# The dotnet cli command sometimes adds //BEGIN and //END comments to the output, Where-Object removes comments
# to ensure a valid json
return dotnet user-secrets list --json --project ../src/Api | Where-Object { $_ -notmatch "^//" } | ConvertFrom-Json
}
if ($selfhost) {
$msSqlConnectionString = $(Get-UserSecrets).'dev:selfHostOverride:globalSettings:sqlServer:connectionString'
$envName = "self-host"
} else {
$msSqlConnectionString = $(Get-UserSecrets).'globalSettings:sqlServer:connectionString'
$envName = "cloud"
}
Write-Host "Starting Microsoft SQL Server Migrations for $envName"
dotnet run --project ../util/MsSqlMigratorUtility/ "$msSqlConnectionString"
}
$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])/"
dotnet ef database update
}
Set-Location "$currentDir"