part of the dlm story: automated database build and test with teamcity
DESCRIPTION
Part of the DLM story: SQL In The City Workshop Cambridge, UK. Automated database build and test with TeamCity.TRANSCRIPT
![Page 1: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/1.jpg)
#sqlinthecity
Automated database build and
test with TeamCity
SITC Workshop Cambridge, UK
![Page 2: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/2.jpg)
What is CI?
• Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.
#sqlinthecity
![Page 3: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/3.jpg)
What is database CI?
• It’s the same!
• Applying the same approach to the database as we do for the application
#sqlinthecity
![Page 4: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/4.jpg)
The road to database CI
1. Source control
2. Automated builds
3. Automated tests
4. Frequent check ins of small changes
#sqlinthecity
![Page 5: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/5.jpg)
The road to database CI
1. Source control
2. Automated builds
3. Automated tests
4. Frequent check ins of small changes
#sqlinthecity
![Page 6: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/6.jpg)
Advantages of Automated Builds
• Early warning of broken code
• Constant availability of a "current" build
• Don’t continue developing on a broken foundation
• Many more….
#sqlinthecity
![Page 7: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/7.jpg)
Goals of today’s workshop
1. Link a source control repository to a build system
2. Use the SQLCI resources to implement build steps that:• Verify that your database code has built successfully• Verify an upgrade to an existing database • Run database unit tests
3. Trigger builds automatically on changes being checked in to source control
4. Introduce artifacts as the basis for future repeatable deployments
#sqlinthecity
![Page 8: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/8.jpg)
• Plugin for TeamCity
• Part of the Red Gate SQL Automation Pack
• Includes 3 build runners:
• Build
• Sync
• Test
#sqlinthecity
SQLCI Plugin – What is it?
![Page 9: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/9.jpg)
SQLCI
#sqlinthecity
![Page 10: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/10.jpg)
• Subversion(SVN)
• SQL Server 2012
• SQL Source Control
• TeamCity
#sqlinthecity
Current setup
![Page 11: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/11.jpg)
Creating a project
• Creating a new TeamCity Project
• Adding a VCS Root
#sqlinthecity
![Page 12: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/12.jpg)
The Build Step…
#sqlinthecity
CREATE
TABLE
foo…
Does creation
script run?
?
1. Convert scripts folder into package
2. Generate the creation script
3. Validate creation script
![Page 13: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/13.jpg)
The Build Step…
#sqlinthecity
![Page 14: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/14.jpg)
Triggering…
#sqlinthecity
![Page 15: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/15.jpg)
Triggering…
#sqlinthecity
• Check it works so far.
![Page 16: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/16.jpg)
Break time!
#sqlinthecity
![Page 17: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/17.jpg)
The Sync Step…
#sqlinthecity
1. Apply package version to target database
2. Deployment validation (is the target the same as the package?)
V1.1
V1.2
compare
![Page 18: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/18.jpg)
The Sync Step…
#sqlinthecity
![Page 19: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/19.jpg)
The Sync Step…
• Check it works so far.
#sqlinthecity
![Page 20: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/20.jpg)
Capturing an upgrade script…
/scriptFile:“<FilePath>“
We can use %build.number% to grab the current build number.
#sqlinthecity
![Page 21: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/21.jpg)
Review…
#sqlinthecity
![Page 22: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/22.jpg)
Try it for yourself….
• SQLServerCentral
#sqlinthecity
![Page 23: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/23.jpg)
Lunch time!
#sqlinthecity
![Page 24: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/24.jpg)
The road to database CI
1. Source control
2. Automated builds
3. Automated tests
4. Frequent check ins of small changes
#sqlinthecity
![Page 25: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/25.jpg)
The road to database CI
1. Source control
2. Automated builds
3. Automated tests
4. Frequent check ins of small changes
#sqlinthecity
![Page 26: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/26.jpg)
Advantages of Automated Tests
• Early warning of broken code
• Constant validation of existing functionality
• Detect when new changes introduce errors
• Feedback on the current state of the code
• Many more….
#sqlinthecity
![Page 27: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/27.jpg)
SQL Test – What is it?
• Add-in for SQL Server Management Studio
• Builds upon tSQLt framework
• Adds a simple UI for creating, managing and running database unit tests.
• All tests are written in T-SQL
www.tsqlt.org
#sqlinthecity
![Page 28: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/28.jpg)
Add database to SQL Test
#sqlinthecity
![Page 29: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/29.jpg)
Add a test
![Page 30: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/30.jpg)
Manually running the tests…
• Check it works so far.
#sqlinthecity
![Page 31: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/31.jpg)
Automating tests
#sqlinthecity
![Page 32: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/32.jpg)
The Test Step…
#sqlinthecity
1. Build empty test database from package
2. Populate a new database with test data (optional)
3. Run tSQLt unit tests(report in JUnit format)
![Page 33: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/33.jpg)
The Test Step…
• Practical
– sqlCI.exe Sync
/package= <values5,2,3>
/databaseServer=<value6>
/databaseName=<value7>
Optionally supply SQL Server Credentials
#sqlinthecity
![Page 34: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/34.jpg)
The Test Step…
• Run the build
#sqlinthecity
![Page 35: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/35.jpg)
The Test Step…
• Break the build
#sqlinthecity
![Page 36: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/36.jpg)
Review…
#sqlinthecity
![Page 37: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/37.jpg)
Break time!
#sqlinthecity
![Page 38: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/38.jpg)
Try it for yourself….
• SQLServerCentral
– How about a test to check the name added by the sproc?
#sqlinthecity
![Page 39: Part of the DLM Story: Automated database build and test with TeamCity](https://reader033.vdocument.in/reader033/viewer/2022060121/559454841a28ab8b118b45a3/html5/thumbnails/39.jpg)
Contact info
• Tom Austin
– Pre Sales Engineer at Red Gate
– Email: [email protected]
www.red-gate.com/ci
#sqlinthecity