What are the challenges you face when working across database platforms? Take the survey
Options

SQL Changeset setup

bhopenwbhopenw Posts: 39
edited June 27, 2009 10:10AM in SQL Compare Previous Versions
Hello,

Is there a way to automatically setup/register workspaces in SQL Changeset.

Ideally, we would like to save a project (.scp) file that compares a Dev DB to the Latest Scripts folder. Add this to soruce control, then when a Dev a has a change he/she can just open of the project and way he/she goes. If the workspace and code is not local it would create it.

While I believe this is not possible, I would like to have a script that I could run that would update the ChangeSet registry, then that Dev could open up the project. This way a dev would only have to run my script to set up the workspace for the project and not have going in SQL Changeset.

Basically, I am looking for a way to have some consentance for Developers, and avoid them have to setup in SQL Changeset all the time. I understand it is a one time thing but for some reason people are have issue with this set up.

Thanks,

BJHop

Comments

  • Options
    Okay,

    It looks this is possible and it shouldn't be all that difficult using powershell.

    We use SQL Changeset (SQLCS) to connect to TFS 2005 sp1

    When SQL Changeset first starts up it adds some elements to the users local Application Data folder (C:\Documents and Settings\bhopenw\Local Settings\Application Data\Red Gate\SQL Changeset). In this directory, there is a xml file named configuration.xml, this is the file use by SQLCS to registery the TFS/SCCI workspaces.

    With that fact found it is truly a simple powershell script to get this working. below is the workflow, I have not finished up the script yet but when I do I will post it.
      * Ensure SQLCS has been started at least once, need to have local app Data section set, if not start it. * Ensure SQLCS is not running, if it is prompt to stop or kill it * Create workspace with mappings set from parameters/config file * Add <PairOfScProviderOpenProjectInfo> node to configuration.xml * start SQLCS

    Where I see this working is we are going to have a common SCP and this script will set up the local environment (workspace) for the developers.

    Thanks,

    BJHop
  • Options
    As I said
    here is the powershell code I created to get the job done
    It will update sql changeset with a new workspace to poll

    I believe it will help us enfore local standards to help work with a local scp file

    This script got a bit more complex than I first thought but I think it works well

    enjoy
    Please let me know if you have any comments or questions
    #Set-SQLChangeset
    #this script set up SQL Changeset for use with a SCP and local workspace
    param&#40;&#91;string&#93; $serverPath = $&#40;throw 'The TFVC server path to DB schema is required'&#41;,
          &#91;string&#93; $localPath = $&#40;throw 'The local path to workspace is required'&#41;,
    	  &#91;string&#93; $tfsUrl = $&#40;'http://as73tfs01:8080'&#41;&#41;
    
    
    ###MAIN###
    $ErrorActionPreference = "Stop"
    
    write-debug "Starting"
    
    #using 
    &#91;void&#93; &#91;Reflection.Assembly&#93;::LoadWithPartialName&#40;"Microsoft.TeamFoundation.Client"&#41;
    &#91;void&#93; &#91;Reflection.Assembly&#93;::LoadWithPartialName&#40;"Microsoft.TeamFoundation.VersionControl.Client"&#41;
    
    #set variables 
    $tfs = New-Object Microsoft.TeamFoundation.Client.TeamFoundationServer&#40;$tfsUrl&#41;
    $vcs = $tfs.GetService&#40;&#91;Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer&#93;&#41;
    $wsCurrent = &#91;Microsoft.TeamFoundation.VersionControl.Client.Workstation&#93;::Current
    
    #may push to this to config file 
    &#91;string&#93; $wsName = "SQLChangeset_" + $&#40;Split-Path $localPath -leaf&#41;
    &#91;string&#93; $path2ConfigXml = "C:\Documents and Settings\$&#40;$env:USERNAME&#41;\Local Settings\Application Data\Red Gate\SQL Changeset\Configuration.xml"
    &#91;string&#93; $path2sqlCs = "C:\Program Files\Red Gate\SQL Compare 8\SQL Changeset\RedGate.SqlChangeset.exe"
    &#91;string&#93; $user = $Env:USERDOMAIN + "\" + $Env:USERNAME
    
    if &#40;-not &#40;Test-Path $path2ConfigXml&#41;&#41;
    &#123;
    	#SQL Changeset has not been started for first time
    	
    	Write-warning "Starting SQL Changeset for first time" 
    	Write-Warning "Please close once started"
    	
    	& $path2sqlCs
    	
    &#125;
    
    #we need to be sure that SQL CS is not running 
    #if it is we need to find out what to do 
    
    while &#40;$&#40;Get-Process | ?&#123;$_.Name -eq 'RedGate.SqlChangeset'&#125;&#41;&#41; 
    &#123;
    	Write-Host "SQL Changeset cannot be running while this process is completed"
    	
    	Write-Host "To exit right-click on the SQL ChangeSet icon in the notification"
    	
    	Write-Host "area  in the right hand side of the status bar where the clock usually is"
    		
    	switch -regex &#40;Read-Host -Prompt "&#91;R&#93; Retry, &#91;K&#93; Kill the process, &#91;A&#93; Abort"&#41;
    	&#123;
    		"R|r"&#123;&#125;
    		"A|a"
    		&#123;
    			write-host -ForegroundColor Red "Abort: Cannot continue with Red Gate SQL Changeset running"
    			return
    		&#125;
    		"K|k"
    		&#123;
    			Write-Warning "Killing the process may have unkown effects on SQLChangeset"
    			switch -regex &#40;Read-Host -Prompt "Are you sure you want to kill the SQL Changeset process &#91;Y/N&#93;"&#41;
    			&#123;
    				"Y|y" 
    				&#123;
    					$sqlcs = $&#40;Get-Process | ?&#123;$_.Name -eq 'RedGate.SqlChangeset'&#125;&#41;
    			
    					$sqlcs.Kill&#40;&#41;
    			
    					sleep -Seconds 5
    				&#125;
    				
    				"N|n"
    				&#123;&#125;
    			&#125;
    			
    		&#125;
    	&#125;
    &#125;
    
    
    
    if &#40;-not &#40;Test-Path $localPath&#41;&#41;
    &#123;
    	New-Item -Path $&#40;Split-Path $localPath -Parent&#41; -Name $&#40;Split-Path $localPath -leaf&#41; -ItemType Directory | Out-Null
    &#125;
    else
    &#123;
    
    	if &#40;$wsCurrent.IsMapped&#40;$localPath&#41;&#41;
    	&#123;
    		Write-Host -ForegroundColor Red "Error: Local path already mapped; $localPath is already mapped on this workstation" 
    		
    		return
    		
    	&#125;
    	
    	
    &#125;
    
    #check to ensure a workspace with same name not already created 
    if&#40;$wsCurrent.GetAllLocalWorkspaceInfo&#40;&#41; | ?&#123;$_.Name -match $wsName&#125;&#41;
    &#123;
    	Write-Host -ForegroundColor Red "Error: workspace name - $wsName - already in use"
    	Write-Host "Workspace name is taken for the local path directory name"
    	return
    &#125;
    
    ##assume directy name is a good name ie DB name
    $ws = $vcs.createworkspace&#40;$wsName&#41;
    
    $ws.map&#40;$serverPath, $localPath&#41;
    
    Write-Debug "Workspace created"
    
    &#91;System.IO.FileInfo&#93; $configXml = Get-Item $path2ConfigXml
    
    Copy-Item -Path $configXml.FullName -Destination $&#40;$configXml.FullName + ".bak"&#41; -Force
    
    &#91;string&#93; $configXmlContents = gc $configXml
    #check to make sure the server path has not already been used 
    Write-Debug "configuration xml backed up"
    
    #search 
    if &#40;$configXmlContents -match "\$serverPath"&#41;
    &#123;
    	Write-Host -ForegroundColor Red "Error: $serverPath already in use in SQL Changeset"
    	Write-Host "Workspace will be deleted"
    	$ws.delete&#40;&#41;
    	return
    &#125;
    
    &#91;xml&#93; $xml = &#91;xml&#93; &#40;gc $configXml&#41;
    
    $projects = $xml.ConfigurationFile.SelectSingleNode&#40;"Projects"&#41;
    
    #need to crate xml elements 
    &#91;System.Xml.XmlElement&#93; $pair = $xml.CreateElement&#40;"PairOfScProviderOpenProjectInfo"&#41;
    &#91;System.Xml.XmlElement&#93; $scp = $xml.CreateElement&#40;"ScProvider"&#41;
    &#91;System.Xml.XmlElement&#93; $scpC = $xml.CreateElement&#40;"ScProvider"&#41;
    &#91;System.Xml.XmlElement&#93; $opi = $xml.CreateElement&#40;"OpenProjectInfo"&#41;
    &#91;System.Xml.XmlElement&#93; $opiC = $xml.CreateElement&#40;"OpenProjectInfo"&#41;
    
    $scpC.SetAttribute&#40;"Name", "Team Foundation Server MSSCCI Provider"&#41;
    $scpC.SetAttribute&#40;"Registry", "SOFTWARE\Microsoft\Team Foundation Server MSSCCI Provider"&#41;
    $scpC.SetAttribute&#40;"Dll", "C:\Program Files\Microsoft Team Foundation Server MSSCCI Provider\TfsMsscciProvider.dll"&#41;
    
    $scp.AppendChild&#40;$scpC&#41;
    
    Write-Debug "Updating configuration xml"
    
    #This is the path SQL CS uses 
    #I think the info it needs to get the workspace object 
    &#91;string&#93; $wsPath = "$tfsUrl/|$wsName|$user"
    
    $opiC.SetAttribute&#40;"LocalPath", $localPath&#41;
    $opiC.SetAttribute&#40;"Name", $serverPath&#41;
    $opiC.SetAttribute&#40;"Path", $wsPath&#41;
    $opiC.SetAttribute&#40;"User", $user&#41;
    
    $opi.AppendChild&#40;$opiC&#41;
    
    $pair.AppendChild&#40;$scp&#41;
    $pair.AppendChild&#40;$opi&#41;
    
    $projects.AppendChild&#40;$pair&#41;
    
    $xml.Save&#40;$configXml.FullName&#41;
    
    Write-Host "SQL Changeset has been successfully updated"
    Write-Host "Starting SQL Changeset"
    & $path2sqlCs
    
    
Sign In or Register to comment.