-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSet-EndpointsDev.ps1
More file actions
57 lines (45 loc) · 1.93 KB
/
Set-EndpointsDev.ps1
File metadata and controls
57 lines (45 loc) · 1.93 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
53
54
55
56
57
<#
.SYNOPSIS
The script updates terminal hostname in the database to prepare it for integration testing.
Called during CI process for non-Dev/Master builds.
#>
param(
[Parameter(Mandatory = $true)]
[string]$connectionString,
[Parameter(Mandatory = $true)]
[string]$newHostname,
[Parameter(Mandatory = $false)]
[string]$overrideDbName
)
Write-Host "Update terminal URLs to $newHostname"
# Note: this script will incorrectly replace hostanames for a non-Fr8 terminals
# if it contains port number. To avoid that we need to add the column IsFr8OwnTerminal
# like done in the TerminalRegistration table.
$commandText = "
-- Update hostname only if port value is present in endpoint URL and terminal belongs to Fr8
UPDATE Terminals SET [Endpoint] =
('$newHostname' + RIGHT ([Endpoint], CHARINDEX (':', REVERSE ([Endpoint]))))
WHERE CHARINDEX (':', REVERSE ([Endpoint])) <= 6
"
Write-Host $commandText
if ([System.String]::IsNullOrEmpty($overrideDbName) -ne $true) {
$builder = new-object system.data.SqlClient.SqlConnectionStringBuilder($connectionString)
$builder["Initial Catalog"] = $overrideDbName
$connectionString = $builder.ToString()
}
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$command = new-object system.data.sqlclient.sqlcommand($commandText, $connection)
$connection.Open()
$command.CommandTimeout = 20 #20 seconds
$command.ExecuteNonQuery()
$commandText = "
-- Update hostname only if port value is present in endpoint URL and terminal belongs to Fr8
UPDATE TerminalRegistration SET [Endpoint] =
('$newHostname' + RIGHT ([Endpoint], CHARINDEX (':', REVERSE ([Endpoint]))))
WHERE CHARINDEX (':', REVERSE ([Endpoint])) <= 6 AND IsFr8OwnTerminal = 1
";
$command = new-object system.data.sqlclient.sqlcommand($commandText, $connection)
$command.CommandTimeout = 20 #20 seconds
$command.ExecuteNonQuery()
Write-Host "Successfully updated terminal hostname."
$connection.Close()