Slide 1

Slide 1 text

Applying CI/CD & DevOps to SQL database development Implementing the Migrations Approach and the Pipeline-as-Code paradigm with Azure DevOps and Flyway Migration

Slide 2

Slide 2 text

Overview CI-CD server/platform Database Automation Azure DevOps YAML Pipelines Unit Testing Code Quality

Slide 3

Slide 3 text

Internship Problem Statement • “Automate the release process of our SQL Server databases, applying CI/CD processes. You have full freedom to propose the tools and technologies to use”

Slide 4

Slide 4 text

Context Fintech company Microsoft SQL Server databases 2 dedicated SQL developers. Possibly more devs will contribute in the near future; Databases have a lot of business logic and programmable objects – Stored Procedures, Triggers, Functions, etc

Slide 5

Slide 5 text

Problem: applying CI/CD to databases is not the same as apps Apps • Delete old version and install new version, for every environment in the CI/CD pipeline • Apps are like a set of chairs in a room – just replace with a new set Databases • Can’t simply delete old version and create a new one, for EVERY environment, would take too long • Databases are like buildings – can’t rebuild one every time you want to change something.

Slide 6

Slide 6 text

Solution: apply migrations to the database, so it changes incrementally

Slide 7

Slide 7 text

Problem: how should these migrations be generated and applied?

Slide 8

Slide 8 text

Solution: choose between two approaches: “State” and “Migrations” State • a set of declarative SQL scripts describe how the database should be, with 1 script per database entity (e.g. Person.sql, Customer.sql, Account.sql, Address.sql) • A migration generator takes care of generating migrations for every change and for every environment, through state comparison Migrations • a set of imperative SQL scripts describe how the database should change • Migrations are hand-written by human developers, and a migration handler applies them across every environment, usually through meta-tables that keep track of already-applied migrations

Slide 9

Slide 9 text

“State” vs “Migrations” State + Higher-level abstraction, making it friendlier for new developers and larger teams - Generator lacks context awareness, might generate an unexpected migration - No guarantee the databases across different environments will be in the same state Migrations + 100% reproducible deployments; every database is always in a known state, regardless of environment - Requires more communication and coordination between team members - Very inefficient for programmable objects (e.g. Stored Procedures, Functions, Triggers) http://workingwithdevs.com/delivering-databases-migrations-vs-state/

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Available migration handlers that allow SQL developers to write in SQL Open-source Commercial Redgate SQL Change Automation

Slide 12

Slide 12 text

Problem: how to automate these migrations?

Slide 13

Slide 13 text

(One) Solution: Azure DevOps YAML Pipelines Classic GUI editor YAML Pipelines

Slide 14

Slide 14 text

NOT talking about the classic GUI editor

Slide 15

Slide 15 text

Talking about the new YAML functionality, 100% code

Slide 16

Slide 16 text

So what are we trying to build?

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Azure DevOps YAML Templates Allows a pipeline to be written in YAML modules, possibly applying traditional software development practices and patterns

Slide 20

Slide 20 text

Root file : “azure-pipelines.yml”

Slide 21

Slide 21 text

“build-job.yml”

Slide 22

Slide 22 text

What about Quality?

Slide 23

Slide 23 text

“quality-steps.yml”

Slide 24

Slide 24 text

“test-steps.yml”

Slide 25

Slide 25 text

Issues with Azure DevOps’ YAML Pipelines • Very immature compared to more established competitors like Travis CI, Jenkins, or TeamCity, with critical features either missing or not consolidated in YAML version (most available on Classic Editor) • No Deployment Groups • No Manual Approvals (especially before deploying to Production) • No IDE, except for the web-based one, which only works for the root YAML file • YAML templates paths always start at the root of the repository. This severely compromises modularity https://devblogs.microsoft.com/devops/azure-devops-roadmap-update-for-2019-q3/ https://docs.microsoft.com/en-us/azure/devops/release-notes/features-timeline

Slide 26

Slide 26 text

Verdict: Review it in 2020, lots of potential. Until then, either use Azure DevOps’ Classic Editor OR go with more established competitors

Slide 27

Slide 27 text

Wanna see more? Play around with this at your own pace? • https://github.com/rodfontessoares/flyway-tsqlt-azure-demo

Slide 28

Slide 28 text

Questions?

Slide 29

Slide 29 text

See you next time, and thanks for playing