DataCCIW

RockTestPrepCCIW

Nov 9th, 2022 (edited)
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 3.45 KB | None | 0 0
  1. ----------------------------------------------------------------------------------------
  2. -- Customized by: Tony Visconti
  3. -- Original Draft: 11-4-22
  4. -- Purpose: Take a copy of a rock production database and prepare it for use in a test environment
  5. -- This is a derivation and aggregation of work from several members in the rock community
  6. -- The original script this came from is hosted here: https://bit.ly/3TlVbzS
  7. ----------------------------------------------------------------------------------------
  8.  
  9. -- IMPORTANT --
  10. -- USE THE BELOW SQL TO TAKE A PREVIOUSLY RESTORED SQL DATABASE AND MAKE IT USABLE FOR SANDBOX, DEV, OR TEST USAGE --
  11. -- IMPORTANT --
  12.  
  13. --
  14. -- Deactivate all Service Jobs except: Job Pulse
  15. --
  16.  
  17. DECLARE @CheckIsDev INT = (Select CASE WHEN DB_NAME() Like 'rock-dev%' THEN 1 ELSE 0 END)
  18.  
  19. IF @CheckIsDev = 1
  20. BEGIN
  21.  
  22. UPDATE [ServiceJob] SET [IsActive] = 0
  23.  
  24. UPDATE [ServiceJob] SET [IsActive] = 'True' WHERE [Name] IN ('Job Pulse', 'Calculate Metrics', 'Group Sync', 'Spark Link',
  25.  'Rock Cleanup', 'Calculate Group Requirements', 'Check for New Plugins', 'Update Persisted DataViews', 'Database Maintenance', 'Renew Certificates')
  26.  
  27. -- Append .test to Email ADDRESSES that are NON-SYSTEM, NON-CALVARY, NOT BLANK, NOT NULL EMAIL ADDRESSES --
  28. -- LIKE is case-insensitive
  29. BEGIN
  30.     UPDATE [Person]
  31. set [Email] = CONCAT([Email],'.test')
  32. WHERE [Email] IS NOT NULL AND [Email] NOT LIKE '%@example.com' and [Email] != '' AND IsSystem != 1
  33. END
  34.  
  35. --
  36. -- Update OrganizationWebSite
  37. --
  38. DECLARE @OrganizationWebSiteId int = (SELECT Id
  39. from [Attribute]
  40. WHERE [Key] = 'OrganizationWebSite')
  41. UPDATE [AttributeValue]
  42. SET [Value] = 'dev.example.com'
  43. WHERE [AttributeId] = @OrganizationWebSiteId
  44.  
  45. --
  46. -- Update PublicationApplicationRoot to Test
  47. --
  48. DECLARE @PublicApplicationRootId int = (select Id
  49. from
  50.     [Attribute]
  51. WHERE [Key] = 'PublicApplicationRoot')
  52. UPDATE [AttributeValue]
  53. SET [Value] = 'dev.example.com'
  54. WHERE [AttributeId] = @PublicApplicationRootId
  55.  
  56. --
  57. -- Update PublicationApplicationRoot to Test
  58. --
  59. DECLARE @InternalApplicationRoot int = (select Id
  60. from
  61.     [Attribute]
  62. WHERE [Key] = 'InternalApplicationRoot')
  63. UPDATE [AttributeValue]
  64. SET [Value] = 'https://rockdev.example.com'
  65. WHERE [AttributeId] = @InternalApplicationRoot
  66.  
  67. --
  68. -- Update SiteDomains
  69. --
  70. UPDATE [SiteDomain]
  71. SET [Domain] = 'dev.example.com'
  72. WHERE [Domain] = 'example.com'
  73.  
  74. -- Other scripts I reviewed include the following I choose to not include
  75. -- Recreate RockUser so it points to the current server's Logins
  76. -- With our azure database setup this is not required
  77.  
  78. -- a ufnUtility_RemoveNonAlphaCharacters function
  79. -- this is used to update email addresses to nickname+lastname@safety.netz
  80. -- I choose to simply append .test to most email addresses instead and did not need the utility function
  81.  
  82. -- ADD 'TEST' BANNER -
  83. -- We have a test banner whose code exists in our production database. This code produces the banner on both the internal and external site
  84. --  when the PublicApplicationRoot global attribute contains the word dev
  85.  
  86. -- TURN OFF SSL FOR ALL PAGES & Sites --
  87. -- We use SSL in our dev environment
  88.  
  89. -- DEACTIVATE ALL MAIL TRANSPORTS --
  90. -- Our Rock transport for mail has a mode called When in Development mode
  91. -- Development mode: outgoing & incoming mail will be held and only visible in the web interface and will not be sent to any recipients or HTTP endpoints.
  92. -- We use this feature to prevent unwanted mail from being delivered by our dev environment
Add Comment
Please, Sign In to add comment