• Stars
    star
    150
  • Rank 240,384 (Top 5 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚙ dbops - Powershell module that provides continuous database deployments on any scale
master development
Build status Build status

DBOps

dbops

DBOps is a Powershell module that provides Continuous Integration/Continuous Deployment capabilities for SQL database deployments. In addition to easy-to-use deployment functions, it provides tracking functionality, ensuring that each script is deployed only once and in due order. It will also grant you with ability to organize scripts into builds and deploy them in a repeatable manner on top of any previously deployed version.

The deployment functionality of the module is provided by DbUp .Net library, which has proven its flexibility and reliability during deployments.

Currently supported RDBMS:

  • SQL Server
  • Oracle
  • PostgreSQL
  • MySQL

In addition it also supports Azure Synapse Analytics SQL Pools (both dedicated and serverless). Be aware that you cannot use the schemaversion table with the serverless SQL Pool - it needs to be explicitly disabled by setting SchemaVersionTable to $null. All scripts deployed in such scenario should be idempotent and re-runnable.

Features

The most notable features of the module:

  • Reliably deploy your scripts in a consistent and repeatable manner
  • Perform ad-hoc deployments with highly customizable deployment parameters
  • Run ad-hoc queries to any supported RDBMS on both Windows and Linux
  • Create ready-to-deploy versioned packages in a single command
  • Brings along all features of CI/CD pipelining functionality: builds, artifact management, deployment
  • Roll back the script (or a whole deployment!) in case of errors
  • Dynamically change your code based on custom variables using #{customVarName} tokens

System requirements

  • Powershell 5.0 or higher

Installation

Using git

git clone https://github.com/dataplat/dbops.git dbops
Import-Module .\dbops

Make sure to have the following modules installed as well:

Using PSGallery (Powershell 5+)

Install-Module dbops

Usage scenarios

  • Ad-hoc deployments of any scale without manual code execution
  • Delivering new version of the database schema in a consistent manner to multiple environments
  • Build/Test/Deploy scenarios inside the Continuous Integration/Continuous Delivery pipeline
  • Dynamic deployment based on modified files in the source folder
  • Versioned package deployment (e.g. Octopus Deployment)

Examples

Simple deployments and ad-hoc queries

Perform plain-text script deployments using a single command:

Install-DBOScript
(click to open the video)

Example code:

# Ad-hoc deployment of the scripts from a folder myscripts
Install-DBOScript -ScriptPath C:\temp\myscripts -SqlInstance server1 -Database MyDB

# Execute a list of files as an Ad-hoc query
Get-ChildItem C:\temp\myscripts | Invoke-DBOQuery -SqlInstance server1 -Database MyDB

Package management

dbops packages

Each package consists of multiple builds and can be easily deployed to the database, ensuring that each build is deployed in proper order and only once.

Add-DBOBuild
(click to open the video)

Example code:

# Deployment using packaging system
New-DBOPackage Deploy.zip -ScriptPath C:\temp\myscripts | Install-DBOPackage -SqlInstance server1 -Database MyDB

# Create new deployment package with predefined configuration and deploy it replacing #{dbName} tokens with corresponding values
New-DBOPackage -Path MyPackage.zip -ScriptPath .\Scripts -Configuration @{ Database = '#{dbName}'; ConnectionTimeout = 5 }
Install-DBOPackage MyPackage.zip -Variables @{ dbName = 'myDB' }

# Adding builds to the package
Add-DBOBuild Deploy.zip -ScriptPath .\myscripts -Type Unique -Build 2.0
Get-ChildItem .\myscripts | Add-DBOBuild Deploy.zip -Type New,Modified -Build 3.0

# Install package using internal script Deploy.ps1 - to use when module is not installed locally
Expand-Archive Deploy.zip '.\MyTempFolder'
.\MyTempFolder\Deploy.ps1 -SqlInstance server1 -Database MyDB

Configurations and defaults

There are multiple configuration options available, including:

  • Configuring default settings
  • Specifying runtime parameters
  • Using configuration files

Get-DBOConfig
(click to open the video)

Example code:

# Setting deployment options within the package to be able to deploy it without specifying options
Update-DBOConfig Deploy.zip -Configuration @{ DeploymentMethod = 'SingleTransaction'; SqlInstance = 'localhost'; Database = 'MyDb2' }
Install-DBOPackage Deploy.zip

# Generating config files and using it later as a deployment template
New-DBOConfig -Configuration @{ DeploymentMethod = 'SingleTransaction'; SqlInstance = 'devInstance'; Database = 'MyDB' } | Export-DBOConfig '.\dev.json'
Get-DBOConfig -Path '.\dev.json' -Configuration @{ SqlInstance = 'prodInstance' } | Export-DBOConfig '.\prod.json'
Install-DBOPackage Deploy.zip -ConfigurationFile .\dev.json

# Invoke package deployment using custom connection string
Install-DBOPackage -Path Deploy.zip -ConnectionString 'Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;'

# Invoke package deployment to an Oracle database OracleDB
Install-DBOPackage -Path Deploy.zip -Server OracleDB -ConnectionType Oracle

# Get a list of all the default settings
Get-DBODefaultSetting

# Change the default SchemaVersionTable setting to null, disabling the deployment journalling by default
Set-DBODefaultSetting -Name SchemaVersionTable -Value $null

# Reset SchemaVersionTable setting back to its default value
Reset-DBODefaultSetting -Name SchemaVersionTable

CI/CD features

dbops CI/CD flow assumes that each package version is built only once and deployed onto every single environment. The successfull builds should make their way as artifacts into the artifact storage, from which they would be pulled again to add new builds into the package during the next iteration.

CI-CD flow

CI/CD capabilities of the module enable user to integrate SQL scripts into a package file using a single command and to store packages in a versioned package repository.

Invoke-DBOPackageCI
(click to open the video)

Example code:

# Invoke CI/CD build of the package MyPackage.zip using scripts from the source folder .\Scripts
# Each execution of the command will only pick up new files from the ScriptPath folder
Invoke-DBOPackageCI -Path MyPackage.zip -ScriptPath .\Scripts -Version 1.0

# Store the package in a DBOps package repository in a folder \\data\repo
Publish-DBOPackageArtifact -Path myPackage.zip -Repository \\data\repo

# Retrieve the latest package version from the repository and install it
Get-DBOPackageArtifact -Path myPackage.zip -Repository \\data\repo | Install-DBOPackage -Server MyDBServer -Database MyDB

Planned for future releases

  • Code analysis: know what kind of code makes its way into the package. Will find hidden sysadmin grants, USE statements and other undesired statements
  • Support for other RDBMS (eventually, everything that DbUp libraries can talk with)
  • Integration with unit tests (tSQLt/Pester/...?)
  • Module for Ansible (right now can still be used as a powershell task)
  • SQLCMD support
  • Deployments to multiple databases at once
  • Optional rollback scripts

Contacts

Submitting issues - GitHub issues

SQLCommunity Slack: https://sqlcommunity.slack.com #dbops or @nvarscar

More Repositories

1

dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
PowerShell
2,345
star
2

dbachecks

✔ SQL Server Environmental Validation
PowerShell
450
star
3

DataSaturdays

A repository for open sourcing a solution for Data Saturdays
HTML
140
star
4

dbaclone

👯 Clone SQL Server databases using PowerShell previously named PSDatabaseClone
PowerShell
127
star
5

dbareports

PowerShell Module to gather, store and report on data about your estate. **This repository has been archived due to no longer being maintained.**
PowerShell
110
star
6

Invoke-SqlCmd2

PowerShell module containing Invoke-SqlCmd2
PowerShell
66
star
7

community-presentations

Presentation Repository for SQL Server / PowerShell Presentations within the Community
Jupyter Notebook
41
star
8

dbatools-templates

Templates for dbatools commands
PowerShell
30
star
9

dbatools-lab

Build a lab environment for testing out dbatools
Jupyter Notebook
22
star
10

mastodon

Where to find Data Platform, PowerShell and Power BI Twitter friends on Mastodon
20
star
11

docker

The code that's used to create the dbatools SQL Server images on Docker Hub.
TSQL
18
star
12

dbadisa

🦅 DISA STIG automation module for SQL Server
PowerShell
16
star
13

docs

The documentation for dbatools module. Issues with command doc and bugs should be reported to dataplat/dbatools.
HTML
14
star
14

ADSNotebook

PowerShell Module for interacting with Azure Data Studio Notebooks
PowerShell
14
star
15

AlwaysEncryptedSample

Sample ASP.NET MVC Application for demonstrating Microsoft SQL Server Always Encrypted Functionality
C#
14
star
16

dbarefresh

🔄 Database refresh module to copy partial data from production to another database
PowerShell
12
star
17

dbasecurityscan

Baseline, check and correct your SQL Database Security
PowerShell
10
star
18

dataplat.github.io

Resources for the SQL Collaborative
HTML
10
star
19

AzureDataPipelineTools

A collection of Azure Function to make building Azure Data Factory pipeline simpler and easier.
C#
9
star
20

dbatools.library

dbatools smo library builder
C#
5
star
21

dbatools-traininglab

a nice lil tutorial to help with useful tutorials
4
star
22

DataSpeakers

A simple repository which can serve as a resource for event owners to find speakers. The data is displayed on https://callfordataspeakers.com/precon and controlled with GitHub Issues and GitHub Actions
Shell
4
star
23

disa-docs

Crowd-sourced Template for SQL Server Documentation as required by DISA
3
star
24

ssis-reporting-pack

3
star
25

dbatools-lab-dotnet-extension

This repo will hold the code to make the Azure Data Studio Extension for the dbatools dotnet interactive Notebooks which enables you to run dbatools against a couple of containers on your machine
Jupyter Notebook
3
star
26

appveyor-lab

repo for full-on appveyor tests
TSQL
2
star
27

AlwaysEncryptedSample.Docs

2
star
28

sqlpsweb

basically a redirector
HTML
2
star
29

dbatools-libary

Source code to the dbatools.dll library utilized by dbatools PowerShell module
C#
2
star
30

dbachecksweb

redirector site for dbachecks.io
HTML
1
star
31

yourrole

Shell
1
star
32

web

dbatools.io website
HTML
1
star