Part of the DLM Story: Automated database build and test with TeamCity

39
#sqlinthecity Automated database build and test with TeamCity SITC Workshop Cambridge, UK

description

Part of the DLM story: SQL In The City Workshop Cambridge, UK. Automated database build and test with TeamCity.

Transcript of Part of the DLM Story: Automated database build and test with TeamCity

Page 1: Part of the DLM Story: Automated database build and test with TeamCity

#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

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

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

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

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

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

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

• 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

SQLCI

#sqlinthecity

Page 10: Part of the DLM Story: Automated database build and test with TeamCity

• 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

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

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

The Build Step…

#sqlinthecity

Page 14: Part of the DLM Story: Automated database build and test with TeamCity

Triggering…

#sqlinthecity

Page 15: Part of the DLM Story: Automated database build and test with TeamCity

Triggering…

#sqlinthecity

• Check it works so far.

Page 16: Part of the DLM Story: Automated database build and test with TeamCity

Break time!

#sqlinthecity

Page 17: Part of the DLM Story: Automated database build and test with TeamCity

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

The Sync Step…

#sqlinthecity

Page 19: Part of the DLM Story: Automated database build and test with TeamCity

The Sync Step…

• Check it works so far.

#sqlinthecity

Page 20: Part of the DLM Story: Automated database build and test with TeamCity

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

Review…

#sqlinthecity

Page 22: Part of the DLM Story: Automated database build and test with TeamCity

Try it for yourself….

• SQLServerCentral

#sqlinthecity

Page 23: Part of the DLM Story: Automated database build and test with TeamCity

Lunch time!

#sqlinthecity

Page 24: Part of the DLM Story: Automated database build and test with TeamCity

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

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

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

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

Add database to SQL Test

#sqlinthecity

Page 29: Part of the DLM Story: Automated database build and test with TeamCity

Add a test

Page 30: Part of the DLM Story: Automated database build and test with TeamCity

Manually running the tests…

• Check it works so far.

#sqlinthecity

Page 31: Part of the DLM Story: Automated database build and test with TeamCity

Automating tests

#sqlinthecity

Page 32: Part of the DLM Story: Automated database build and test with TeamCity

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

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

The Test Step…

• Run the build

#sqlinthecity

Page 35: Part of the DLM Story: Automated database build and test with TeamCity

The Test Step…

• Break the build

#sqlinthecity

Page 36: Part of the DLM Story: Automated database build and test with TeamCity

Review…

#sqlinthecity

Page 37: Part of the DLM Story: Automated database build and test with TeamCity

Break time!

#sqlinthecity

Page 38: Part of the DLM Story: Automated database build and test with TeamCity

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

Contact info

• Tom Austin

– Pre Sales Engineer at Red Gate

– Email: [email protected]

www.red-gate.com/ci

#sqlinthecity