Red Gate forums :: View topic - Run any sql script (from a web server)
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation

Deployment Manager PowerShell Scripts forum

Run any sql script (from a web server)

Search in Deployment Manager PowerShell Scripts forum
Post new topic   Reply to topic
Jump to:  
Author Message
jtucker@inflexxion.com



Joined: 27 Jun 2013
Posts: 12
Location: Boston

PostPosted: Mon Jan 13, 2014 2:09 pm    Post subject: Run any sql script (from a web server) Reply with quote

Prerequisite: Install of SQLPS.

Code:
$ElapsedStopWatch = [System.Diagnostics.Stopwatch]::StartNew()
# $RedGatePackageDirectoryPath is the On Deck Circle where the package is initial extracted.
# http://powershell.com/cs/forums/t/13752.aspx
if ([string]::IsNullOrEmpty($RedGatePackageDirectoryPath))
{
   $RedGatePackageDirectoryPath = "D:\On Deck Circle\MigrationScript"   
}

"The package binaries are in " + $RedGatePackageDirectoryPath | Write-Host
"Running migration script for environment " + $RedGateEnvironmentName | Write-Host


if ($IsRollback.ToLower() -eq "true")
{
   "Rolling the Data synch for " + $RedGateEnvironmentName | Write-Host
   
   if ([string]::IsNullOrEmpty($ApplicationRollbackPath))
   {
      $ApplicationRollbackPath = "D:\ApplicationRollback\MigrationScript"
   }
   
   "The backup directory is " + $ApplicationRollbackPath | Write-Host
   set-location $ApplicationRollbackPath
   get-location
   $out = $RedGatePackageDirectoryPath   + "\" + "UnDoMigration.log"
   $inputFile = $RedGatePackageDirectoryPath + "\" + $UnDoMigrationScript
   invoke-sqlcmd -ServerInstance $TargetSqlServer -Database $TargetDatabaseName -InputFile $inputFile | format-table | out-file -filePath $out
}
else
{
   "Deploying Data Synch to "  + $RedGateEnvironmentName | Write-Host
   # these steps are crucial
   set-location $RedGatePackageDirectoryPath
   get-location
   
   $out = $RedGatePackageDirectoryPath   + "\" + "DoMigration.log"
   $inputFile = $RedGatePackageDirectoryPath + "\" + $DoMigrationScript
   invoke-sqlcmd -ServerInstance $TargetSqlServer -Database $TargetDatabaseName -InputFile $inputFile | format-table | out-file -filePath $out
   Copy-Item $RedGatePackageDirectoryPath $ApplicationRollbackPath -force -recurse
}
# Stop the timer
$elapsedTime = $ElapsedStopWatch.Elapsed.ToString()
$elapsedTime | Write-Host
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group