Sania: Syntactic and Semantic Analysis for Automated Testing against SQL Injection
Database automated build and test - SQL In The City Cambridge
-
Upload
red-gate-software -
Category
Technology
-
view
646 -
download
2
description
Transcript of Database automated build and test - SQL In The City Cambridge
![Page 1: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/1.jpg)
#sqlinthecity
David AtkinsonProduct Manager, Red Gate
Automated Build and Test(or continuous integration)
(for your database)
![Page 2: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/2.jpg)
What will we cover today?
Database build automation:What, Why, How
Practical Demo
Questions encouraged!
#sqlinthecity
![Page 3: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/3.jpg)
Show of hands: How agile is your database development?
1. Database objects/scripts aren’t in version control
2. Database objects/scripts are in version control
3. An automated build system exists to build and test the database
4. An automated release system is used to promote your database to your environments
#sqlinthecity
![Page 4: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/4.jpg)
1. Database objects/scripts aren’t in version control
2. Database objects/scripts are in version control
3. An automated build system exists to build and test the database
4. An automated release system is used to promote your database to your environments
How agile is your database development?
#sqlinthecity
![Page 5: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/5.jpg)
“Continuous Integration is a practice designed to ensure that your software is
always working, and that you get comprehensive feedback in a few minutes as to whether any given change to your system
has broken it.”Jez Humble, ThoughtWorks,
author of “Continuous Delivery”
#sqlinthecity
What is continuous integration?
![Page 6: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/6.jpg)
“Database Continuous Integration is a practice designed to ensure that your
database software is always working, and that you get comprehensive feedback in a
few minutes as to whether any given change to your system has broken it.”
What is continuous integration?
#sqlinthecitydatabase
^
![Page 7: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/7.jpg)
Database Build Automation#sqlinthecity
![Page 8: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/8.jpg)
What is build?
• For application code = compile• For database code = database creation
script – But only for a new installation!
• Upgrade scripts required for existing installations– Need to preserve the state of the data
#sqlinthecity
![Page 9: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/9.jpg)
What is test?
• For .NET code, NUnit.– Runs on a developer’s machine and
build server• What about the database?– tSQLt is an open source framework for
testing SQL Server databases– SQL Test provides SSMS integration
#sqlinthecity
![Page 10: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/10.jpg)
Demo background
Two fictional developers, David and Grant, are working on the website, www.simple-talk.com, a community website for .NET and SQL Server developers
The application comprises• An ASP.Net web application• A SQL Server database
#sqlinthecity
![Page 11: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/11.jpg)
Demo background
Continuous integration has been configured to:
1. Keep a test database up to date with the latest changes
2. Run automated tSQLt tests(on realistic amounts of data)
3. Generate up-to-date documentation4. Generate deployment scripts
#sqlinthecity
![Page 12: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/12.jpg)
Demo background
A few improvements are being made to Simple Talk.
These changes will be deployed to production.
But… only when the dev team has demonstrated that the changes work!
#sqlinthecity
![Page 13: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/13.jpg)
Tools used• TeamCity (CI tool from JetBrains)• SQL Automation Pack (includes TeamCity
plugin)
• Glimpse (open source)
From the SQL Developer Bundle:• SQL Source Control• SQL Test (tSQLt unit testing framework)• SQL Data Generator• SQL Doc
#sqlinthecity
![Page 14: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/14.jpg)
Demo
#sqlinthecity
![Page 15: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/15.jpg)
Custom Migration ScriptsAn introduction
#sqlinthecity
![Page 16: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/16.jpg)
Generating a deployment script
1
12
#sqlinthecity
![Page 17: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/17.jpg)
How changes are made
1 2 3 4 5 6
modify procedure
create table
drop view
create trigger
delete column
#sqlinthecity
![Page 18: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/18.jpg)
1 2 3 4 5 6
modify procedure
create table
drop view
create trigger
delete column
7 8 9 10 11 12
modify trigger
create view
create procedure
create function
drop procedure
modify function
How changes are made#sqlinthecity
![Page 19: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/19.jpg)
Infer deployment script
How SQL Compare sees the world
1
12
#sqlinthecity
![Page 20: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/20.jpg)
But not all changes can be inferred
1 2 3 4 5 6
7 8 9 10 11 12
table rename
column rename add NOT NULL
column without DEFAULT
split table
merge table
data transformation
data motion
merge columnsplit column
#sqlinthecity
![Page 21: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/21.jpg)
SQL Compare and SQL Source Control support custom migration scripts
1 2 3 4 5 6
7 8 9 10 11 12
Custom migration script
#sqlinthecity
![Page 22: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/22.jpg)
Deployment script with migration scripts
1
12
#sqlinthecity
![Page 23: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/23.jpg)
SQL Compare
1
12
1’
Migration scripts
#sqlinthecity
![Page 24: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/24.jpg)
Demo
#sqlinthecity
![Page 25: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/25.jpg)
Recap: database CI
1. Incrementally keeps a test database up to date
2. Runs tSQLt tests on a database with realistic amounts of data
3. Generates always-up-to-date documentation
4. Generates and validates deployment scripts
5. Publishes a Deployment Manager database package
#sqlinthecity
![Page 26: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/26.jpg)
Recap of demo: writing a test
1. A new test is added2. Continuous Integration identifies a failure3. We reproduce the bug locally4. We fix the bug and test it5. We commit the fix to source control
#sqlinthecity
![Page 27: Database automated build and test - SQL In The City Cambridge](https://reader034.fdocuments.in/reader034/viewer/2022052618/554f4f90b4c905b9508b4c6a/html5/thumbnails/27.jpg)
Recap: migration scripts
1. The fix sets the [PublishDate] column from NULL to NOT NULL
2. Grant’s “get latest” fails because existing data that has NULL values
3. The continuous integration build alerts us of the same issue
4. A migration script is added to UPDATE existing data prior to changing the column to NOT NULL
5. Get Latest becomes possible and the continuous integration build once again indicates working software
#sqlinthecity