Search code examples
sql-serverintegration-testingredgate

Initialize empty database from SQL scripts generated by Redgate SQL Source Control


I have a folder with SQL scripts generated by Redgate SQL Source Control:

enter image description here

I want to create a new SQL server database on the CI server to run integration tests as a part of the pipeline. I can easily create a new SQL server docker container. But then I need to create all tables, function etc. I want to use SQL scripts generated by Redgate SSC but I don't see the way to run them in the pipeline. I tried to run them manually but it's quite hard because it requires to run them in a proper sequence because there are dependencies between different SQL objects.

Is there a known way to do it?

UPDATE: Currently I'm looking into Building a Database Directly from Object-level Source Scripts approach.


Solution

  • The Scripts Folder created by SQL Source Control represents the create statements but to build a new database they need to be ordered correctly. SQL Compare Pro can be used to read in a scripts folder as its source using /scripts1, and if you set the target (/s2 and /db2) to be your empty database, it will create (and apply if you use the /sync) a deployment script to create your database. The SQL Compare Pro CLI comes with SQL Toolbelt Essentials or Flyway Enterprise, and is available as a traditional command line executable as well as from Dockerhub. Please contact [email protected] if you're unsure about licensing.

    Here is an example:

    sqlcompare /scripts1:"C:\Scripts Folder\" /s2:"my_server\my_instance,myport;encrypt=true;trustservercertificate=true" /db2:MyTargetDB /sync