SlideShare a Scribd company logo
Developing, Building and
Releasing databases with
SSDT and
Taavi Koosaar
DevOps Consultant | VS ALM MVP | VS ALM
Ranger
Agenda
• Concepts
• Development
• Build
• Release
Concepts
Development and deployment models
• Manual scripts, combine and run
– Write the scripts manually and run them in correct sequence
• Model based deployment
– Compare two schemas and apply difference
• Migration based deployment
– Apply all changes since the last migration
– E.g. EF migration
The SSDT tooling
DACFx
SqlPackageSSMSSSDT
Visual Studio
SQL DBdacpac
SQL Client
SSDT 2016 July and forward
DAC framework
• The component /framework that makes deployment
possible
– Model, deployment and api
– SqlPackage.exe
– Data Tier Applications
• Comes with SSDT and SQL Server (can also be
separately installed)
• Compatible downwards
• Not everything of SQL is supported
– https://msdn.microsoft.com/en-us/library/ee210549.aspx
SSDT in Visual Studio
• SQL Server Object Explorer – connected / offline dev
• SQL Database project structure, references and daily
work
– Incl code analytics, intellisense, refactoring
• SQL Schema Compare | Data Compare
• Pre-Build, Post-Build and Pre-DacPac, Post-DacPac
– Reference data scripts
• DACPAC, BACPAC and Publish/Deployment
– Settings, sqlcmd variables
• Refactor log
SQL Database project
• Everything you plan to deploy to database and
everything you are referencing should be there
– Except the few things you may not want to e.g. logins, roles
• Project & Database references
– Composite projects
• (SQL CMD) Variables
• Code Analysis rules
• Snapshots
Composite projects
• Reference external databases
• Break up a larger database into logical units
• Separate by schema / functional area
• Decrease build time – build smaller pieces
Composite project references
SQL
DB
dacpac
My DB Project
Artefacts
Artefacts
Artefacts
Artifacts
My Other
DB Project
data-tier
application
system database
project
Same Database
Same Server, Different
Database
Different Server, Different
Database
master
msdb
What is a DacPac?
• A zip file
• Result of the build of database project
• Contains the model / schema / refactorings
• Contains the pre and post deployment combined scripts
• Versioned
DacPac deployment flow (per DacPac)
Deploy
Schema
Comparison
Script
generation
(delta)
Execute Pre
Deployment
Execute
generated
script
Execute Post
Deployment
Development
Getting started with database project
• Import existing database into database project
– From database
– From dacpac (e.g. that came from production)
• First time, you will hit and find a lot of …
– Invalid objects - Old objects referencing non-existent columns /
encrypted objects / invalid synonyms / cross database
references / circular references / unsupported objects for target
platform
• Engage a Subject Matter Expert: Talk to your DBA to help clean up
these issues
Getting started with database project
• Validation turned on
– Turn validation off for initial import!
– Use the latest version of the tools!
– Import everything and fix issues within Visual Studio
• SSDT imports the first 1000 stored procedures into
Procs1, the next into Procs2 etc
– You may need to add some folder structure to your project to
keep developers sane.
– Having many 1000’s of objects affects SSDT performance
Enhanced DacPac deployment flow
1. Database backup
2. Pre DacPac deployment scripts
3. Dacpac deploy
1. Compare source and target schemas
2. Generate diff script
3. Pre Deployment script
4. Run diff script
5. Post Deployment scripts
4. Post DacPac deployment scripts (optional)
5. Restore on failure (optional)
DB Proj Structure
Refactoring
• Rename, Move to Schema, Expand Wildcards, Fully
qualified names
• Refactor log - Extra metadata in dacapc to understand
change
Everything should be named
• PK
• FK
• Constraints
• …
[ModifiedDate] DATETIME
CONSTRAINT [DF_Address_ModifiedDate] DEFAULT (getdate()) NOT NULL
CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED ([AddressID] ASC)
CONSTRAINT [FK_Address_StateProvince_StateProvinceID]
FOREIGN KEY ([StateProvinceID])
REFERENCES [Person].[StateProvince] ([StateProvinceID])
Static data is static (and part of schema)
• All data in the static scripts must be static incl ID
columns
• Use merge script approach for static data when possible
– Can use sp_generate_merge to create merge scripts from real
tables
– https://github.com/readyroll/generate-sql-merge
• When adding/removing ReferenceData files or Pre/Post
deployment scripts
– Pre / Post deployment.sql file needs be updated!
Pre-deployment, post-deployment,
predacpac
• Reference all the necessary databases and projects to
build (dacpacs, master, database projects)
– Use extraction of dacpacs from real databases
• PreDacPac, PreDeploy, PostDeploy scripts (incl static
data) are marked Build Action = None
• All pre, post and predacpac scripts must be repeatable
and fail-safe
• Use SQL CMD variables such as version, environment in
conditions in scripts, and Installation table
Handling changes
• Transitional
– R1: Do non-breaking change (e.g. add NULL column)
– R2: Turn column into NOT NULL
• All in one
– Use predacpac to do some of the changes before dacpac
deployment hits
Build
Building a DacPac
Commit changes to source
control
Deploy
Continuous
Integration
Pull changes from source control
Build
solution
Package the
output
Test
Release
Deploy a DacPac
Use variables in release pipeline
Version and Environment in the DB / scripts
• Make sure to send in Environment and Version as
variables to tasks in release
– To PreDacPac SQL script
– To dacpac deployment
• Using Sql Dacpac
– /v:Environment="$(Release.EnvironmentName)"
/v:Version="$(Build.BuildNumber)"
• Using Sql Script
– -Variable "Environment=`"$(Release.EnvironmentName)`"",
"Version=`"$(Build.BuildNumber)`""
Custom properties for dacpac deploy
• E.g.
/p:DropObjectsNotInSource=True
/p:DoNotDropObjectTypes=Users;RoleMembership;Permi
ssions
• /p:BlockOnPossibleDataLoss=False
• All SqlPackage options are documented in msdn
– https://goo.gl/Uh16By
Validate database schema changes
• As often as possible by deploying dacpac to specific
environment
• The bigger the environments schema difference (dev ->
test -> prod), the bigger the upgrade script (and more
fragile)
– To mitigate write all pre/post/.. scripts fail safe and repeatable
– To mitigate restore stage/acceptance database and run once-off
throw away upgrades as safety CI on schedule
– Note! This is necessary more often when releases are less
frequent, otherwise CD taking package from Dev -> Test ->
Stage -> Prod should handle it
DacPac compare report
• DacPac has support to report the changes that will be
done
– Extra arguments to sql package
– /deployscriptpath:”MyDeployScript.sql”
/deployreportpath:”MyDeployReport.xml”
• Can compare with previous release
– Custom extension, currently not tested
– https://marketplace.visualstudio.com/items?itemName=colinsal
mcorner.colinsalmcorner-buildtasks
• https://blogs.msdn.microsoft.com/ssdt/2016/10/20/sql-
server-data-tools-16-5-release/
Links
• Download SSDT
– https://msdn.microsoft.com/library/mt204009.aspx
• Download SQL CMD
– https://www.microsoft.com/en-
us/download/details.aspx?id=53591
• SSDT Nuget Package
– https://www.nuget.org/packages/Microsoft.Data.Tools.Msbuild/
• Generate SP Merge
– https://github.com/readyroll/generate-sql-merge
Thank You!
Taavi Koosaar
taavik@solidify.se
@melborp | +46 732 013 296
SSDT can help manage and maintain
your SQL database!
www.solidify.se

More Related Content

What's hot (20)

PDF
Migration From Oracle to PostgreSQL
PGConf APAC
 
PPTX
Liquibase
Roman Uholnikov
 
PPTX
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
PDF
Oracle to Postgres Migration - part 1
PgTraining
 
PDF
Oracle to Postgres Migration - part 2
PgTraining
 
PPTX
Microsoft SQL Server internals & architecture
Kevin Kline
 
PDF
Migrating Oracle database to PostgreSQL
Umair Mansoob
 
PDF
Database migrations with Flyway and Liquibase
Lars Östling
 
PDF
Database migration with flyway
Jonathan Holloway
 
PPTX
Sql server 2012 dba online training
sqlmasters
 
ODP
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
PPTX
Continuous DB Changes Delivery With Liquibase
Aidas Dragūnas
 
PPTX
Flyway: The agile database migration framework for Java
Axel Fontaine
 
PPTX
SQL Server R Services: What Every SQL Professional Should Know
Bob Ward
 
PPT
NoSQL_Night
Clarence J M Tauro
 
PDF
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
Ashnikbiz
 
PPTX
Brk3288 sql server v.next with support on linux, windows and containers was...
Bob Ward
 
PPTX
Sql server 2016 it just runs faster sql bits 2017 edition
Bob Ward
 
PDF
SQL Server 2016 novelties
MSDEVMTL
 
Migration From Oracle to PostgreSQL
PGConf APAC
 
Liquibase
Roman Uholnikov
 
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
Oracle to Postgres Migration - part 1
PgTraining
 
Oracle to Postgres Migration - part 2
PgTraining
 
Microsoft SQL Server internals & architecture
Kevin Kline
 
Migrating Oracle database to PostgreSQL
Umair Mansoob
 
Database migrations with Flyway and Liquibase
Lars Östling
 
Database migration with flyway
Jonathan Holloway
 
Sql server 2012 dba online training
sqlmasters
 
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
Continuous DB Changes Delivery With Liquibase
Aidas Dragūnas
 
Flyway: The agile database migration framework for Java
Axel Fontaine
 
SQL Server R Services: What Every SQL Professional Should Know
Bob Ward
 
NoSQL_Night
Clarence J M Tauro
 
Ashnik EnterpriseDB PostgreSQL - A real alternative to Oracle
Ashnikbiz
 
Brk3288 sql server v.next with support on linux, windows and containers was...
Bob Ward
 
Sql server 2016 it just runs faster sql bits 2017 edition
Bob Ward
 
SQL Server 2016 novelties
MSDEVMTL
 

Similar to Meetup developing building and_deploying databases with SSDT (20)

PPTX
SQL Explore 2012 - Meir Dudai: DAC
sqlserver.co.il
 
PPTX
SQL Server Deployments made easy with DACPAC
Sanil Mhatre
 
PDF
The databases in SSDT: A work with project and best practices
Kamil Nowinski
 
PPTX
Database CI/CD Pipeline
muhammadhashir57
 
PPTX
Azure DevOps for the Data Professional
Sarah Dutkiewicz
 
PPTX
SSDT unleashed
GomathiNayagam S
 
PDF
BASTA Spring 2023 - AUTOMATISIERTES DATENBANK-DEPLOYMENT IM DEVOPS-PROZESS
Marc Müller
 
PDF
BASTA! 2022 - Automatisiertes Datenbank-Deployment im DevOps-Prozess
Marc Müller
 
PDF
Database CI Demo Using Sql Server
Umesh Kumar
 
PPTX
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Microsoft TechNet - Belgium and Luxembourg
 
PPTX
Declarative Database Development with SQL Server Data Tools
Gert Drapers
 
PPTX
Sql source control
AndyPickett
 
PDF
DWX 2018 - Automatisiertes Datenbankdeployment im DevOps Prozess
Marc Müller
 
PDF
DWX 2018 - Automatisiertes Datenbank-Deployment im DevOps Prozess
Marc Müller
 
PPTX
DevOps+Data: Working with Source Control
Ed Leighton-Dick
 
PDF
Extreme performance - IDF UG
sqlserver.co.il
 
PPTX
#DOAW16 - DevOps@work Roma 2016 - Databases under source control
Alessandro Alpi
 
PPTX
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Dr. John Tunnicliffe
 
PPTX
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Dr. John Tunnicliffe
 
PPTX
Database projects within visual studio
Ronnie Hicks
 
SQL Explore 2012 - Meir Dudai: DAC
sqlserver.co.il
 
SQL Server Deployments made easy with DACPAC
Sanil Mhatre
 
The databases in SSDT: A work with project and best practices
Kamil Nowinski
 
Database CI/CD Pipeline
muhammadhashir57
 
Azure DevOps for the Data Professional
Sarah Dutkiewicz
 
SSDT unleashed
GomathiNayagam S
 
BASTA Spring 2023 - AUTOMATISIERTES DATENBANK-DEPLOYMENT IM DEVOPS-PROZESS
Marc Müller
 
BASTA! 2022 - Automatisiertes Datenbank-Deployment im DevOps-Prozess
Marc Müller
 
Database CI Demo Using Sql Server
Umesh Kumar
 
Database Schema Management & Deployment using SQL Server Data Tools (SSDT)
Microsoft TechNet - Belgium and Luxembourg
 
Declarative Database Development with SQL Server Data Tools
Gert Drapers
 
Sql source control
AndyPickett
 
DWX 2018 - Automatisiertes Datenbankdeployment im DevOps Prozess
Marc Müller
 
DWX 2018 - Automatisiertes Datenbank-Deployment im DevOps Prozess
Marc Müller
 
DevOps+Data: Working with Source Control
Ed Leighton-Dick
 
Extreme performance - IDF UG
sqlserver.co.il
 
#DOAW16 - DevOps@work Roma 2016 - Databases under source control
Alessandro Alpi
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Dr. John Tunnicliffe
 
Continuous Integration and the Data Warehouse - PASS SQL Saturday Slovenia
Dr. John Tunnicliffe
 
Database projects within visual studio
Ronnie Hicks
 
Ad

More from Solidify (14)

PPTX
Continuous delivery using Azure and VSTS, Global Azure BootCamp 2017 - Estonia
Solidify
 
PPTX
Performance monitoring in a DevOps World
Solidify
 
PDF
Continuous Delivery to Azure with VSTS
Solidify
 
PPTX
Continuous Delivery på riktigt
Solidify
 
PPTX
DevOps and Continuous Delivery with Visual Studio 2015 and VSTS
Solidify
 
PPTX
Tech Days 2015 nyheter i visual studio alm 2015
Solidify
 
PPTX
Tech Days 2015 continuous delivery med azure och visual studio online
Solidify
 
PPTX
Alm roadshow 2015.1
Solidify
 
PPTX
Tech days 2014 från kod till produktion på 60 minuter
Solidify
 
PPTX
Solidify continuous delivery 2014
Solidify
 
PPTX
Har du en DevOps i ditt team?
Solidify
 
PPTX
Har du en DevOps i ditt team?
Solidify
 
PPTX
TFS 2013 Deep-Dive på LabCenter 2014-02-06
Solidify
 
PPTX
Team Foundation Server 2013 Lansering
Solidify
 
Continuous delivery using Azure and VSTS, Global Azure BootCamp 2017 - Estonia
Solidify
 
Performance monitoring in a DevOps World
Solidify
 
Continuous Delivery to Azure with VSTS
Solidify
 
Continuous Delivery på riktigt
Solidify
 
DevOps and Continuous Delivery with Visual Studio 2015 and VSTS
Solidify
 
Tech Days 2015 nyheter i visual studio alm 2015
Solidify
 
Tech Days 2015 continuous delivery med azure och visual studio online
Solidify
 
Alm roadshow 2015.1
Solidify
 
Tech days 2014 från kod till produktion på 60 minuter
Solidify
 
Solidify continuous delivery 2014
Solidify
 
Har du en DevOps i ditt team?
Solidify
 
Har du en DevOps i ditt team?
Solidify
 
TFS 2013 Deep-Dive på LabCenter 2014-02-06
Solidify
 
Team Foundation Server 2013 Lansering
Solidify
 
Ad

Recently uploaded (20)

PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 

Meetup developing building and_deploying databases with SSDT

  • 1. Developing, Building and Releasing databases with SSDT and Taavi Koosaar DevOps Consultant | VS ALM MVP | VS ALM Ranger
  • 4. Development and deployment models • Manual scripts, combine and run – Write the scripts manually and run them in correct sequence • Model based deployment – Compare two schemas and apply difference • Migration based deployment – Apply all changes since the last migration – E.g. EF migration
  • 5. The SSDT tooling DACFx SqlPackageSSMSSSDT Visual Studio SQL DBdacpac SQL Client
  • 6. SSDT 2016 July and forward
  • 7. DAC framework • The component /framework that makes deployment possible – Model, deployment and api – SqlPackage.exe – Data Tier Applications • Comes with SSDT and SQL Server (can also be separately installed) • Compatible downwards • Not everything of SQL is supported – https://msdn.microsoft.com/en-us/library/ee210549.aspx
  • 8. SSDT in Visual Studio • SQL Server Object Explorer – connected / offline dev • SQL Database project structure, references and daily work – Incl code analytics, intellisense, refactoring • SQL Schema Compare | Data Compare • Pre-Build, Post-Build and Pre-DacPac, Post-DacPac – Reference data scripts • DACPAC, BACPAC and Publish/Deployment – Settings, sqlcmd variables • Refactor log
  • 9. SQL Database project • Everything you plan to deploy to database and everything you are referencing should be there – Except the few things you may not want to e.g. logins, roles • Project & Database references – Composite projects • (SQL CMD) Variables • Code Analysis rules • Snapshots
  • 10. Composite projects • Reference external databases • Break up a larger database into logical units • Separate by schema / functional area • Decrease build time – build smaller pieces
  • 11. Composite project references SQL DB dacpac My DB Project Artefacts Artefacts Artefacts Artifacts My Other DB Project data-tier application system database project Same Database Same Server, Different Database Different Server, Different Database master msdb
  • 12. What is a DacPac? • A zip file • Result of the build of database project • Contains the model / schema / refactorings • Contains the pre and post deployment combined scripts • Versioned
  • 13. DacPac deployment flow (per DacPac) Deploy Schema Comparison Script generation (delta) Execute Pre Deployment Execute generated script Execute Post Deployment
  • 15. Getting started with database project • Import existing database into database project – From database – From dacpac (e.g. that came from production) • First time, you will hit and find a lot of … – Invalid objects - Old objects referencing non-existent columns / encrypted objects / invalid synonyms / cross database references / circular references / unsupported objects for target platform • Engage a Subject Matter Expert: Talk to your DBA to help clean up these issues
  • 16. Getting started with database project • Validation turned on – Turn validation off for initial import! – Use the latest version of the tools! – Import everything and fix issues within Visual Studio • SSDT imports the first 1000 stored procedures into Procs1, the next into Procs2 etc – You may need to add some folder structure to your project to keep developers sane. – Having many 1000’s of objects affects SSDT performance
  • 17. Enhanced DacPac deployment flow 1. Database backup 2. Pre DacPac deployment scripts 3. Dacpac deploy 1. Compare source and target schemas 2. Generate diff script 3. Pre Deployment script 4. Run diff script 5. Post Deployment scripts 4. Post DacPac deployment scripts (optional) 5. Restore on failure (optional)
  • 19. Refactoring • Rename, Move to Schema, Expand Wildcards, Fully qualified names • Refactor log - Extra metadata in dacapc to understand change
  • 20. Everything should be named • PK • FK • Constraints • … [ModifiedDate] DATETIME CONSTRAINT [DF_Address_ModifiedDate] DEFAULT (getdate()) NOT NULL CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED ([AddressID] ASC) CONSTRAINT [FK_Address_StateProvince_StateProvinceID] FOREIGN KEY ([StateProvinceID]) REFERENCES [Person].[StateProvince] ([StateProvinceID])
  • 21. Static data is static (and part of schema) • All data in the static scripts must be static incl ID columns • Use merge script approach for static data when possible – Can use sp_generate_merge to create merge scripts from real tables – https://github.com/readyroll/generate-sql-merge • When adding/removing ReferenceData files or Pre/Post deployment scripts – Pre / Post deployment.sql file needs be updated!
  • 22. Pre-deployment, post-deployment, predacpac • Reference all the necessary databases and projects to build (dacpacs, master, database projects) – Use extraction of dacpacs from real databases • PreDacPac, PreDeploy, PostDeploy scripts (incl static data) are marked Build Action = None • All pre, post and predacpac scripts must be repeatable and fail-safe • Use SQL CMD variables such as version, environment in conditions in scripts, and Installation table
  • 23. Handling changes • Transitional – R1: Do non-breaking change (e.g. add NULL column) – R2: Turn column into NOT NULL • All in one – Use predacpac to do some of the changes before dacpac deployment hits
  • 24. Build
  • 26. Commit changes to source control Deploy Continuous Integration Pull changes from source control Build solution Package the output Test
  • 29. Use variables in release pipeline
  • 30. Version and Environment in the DB / scripts • Make sure to send in Environment and Version as variables to tasks in release – To PreDacPac SQL script – To dacpac deployment • Using Sql Dacpac – /v:Environment="$(Release.EnvironmentName)" /v:Version="$(Build.BuildNumber)" • Using Sql Script – -Variable "Environment=`"$(Release.EnvironmentName)`"", "Version=`"$(Build.BuildNumber)`""
  • 31. Custom properties for dacpac deploy • E.g. /p:DropObjectsNotInSource=True /p:DoNotDropObjectTypes=Users;RoleMembership;Permi ssions • /p:BlockOnPossibleDataLoss=False • All SqlPackage options are documented in msdn – https://goo.gl/Uh16By
  • 32. Validate database schema changes • As often as possible by deploying dacpac to specific environment • The bigger the environments schema difference (dev -> test -> prod), the bigger the upgrade script (and more fragile) – To mitigate write all pre/post/.. scripts fail safe and repeatable – To mitigate restore stage/acceptance database and run once-off throw away upgrades as safety CI on schedule – Note! This is necessary more often when releases are less frequent, otherwise CD taking package from Dev -> Test -> Stage -> Prod should handle it
  • 33. DacPac compare report • DacPac has support to report the changes that will be done – Extra arguments to sql package – /deployscriptpath:”MyDeployScript.sql” /deployreportpath:”MyDeployReport.xml” • Can compare with previous release – Custom extension, currently not tested – https://marketplace.visualstudio.com/items?itemName=colinsal mcorner.colinsalmcorner-buildtasks • https://blogs.msdn.microsoft.com/ssdt/2016/10/20/sql- server-data-tools-16-5-release/
  • 34. Links • Download SSDT – https://msdn.microsoft.com/library/mt204009.aspx • Download SQL CMD – https://www.microsoft.com/en- us/download/details.aspx?id=53591 • SSDT Nuget Package – https://www.nuget.org/packages/Microsoft.Data.Tools.Msbuild/ • Generate SP Merge – https://github.com/readyroll/generate-sql-merge
  • 35. Thank You! Taavi Koosaar [email protected] @melborp | +46 732 013 296 SSDT can help manage and maintain your SQL database!