
USE ION_Data

DECLARE @OldName nvarchar (100)
DECLARE @newName nvarchar (100)

-- put in your IONE6 and PME server names where indicated
SET @oldName = 'Original_Server_Name'
SET @newName = 'New_Server_Name'

-- update Source table

UPDATE SOURCE
SET Name = 'LOGINSERTER.' + @newName
WHERE Name = 'LOGINSERTER.' + @oldName

UPDATE SOURCE
SET Name = 'QUERYSERVER.' + @newName
WHERE Name = 'QUERYSERVER.' + @oldName

UPDATE SOURCE
SET Name = 'VIP.' + @newName
WHERE Name = 'VIP.' + @oldName

UPDATE SOURCE
SET DisplayName = 'LOGINSERTER.' + @newName
WHERE Name = 'LOGINSERTER.' + @oldName

UPDATE SOURCE
SET DisplayName = 'QUERYSERVER.' + @newName
WHERE DisplayName = 'QUERYSERVER.' + @oldName

UPDATE SOURCE
SET DisplayName = 'VIP.' + @newName
WHERE DisplayName = 'VIP.' + @oldName


USE ION_Network
--Update the server. Note that it will change all the servers with given machine name. 
--Hence will not work where multiple servers are configured in PME. 
Update Machine SET Name = @newName
Update Gate SET Enabled = 1, Name = @newName, Address = @newName WHERE TYPE = 'COMPUTER'
Update SoftwareNode SET Name = 'TREEMON.'+ @newName where SoftwareNodeTypeID=9

-- update CFG_ITemValue table

UPDATE CFG_ItemValue
SET Value = 'http://' + @newName + '/ionreportdataservice/ReportDataService.asmx'
WHERE Value = 'http://' + @oldName + '/ionreportdataservice/ReportDataService.asmx'

-- update IRM_DeviceInfo table

UPDATE IRM_DeviceInfo
SET Name = 'LOGINSERTER.' + @newName
WHERE Name = 'LOGINSERTER.' + @oldName

UPDATE IRM_DeviceInfo
SET Name = 'QUERYSERVER.' + @newName
WHERE Name = 'QUERYSERVER.' + @oldName

UPDATE IRM_DeviceInfo
SET Name = 'VIP.' + @newName
WHERE Name = 'VIP.' + @oldName

-- update Softwarenode table

UPDATE SoftwareNode
SET Name = 'LOGINSERTER.' + @newName
WHERE Name = 'LOGINSERTER.' + @oldName

UPDATE SoftwareNode
SET Name = 'LOGINSERTER.' +  @newName + '_FAST_LINKER'
WHERE Name = 'LOGINSERTER.' + @oldName + '_FAST_LINKER'

UPDATE SoftwareNode
SET Name = 'QUERYSERVER.' + @newName
WHERE Name = 'QUERYSERVER.' + @oldName

UPDATE SoftwareNode
SET Name = 'VIP.' + @newName
WHERE Name = 'VIP.' + @oldName

-- clean up the other software node names
-- new ones will be created

DELETE FROM softwarenode
WHERE Name like '%' + @oldName

-- update SRC_Source
UPDATE SRC_SOURCE
SET Name = 'LOGINSERTER.' + @newName
WHERE Name = 'LOGINSERTER.' + @oldName

UPDATE SRC_SOURCE
SET Name = 'QUERYSERVER.' + @newName
WHERE Name = 'QUERYSERVER.' + @oldName

UPDATE SRC_SOURCE
SET Name = 'VIP.' + @newName
WHERE Name = 'VIP.' + @oldName

UPDATE SRC_SOURCE
SET DisplayName = 'LOGINSERTER.' + @newName
WHERE DisplayName = 'LOGINSERTER.' + @oldName

UPDATE SRC_SOURCE
SET DisplayName = 'QUERYSERVER.' + @newName
WHERE DisplayName = 'QUERYSERVER.' + @oldName

UPDATE SRC_SOURCE
SET DisplayName = 'VIP.' + @newName
WHERE DisplayName = 'VIP.' + @oldName

-- IAS_MeasurementAddress
DELETE FROM IAS_MeasurementAddress WHERE Segment2 like 'VIP%' 
AND ISManual = 0

USE ApplicationModules

--Relook. Change the hard coded key IDs
UPDATE Configuration.ConfigurationValue SET value = REPLACE (value, @oldName,@newName) WHERE ConfigurationKeyId = 36
UPDATE Configuration.ConfigurationValue SET value = REPLACE (value, @oldName,@newName) WHERE ConfigurationKeyId = 37

--As of 7.2.2 Appmods only connects to single PME server.
UPDATE Inventory.ApplicationServer SET Name=@newName WHERE ServerId = 1