Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #13 from Iristyle/getsqldatabases

Added Get-SqlDatabases and Get-BranchName
  • Loading branch information...
commit aa0059f5fb46c5e86deea5980bdd8a650993331e 2 parents 4219da9 + aac61e4
@Iristyle authored
View
5 Midori.nuspec
@@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>Midori</id>
- <version>0.4.4.0</version>
+ <version>0.4.5.0</version>
<title>Midori - Sweeter Psake builds</title>
<authors>Ethan Brown</authors>
<owners>Ethan Brown</owners>
@@ -17,9 +17,12 @@
* Jenkins - Download assets stored in S3
* XUnit - Runs xunit tests and merges nunit output files for build servers, can create standalone xunit project files
* Misc helpers - Safer transcription, better error logging, create 7z/zip/tar files, and other common usage helpers
+ * Source Control - Retrieve current branch name
</description>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>
+ * 0.4.5.0 - Added Get-SqlDatabases cmdlet for listing databases on a server
+ Added Get-BranchName cmdlet to list the current branch
* 0.4.4.0 - Bug fixes for loading SQL module in PowerShell v3
Invoke-SqlFileSmo ate exceptions instead of rethrowing them
New-SqlDatabase was not honoring UserAccess setting
View
9 README.md
@@ -81,7 +81,7 @@ $buildPackageDir = Join-Path (Get-CurrentDirectory) 'packages'
$sourcePackageDir = Join-Path (Get-CurrentDirectory) '..\src\Packages'
@(@{Id = 'psake'; Version='4.2.0.1'; Dir = $buildPackageDir; NoVersion = $true },
- @{Id = 'Midori'; Version='0.4.4.0'; Dir = $buildPackageDir; NoVersion = $true },
+ @{Id = 'Midori'; Version='0.4.5.0'; Dir = $buildPackageDir; NoVersion = $true },
#still require dotnetZip to extract the 7-zip command line, sigh
@{Id = 'DotNetZip'; Version='1.9.1.8'; Dir = $buildPackageDir; NoVersion = $true },
@{Id = 'xunit.runners'; Version='1.9.1'; Dir = $buildPackageDir; NoVersion = $true }) |
@@ -213,9 +213,16 @@ setting up integration tests or similar.
* `Copy-SqlDatabase` - Provides either a backup/restore of an existing
database, or a transfer. By default, provides the simpler backup/restore
which is generally all that would ever be necessary on a build server.
+ * `Get-SqlDatabases` - Lists the database names on a given instance / server.
+* SourceControl - Some helpers for working with distributed source systems such
+as Git or Mercurial.
+ * `Get-BranchName` - Returns the current branch name for the current working
+ directory, should one exist.
### Release Notes
+* 0.4.5.0 - Added Get-SqlDatabases cmdlet for listing databases on a server
+Added Get-BranchName cmdlet to list the current branch
* 0.4.4.0 - Bug fixes for loading SQL module in PowerShell v3
Invoke-SqlFileSmo ate exceptions instead of rethrowing them
New-SqlDatabase was not honoring UserAccess setting
View
30 tools/SourceControl.psm1
@@ -0,0 +1,30 @@
+function Get-BranchName
+{
+<#
+.Synopsis
+ Will return the current branch name if the current directory is a Git
+ or Mercurial repository.
+
+ Returns null otherwise.
+.Description
+ For Git, uses rev-parse command, and for Mercurial uses the branch
+ command.
+.Example
+ Get-BranchName
+
+ Description
+ -----------
+ Will execute against the local directory, returning the branch name if
+ there is one. Returns null otherwise.
+#>
+
+ $branch = git rev-parse --symbolic-full-name --abbrev-ref HEAD 2> $null
+ if (!$branch)
+ {
+ $branch = hg branch 2> $null
+ }
+
+ return $branch
+}
+
+Export-ModuleMember -Function Get-BranchName
View
67 tools/Sql.psm1
@@ -854,6 +854,71 @@ function Remove-SqlDatabase
}
}
+function Get-SqlDatabases
+{
+<#
+.Synopsis
+ Will read the list of databases from a given server instance.
+.Description
+ The given service is checked to ensure it's running and then the script
+ is executed, to get the list of databases.
+
+ Requires that SMO and some SQL server be installed on the local machine
+.Parameter ServiceName
+ The name of the SQL Server service name - will default to
+ MSSQL$SQLEXPRESS if left unspecified.
+.Parameter InstanceName
+ The name of the SQL server instance. By default, .\SQLEXPRESS
+.Parameter IncludeSystem
+ Optionally includes the system databases in the list as well.
+.Example
+ Get-SqlDatabases
+
+ Description
+ -----------
+ Will use the default localhost SQLEXPRESS instance and will list all
+ attached databases.
+.Example
+ Get-SqlDatabases -IncludeSystem
+
+ Description
+ -----------
+ Will use the default localhost SQLEXPRESS instance and will list all
+ attached databases, including system databases such as master.
+
+#>
+ param(
+ [Parameter(Mandatory=$false)]
+ [string]
+ $ServiceName = 'MSSQL$SQLEXPRESS',
+
+ [Parameter(Mandatory=$false)]
+ [string]
+ $InstanceName = '.\SQLEXPRESS',
+
+ [Parameter(Mandatory=$false)]
+ [switch]
+ $IncludeSystem = $false
+ )
+
+ Load-Types
+ Start-ServiceAndWait $ServiceName
+
+ Write-Host "Listing databases on $InstanceName"
+ try
+ {
+ $server = New-Object Microsoft.SqlServer.Management.Smo.Server($InstanceName)
+
+ return $server.Databases |
+ ? { if (!$IncludeSystem) { !$_.IsSystemObject } else { $true } } |
+ Select -ExpandProperty Name
+ }
+ finally
+ {
+ if ($server) { $server.ConnectionContext.Disconnect() }
+ }
+}
+
function Invoke-SqlFileSmo
{
<#
@@ -1048,4 +1113,4 @@ function Invoke-SqlFileSmo
Export-ModuleMember -Function New-SqlDatabase, Invoke-SqlFileSmo,
Remove-SqlDatabase, Copy-SqlDatabase, Transfer-SqlDatabase, Backup-SqlDatabase,
- Restore-SqlDatabase
+ Restore-SqlDatabase, Get-SqlDatabases
View
2  tools/build.ps1
@@ -53,7 +53,7 @@ $buildPackageDir = Join-Path (Get-CurrentDirectory) 'packages'
$sourcePackageDir = Join-Path (Get-CurrentDirectory) '..\src\Packages'
@(@{Id = 'psake'; Version='4.2.0.1'; Dir = $buildPackageDir; NoVersion = $true },
- @{Id = 'Midori'; Version='0.4.4.0'; Dir = $buildPackageDir; NoVersion = $true },
+ @{Id = 'Midori'; Version='0.4.5.0'; Dir = $buildPackageDir; NoVersion = $true },
#still require dotnetZip to extract the 7-zip command line, sigh
@{Id = 'DotNetZip'; Version='1.9.1.8'; Dir = $buildPackageDir; NoVersion = $true },
@{Id = 'xunit.runners'; Version='1.9.1'; Dir = $buildPackageDir; NoVersion = $true }) |
Please sign in to comment.
Something went wrong with that request. Please try again.