Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

55 Zeilen
2.1KB

  1. [CmdletBinding()]
  2. param(
  3. [Parameter(Mandatory = $true)][string]$ServerInstance,
  4. [Parameter(Mandatory = $true)][string]$SqlLogin,
  5. [Parameter(Mandatory = $true)][SecureString]$SqlPassword,
  6. [string]$DatabaseName = 'WscMvcTest'
  7. )
  8. # Idempotent: creates the M5 integration test database and its one table if
  9. # missing, does nothing if they already exist. This is a deliberate, explicit
  10. # deployment step (SPEC SS10/SS9: "no broad filesystem/DB write privileges";
  11. # a web request must never create schema) - never called from Default.asp or
  12. # any WSC, only from this tool. Credentials are supplied as parameters at
  13. # invocation time, never embedded in this (tracked) script - see
  14. # docs/DECISIONS.md for where the actual secret lives. SqlPassword is a
  15. # SecureString and is only ever converted to plain text in the narrow window
  16. # where sqlcmd.exe (an external process with no SecureString-aware API)
  17. # actually needs it as a command-line argument.
  18. $ErrorActionPreference = 'Stop'
  19. $plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringUni(
  20. [Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($SqlPassword)
  21. )
  22. $createDbSql = @"
  23. IF DB_ID(N'$DatabaseName') IS NULL
  24. BEGIN
  25. CREATE DATABASE [$DatabaseName];
  26. END
  27. "@
  28. $createTableSql = @"
  29. IF OBJECT_ID(N'dbo.Widgets', N'U') IS NULL
  30. BEGIN
  31. CREATE TABLE dbo.Widgets (
  32. Id INT IDENTITY(1,1) PRIMARY KEY,
  33. Name NVARCHAR(100) NOT NULL
  34. );
  35. END
  36. "@
  37. try {
  38. Write-Output "Ensuring database [$DatabaseName] exists on $ServerInstance ..."
  39. sqlcmd -S $ServerInstance -U $SqlLogin -P $plainPassword -d master -Q $createDbSql -b
  40. if ($LASTEXITCODE -ne 0) { throw "sqlcmd failed creating database (exit $LASTEXITCODE)" }
  41. Write-Output "Ensuring dbo.Widgets table exists ..."
  42. sqlcmd -S $ServerInstance -U $SqlLogin -P $plainPassword -d $DatabaseName -Q $createTableSql -b
  43. if ($LASTEXITCODE -ne 0) { throw "sqlcmd failed creating table (exit $LASTEXITCODE)" }
  44. } finally {
  45. $plainPassword = $null
  46. }
  47. Write-Output "Test database ready: [$DatabaseName] on $ServerInstance (table dbo.Widgets)."

Powered by TurnKey Linux.