Skip to content

Instantly share code, notes, and snippets.

View Alex-Yates's full-sized avatar

Alex Yates (Personal) Alex-Yates

View GitHub Profile
@Alex-Yates
Alex-Yates / RefreshStagingFromProd.ps1
Created July 22, 2016 10:04
DLM Automation PS scripts: Restore Prod DB over Acceptance DB (run before dry run deployments)
param
(
[Parameter(Mandatory=$true)]
[string]$ProductionDB = $null,
[Parameter(Mandatory=$true)]
[string]$AcceptanceDB = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseServer = $null
)
@Alex-Yates
Alex-Yates / CreateDatabaseRelease.ps1
Last active July 22, 2016 10:10
DLM Automation PS scripts: Create database release from package
param
(
[Parameter(Mandatory=$true)]
[string]$PackageFilePathPattern = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseServer = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseName = $null,
[Parameter(Mandatory=$false)]
[string]$DatabaseUserName = $null,
@Alex-Yates
Alex-Yates / DeployFromDatabaseRelease.ps1
Created July 22, 2016 10:06
DLM Automation PS scripts: Deploy from database release
param
(
[Parameter(Mandatory=$true)]
[string]$PackageFilePathPattern = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseDeploymentResourcesPath = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseServer = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseName = $null,
@Alex-Yates
Alex-Yates / DeployFromDatabase.ps1
Created July 22, 2016 10:08
DLM Automation PS scripts: Deploy from database
param
(
[Parameter(Mandatory=$true)]
[string]$TargetDatabaseServer = $null,
[Parameter(Mandatory=$true)]
[string]$TargetDatabaseName = $null,
[Parameter(Mandatory=$false)]
[string]$TargetDatabaseUserName = $null,
[Parameter(Mandatory=$false)]
[string]$TargetDatabasePassword = $null,
@Alex-Yates
Alex-Yates / DeployFromDatabasePackage.ps1
Created July 22, 2016 10:08
DLM Automation PS scripts: Deploy from database package
param
(
[Parameter(Mandatory=$true)]
[string]$PackageFilePathPattern = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseServer = $null,
[Parameter(Mandatory=$true)]
[string]$DatabaseName = $null,
[Parameter(Mandatory=$false)]
[string]$DatabaseUserName = $null,
# VSTS Redgate Build step does not have a field for DLM Dashboard integration
# However, by running this PS script after your build step you can register the package
# Replace localhost with the DLM Dashboard server
# If using a different port be sure to modify below
# Make sure the NuGet package will match whatever version numbers you are using in your build step
# Set the working directory of the powershell script to the VCS root, where the plugin creates the NuGet package.
$package = Import-DlmDatabasePackage –Path SqlServerCentral1.0.$env:BUILD_BUILDID.nupkg
Publish-DlmDatabasePackage $package –DlmDashboardUrl http://localhost:19528
@Alex-Yates
Alex-Yates / BuildWithDLMAutomation.ps1
Last active December 22, 2016 21:19
A PowerShell script to build, test and deploy your Redgate SQL Source Control scripts folder using the Redgate DLM Automation cmdlets
# Script created 11/11/2016 by Alex Yates of DLM Consultants
# Shared freely, but a beer would be appreciated if you find this useful and we are ever in the same pub
# Full documentation for Redgate DLM Automation PowerShell cmdlets at:
# https://documentation.red-gate.com/display/DLMA2/Cmdlet+reference
# Variables (fill these in)
# Required - the location of your source code
$scriptsFolder = "C:\where\is\your\DB\source\code"
PRINT N'Creating TwilightSparkle database'
CREATE DATABASE TwilightSparkle
GO
USE TwilightSparkle
GO
PRINT N'Creating TwilightSparkle objects:'
PRINT N'Creating [dbo].[tblTheSame]'
CREATE TABLE [dbo].[tblTheSame]
(
[Numbers] [int] NULL,
# This script uses cmdlets from Redgate DLM Automation, which is part of the SQL Toolbelt
# Documentation for these cmdlets is available at:
# https://documentation.red-gate.com/display/DLMA2/Cmdlet+reference
$sourceCode = "Documents/Ponies_dev/state"
$twilightSparkleDb = New-DlmDatabaseConnection -ServerInstance "myServer\myInstance" -Database "TwilightSparkle" | Test-DlmDatabaseConnection
$filterPath = "Documents\Ponies_dev\filters\TwilightSparkle.scpf"
Sync-DlmDatabaseSchema -Source $sourceCode -Target $twilightSparkleDb -filterPath $filterPath
/****** Object: Table [dbo].[tblOnBothButDifferent] Script Date: 24/11/2016 13:58:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblOnBothButDifferent](
[Numbers] [INT] NULL,
[Words] [NVARCHAR](50) NULL,