Search code examples
sql-serverpowershellredgate

Recreate database from RedGate checked-in scripts


We've got a SQL Server instance with some 15-20 databases, which we check in TFS with the help of RedGate. I'm working on a script to be able to replicate the instance (so a developer could run a local instance when needed, for example) with the help of these scripts. What I'm worried about is the dependencies between these scripts.

In TFS, RedGate has created these folders with .sql files for each database:

Functions
Security
Stored Procedures
Tables
Triggers
Types
Views

I did a quick test with Powershell, just looping over these folders to execute the sql, but I think that might not always work. Is there a strict ordering which I can follow? Or is there some simpler way to do this? To clarify, I want to be able to start with an completly empty SQL Server instance, and end up with a fully configured one according to what is in the TFS (without data, but that is ok). Using Powershell is not a requirement, so if it is simpler to do some other way, that is preferrable.


Solution

  • If you're already using RedGate they have a ton of articles on how to move changes from source control to database. Here's one which describes moving database code from TFS using sqcompare command-line:

    http://www.codeproject.com/Articles/168595/Continuous-Integration-for-Database-Development

    If you compare to any empty database it will create the script you are looking for.