Site Archive (Complete)
Database Blog: Powershell and SMO scripts to support Version Control
DATABASE
EXCEPTION::QUERY

A Blog About Database Products and Technology.

by Kevin Carlson
SELECT * FROM [Musings]

Database matters.

by Niklas Hemdal
October 22, 2007

Powershell and SMO scripts to support Version Control

In the previous post we established a generic version control folder structure for our codelines. I have created two scripts: ScriptDatabase.ps1 and CreateSchema.ps1 to support this codeline structure. The ScriptDatabase.ps1 script will extract all of the database objects from a specified database into our Previous folder in the codeline structure. The CreateSchema.ps1 will create a new database schema from the codeline folders on the specified Microsoft SQL Server instance.

I have incorporated log4net in each PowerShell script. You can view the log4net configuration file here. Just drop the log4net.dll in the same directory as the PowerShell script and you are good to go. log4net is configured for Console output, but I have included the Appender for logging to a file.

Invoking the scriptdatabase.ps1 script:

C:\powershell .\scriptdatabase.ps1 MyInstanceName MyDatabaseName C:\Project\MainLine\Database\MyDatabaseName\Previous

where, "MyInstanceName" is the name of a Microsoft SQL Server Instance, "MyDatabaseName" is the name of an existing database on the specified instance, and "C:\temp" is the root path for the codeline folders. In other words the script will create/populate C:\Project\MainLine\Database\MyDatabaseName\Previous\StoredProcedures, C:\Project\MainLine\Database\MyDatabaseName\Previous\ForeignKeys, C:\Project\MainLine\Database\MyDatabaseName\Previous\Tables, etc.

In the next post I will explain how Sprint updates are handled.

[The source code is also available as one zip file: ddj071022hemdal.zip.]

Posted at 05:25 PM  Permalink




 
INFO-LINK


Related Sites: DotNetJunkies, SD Expo, SqlJunkies