How to get SlowCheetah to transform SQL files

130 Views Asked by At

The Microsoft Slowcheetah website states

This package allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio.

I have a SQL Server VS solution which requires configuration dependent users and logins. Slowcheetah would be a good solution if I can figure out what the transform file should look like.

For example I would like the statement

CREATE LOGIN [DEVDOMAIN\ReadonlyUser] FROM WINDOWS DEFAULT_DATABASE = MyDb_Dev;

Transformed to

CREATE LOGIN [TESTDOMAIN\ReadonlyUser] FROM WINDOWS DEFAULT_DATABASE = MyDb_Uat;

Is this achievable?

2

There are 2 best solutions below

0
AlwaysLearning On BEST ANSWER

SlowCheetah currently only supports using XML Document Transforms on XML files or JSON Document Transforms on JSON files.

If you can get your user data into one of those format you'll be set, otherwise...

0
Hugh Jones On

So it is not possible as far as anyone can tell. I also had no luck trying to get files to load into the projects according to which build configuration had been selected. This seems to be a feature of VS Sql Projects.

The solution I came up with in the end was to

i) Manually edit the .sqlproj (unload the project, right-click, select 'edit') adding in

<ItemGroup>
  <None include="dbo\Security\users\ReadonlyUser\DEV_Login.sql"  
  <None include="dbo\Security\users\ReadonlyUser\UAT_Login.sql"
  <!-- et cetera -->
</ItemGroup>

ii) add another itemgroup

<ItemGroup>
  <Build include="dbo\Security\users\ReadonlyUser_Login.sql"   
</ItemGroup>

iii) Reload the project and add a Build event (Pre-build event command line)

Copy $(ProjectDir)\dbo\Security\users\ReadonlyUser\$(Configuration)_Login.sql $(ProjectDir)\dbo\Security\users\ReadonlyUser_Login.sql