VisualStudio SQL database project sqlcmdvars TFS deployment override custom File path? - sql-server

I have an SQL database project in VisualStudio 2010 in source control with TFS 2010 with a few branches that each deploy to different servers depending on the configuration profile.
Using a sqlcmdvars file with the configuration profile appended in the filename (Debug.sqlcmdvars, etc..) for each configuration profile lets me specify the unique file path for a particular deployment environment by use of the reserved names Path1 and Path2 for the mdf file and the log file.
<?xml version="1.0" encoding="utf-8"?>
<SqlCommandVariables xmlns="urn:Microsoft.VisualStudio.Data.Schema.Package.SqlCmdVars">
<Version>1.0</Version>
<Properties>
<Property>
<PropertyName>Path1</PropertyName>
<PropertyValue>C:\SQLSERVER LOG\$(DatabaseName)\</PropertyValue>
</Property>
<Property>
<PropertyName>Path2</PropertyName>
<PropertyValue>C:\SQLSERVER DATA\$(DatabaseName)\</PropertyValue>
</Property>
</Properties>
</SqlCommandVariables>
Now I'm trying to add a custom FileStream file with an associated FileStream FileGroup
I have added an additional entry in sqlcmdvars files:
<Property>
<PropertyName>PathBlobStream</PropertyName>
<PropertyValue>C:\SQLSERVER DATA\$(DatabaseName)\BlobStream\</PropertyValue>
</Property>
But am not sure how to tell the database to use this over what the SchemaObjects\Database Level Objects\Storage\BlobStore.sqlfile.sql has declared:
ALTER DATABASE [$(DatabaseName)]
ADD FILE (NAME = [BlobStore], FILENAME = 'C:\SQLSERVER DATA\####\BlobStream') TO FILEGROUP [BlobStreamFileGroup];
How do you use the new entry in the sqlcmdvars to override the path for the new FileStream file?

The best way I found to do this was add additional entries in the dbproj file to use a different schema file depending on the configuration profile:
<ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<Build Include="Schema Objects\Database Level Objects\Storage\Files\BlobStore.sqlfile.sql">
<SubType>Code</SubType>
</Build>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Internal' ">
<Build Include="Schema Objects\Database Level Objects\Storage\Files\BlobStore.sqlfile.Internal.sql">
<SubType>Code</SubType>
</Build>
</ItemGroup>
The key was copy/pasting the original schema file and appending the configuration profile name in the file name. This keeps the debug variation with the original file name so that any future schema comparisons will be oblivious to the additional variations. You want to include the additional schema files in source control, but if following suite to the entries above, they won't show up in the project. I verified MSBuild handles this correctly. I'm crossing my fingers that TFS will do the same.

Related

SQL Server DACPAC Deployment Dropping Users/Roles/Permissions

I'm deploying an (Azure) SQL Server Database using a DACPAC. Every time I deploy it's dropping my users, roles, and permissions even though I'm explicitly telling it not to in the publishing profile I'm using.
The publishing profile is defined as
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>neonbliss</TargetDatabaseName>
<DeployScriptFileName>Neon Bliss Storefront Database.sql</DeployScriptFileName>
<BlockOnPossibleDataLoss>True</BlockOnPossibleDataLoss>
<DropObjectsNotInSource>True</DropObjectsNotInSource>
<ProfileVersionNumber>1</ProfileVersionNumber>
<DatabaseEdition>Basic</DatabaseEdition>
<DatabaseServiceObjective>Basic</DatabaseServiceObjective>
<DatabaseMaximumSize>2</DatabaseMaximumSize>
<DoNotDropRoleMembership>True</DoNotDropRoleMembership>
<DoNotDropUsers>True</DoNotDropUsers>
<DoNotDropPermissions>True</DoNotDropPermissions>
<DoNotDropSecurityPolicies>True</DoNotDropSecurityPolicies>
<ExcludeUsers>True</ExcludeUsers>
<ExcludeSecurityPolicies>True</ExcludeSecurityPolicies>
<ExcludeDatabaseRoles>True</ExcludeDatabaseRoles>
<IgnorePermissions>True</IgnorePermissions>
<TreatVerificationErrorsAsWarnings>True</TreatVerificationErrorsAsWarnings>
</PropertyGroup>
</Project>
Has anyone seen this?
This has been an ongoing DACPAC issue, presumably with the DropObjectsNotInSource overriding all other flags indiscriminately.
If you don't want to specifically add the security objects into your SSDT package, then since the publishing profile isn't sticking like you need, you'll need to adjust the arguments of SQLPackage.exe with...
/p:ExcludeObjectTypes=Users;Logins;RoleMembership;Permissions

How can i include a master changelog file inside another master changelog file in liquibase

I have a requirement where am pulling changelog files containing changesets as a maven dependency from other project module. I need to include the master changelog file of other project (which has reference to all the changesets in it)in current project from where i will execute the maven liquibase update / rollback or spring boot liuqibase setup. Is there a way to make it work?
I tried to do that like shown below
<?xml version="1.0" encoding="UTF-8" standalone="no"?><databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangeloghttp://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
<property name="blob" value="bytea" dbms="postgresql"/>
<property name="blob" value="blob" dbms="derby"/>
<preConditions>
<or>
<dbms type="derby"/>
<dbms type="postgresql"/>
</or>
</preConditions>
<include file="db/changelog/db.changelog-master.xml"/>
<include file="db/changelog/changesets/2019-06-001-modeler.changelog.xml"/>
</databaseChangeLog>
But i get error
Error setting up or running Liquibase: liquibase.exception.SetupException:
Error Reading Migration File: Found 2 files that match db/changelog/db.changelog-master.xml
I have same folder structure in all the projects.
This was a reported bug a while back and is now fixed with the later versions of Liquibase.
Please try to use the latest Liquibase version and see if the issue goes away.
Below is a reference for Liquibase releases.
https://github.com/liquibase/liquibase/releases
Liquibase can't understand which of your files with same name it should use.
If it's possible you should change path to your changelog.
So if your changelogs are both on path db/changelog/db.changelog-master.xml try to rename the paths at least. For example use db/changelog/module1/db.changelog-master.xml or db/changelog/db.changelog-module1-master.xml.

DACPAC Deployment setting

I want to publish my dacpac file using VSTS. I will be giving only DACPAC file to Dev ops team. I want to ignore drop table that is not in source. If i Publish it from SSDT, I can change in advanced settings. How to do that for VSTS. I can see an option under debug menu, But I am unable to check that option, Screen shot is attached in below URL.
https://i.stack.imgur.com/TBQPe.png
You can give publish.xml along side your dacpac and include a similar setting in that xml as well such as mentioned below
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>dbname</TargetDatabaseName>
<DeployScriptFileName>dbname.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=<name>;Integrated Security=True;Persist
Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect
Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
<BlockOnPossibleDataLoss>False</BlockOnPossibleDataLoss>
<DropObjectsNotInSource>False</DropObjectsNotInSource>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
</Project>
and while deploying dacpac (using cmd or powershell) you need to pass this xml file path in /Profile: parameter to pick this xml for deployment settings

ChangeSet for Oracle plugin in Liquibase always empty

I've downloaded Oracle Plugin for Liquibase, I've built it with maven and copied liquibase-oracle-3.3-SNAPSHOT.jar in /lib directory in Liquibase home.
I've added namespace into changeLog file, as reported in documentation, and this is my changeLog file:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ora="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet author="myAuthor" id="xxx">
<ora:encapsulateTableWithView tableName="TABLENAME"/>
</changeSet>
</databaseChangeLog>
Update operation via CLI is always successful, but nothing happens on DB: the row in the DATABASECHANGELOG table referring this operation is correct but reports "empty" in description column.
I also added liquibase-oracle-3.3-SNAPSHOT.jar to classpath in liquibase.properties file, but it's useless.
Every changeSet traced in DATABASECHANGELOG table with specific Oracle plugin tag has the same checksum (7:d41d8cd98f00b204e9800998ecf8427e) and reports "empty" in DESCRIPTION.
Any idea?
I found what was the problem: i launched by CLI command
java -jar liquibase.jar --changeLogFile=myChangeLog.xml update
but the changeSet resulted always empty: this because liquibase.jar didn't take classes from liquibase-oracle-3.3-SNAPSHOT.jar. I added liquibase.bat at environment variables in PATH and new command is
liquibase --changeLogFile=myChangeLog.xml update
and it works fine.

MSBuild extensionpack: verify backup remote

I am trying to backup a database on a remote database server and then verify that backup file.
The backup works well but when I try to verify the backup the build fails with an error:
DataFilePath not found: c:\DatabaseBackups\MyDB.bak
I use the following xml build file on my local computer:
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
<SqlInstance>myremoteserver</SqlInstance>
<ProductionBackup>c:\DatabaseBackups\MyDB.bak</ProductionBackup>
<SqlUserName>user</SqlUserName>
<SqlPassword>pass</SqlPassword>
<DatabaseName>MyDB</DatabaseName>
</PropertyGroup>
<Import Project="$(TPath)"/>
<Target Name="BackupDB">
<!-- Backup a database -->
<MSBuild.ExtensionPack.Sql2008.Database TaskAction="Backup" DatabaseItem="$(DatabaseName)" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="$(ProductionBackup)"/>
<!-- Verify a database backup -->
<MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="$(ProductionBackup)"/>
</Target>
</Project>
This build file works fine if I run the backup and verification on my local machine but fails when I change the MachineName to a remote server.
I believe that when searching for the backup file MS Build searches on my local machine and not on the remote machine. How can I tell MS Build to search the remote server for the backup file?
Just provide the file path as a unc path. Make the destination shared to your user and it should work fine.
If youve admin rights:
<MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="\\$(SQLInstance)\C$\DatabaseBackups\MyDB.bak"/>
Otherwise share the databaseBackups folder to your user:
<MSBuild.ExtensionPack.Sql2008.Database TaskAction="VerifyBackup" MachineName="$(SqlInstance)" UserName="$(SqlUserName)" UserPassword="$(SqlPassword)" DataFilePath="\\$(SQLInstance)\DatabaseBackups\MyDB.bak"/>

Resources