Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

SSDT Data Migration

The SSDT Data Migration extension offers an advanced script based management for database scheme migrations. The main functionality is provided by a fully customizable and self-managed pre-, post and reference data script execution.

Intro

SSDT is a database development tooling fully integrated into Microsoft Visual Studio. It supports database scheme migrations out of the box using DACPAC definition files and consist of an integrated single pre- and post script file capability. In practice more complex environments and database deployment scenarios require additional logic which requires an extended migration management.

The SSDT Data Migration Scripts extension provides additional logic and management to meet the complexity for database deployments.

Database Deployment Flow

Based on the single pre-, post and reference data scripts the extension allows to use multiple managed sub-deployment scripts:

  • Pre-Scripts
    • ...must be used with caution as the target database is in an undefined state as long as the actual scheme update has not been executed. Especially, if the database does not yet exist on the target server there is no way to run any of the pre-deployment scripts. must be used with
  • Post-Scripts
    • ...are less critical compared to pre-scripts since the scheme migration has been executed in advance and provides an upgraded and consistent target database scheme.
  • Reference Data Scripts
    • ...are used for data which is needed by the application logic (extendable business logic, configuration, translations, etc...). Reference data should always be consistent with the application binaries. Most often, reference data uses merge statements for static reference table contents.

The following illustration shows the basic deployment flow using SSDT and the script extensibility features. All scripts and scheme migrations are bundled as artifacts during the build process and published onto the database by the dacfx framework at deployment time.

alt text

Build (and publish) a .dacpac (SQL Server database project) with .NET Core

The cross-platform version of sqlpackage allows publishing a .dacpac package for quite some time. Though building the database project (.sqlproj) was only possible on Windows because the .sqlproj project file is based on the full .NET Framework. The MSBuild.Sdk.SqlProj project finally allows to build the .dacpac file also on Mac or Linux.

Getting started

These instructions will get you a sample of the SSDT project up and running on your local machine for development and testing purposes.

Prerequisites

This chapter lists all prerequisites which have to be met to run the extension locally or on build servers.

  • Install SQL Server Data Tools Visual Studio component (Visual Studio Installer | Modify | Individual Components | Cloud, database and server | SQL Server Data Tools)
  • Install 4tecture.CustomSSDTMigrationScripts.msi extension from the releases section.

Setup Sample - SQL Server Database project

Use the samples project ending with "*.Sample" from the Sample folder as the initial template project or follow these instructions (using default configuration settings):

  1. Create a new SQL Server Database project

  2. On the root level of the project create the following folder structure and files with the given build option:

    |-Scripts
    |-PostScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-PreScripts (folder)
    |-{yourPreScript1.sql} (Build Action = None)
    |-... |-ReferenceDataScripts (folder)
    |-{yourPostScript1.sql} (Build Action = None)
    |-...
    |-Script.PostDeployment.sql (Build Action = PostDeploy)
    |-Script.PreDeployment.sql (Build Action = PreDeploy)
    |-Tables
    |-_MigrationScriptsHistory.sql (Build Action = Build)
    |-Scripts.targets
    
    • The migration scripts history table (_MigrationScriptsHistory.sql) is mandatory and must be setup with the following data definition language template:
      CREATE TABLE [dbo].[_MigrationScriptsHistory]
      (
      [ScriptNameId] NVARCHAR(255) NOT NULLPRIMARY KEY, [ExecutionDate] DATETIME2 NOT NULL, [ScriptHash] NVARCHAR(255) NOT NULL
      )
      
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
    • The project targets (Scripts.targets) must be initialized as followed:
      <?xml version="1.0" encoding="utf-8"?>
      <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
      <ImportProject="$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props"Condition="Exists('$(MSBuildExtensionsPath)\4tecture\build\CustomSSDTMigrationScripts.props')" />
      </Project>
  3. Open the .sqlproj project file in a text editor and add the following project import statement for the targets file within the projects root element:

    <ProjectDefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003"ToolsVersion="4.0">
    <ImportProject=".\Scripts.targets" />
    ...
    </Project>
  4. Rebuild your SSDT project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Setup Sample - Add a cross-platform .dacpac build project to an existing solution with an existing SQL Server Database project

Use the sample project ending with ".Sample.Build" from the Sample folder as the initial template project or follow these instructions (using the default configuration settings):

  1. Create .NET Standard Class Library

  2. Open the .csproj file and change the Sdk value and define the SQL Server target:

    <ProjectSdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>

    to

    <ProjectSdk="MSBuild.Sdk.SqlProj/1.9.0">
    <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <SqlServerVersion>Sql130</SqlServerVersion>
    </PropertyGroup>
  3. Add the nuget package reference to add the Custom SSDT extension

    <ItemGroup>
    <PackageReferenceInclude="4tecture.CustomSSDTMigrationScripts"Version="1.2.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    </ItemGroup>
  4. On the root level of the project create the following folder structure and files:

    |-Scripts
    |-PostScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-PreScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-ReferenceDataScripts (folder)
    |-.gitkeep (empty file to let git know to keep the empty folder)
    |-Script.PostDeployment.sql
    |-Script.PreDeployment.sql
    
    • The SQL pre-script (Script.PreDeployment.sql) must be setup as follow:
      :r .\RunPreScriptsGenerated.sql
    • The SQL post.script (Script.PostDeployment.sql) must be initialized as followed:
      :r .\RunReferenceDataScriptsGenerated.sql
      :r .\RunPostScriptsGenerated.sql
  5. Add a link in the new .csproj to the .sql scripts in your existing database project

    <ItemGroup>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Functions\**\*.sql">
    <Link>Functions\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Snapshots\**\*.sql">
    <Link>Snapshots\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\StoredProcedures\**\*.sql">
    <Link>StoredProcedures\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Tables\**\*.sql">
    <Link>Tables\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\UserDefinedDataTypes\**\*.sql">
    <Link>UserDefinedDataTypes\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <ContentInclude="{Relativ-SQL-Server-Database-Project-Path}\Views\**\*.sql">
    <Link>Views\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PostScripts\**\*.sql">
    <Link>Scripts\PostScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\PreScripts\**\*.sql">
    <Link>Scripts\PreScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\Scripts\ReferenceDataScripts\**\*.sql">
    <Link>Scripts\ReferenceDataScripts\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </None>
    <NoneInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog"Link="{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
  6. Define the actions to the created script files, link and use the source .refactorlog:

    <ItemGroup>
    <PostDeployInclude="Scripts\Script.PostDeployment.sql" />
    <PreDeployInclude="Scripts\Script.PreDeployment.sql" />
    <RefactorLogInclude="{Relativ-SQL-Server-Database-Project-Path}\{SQL-Server-Database-Project}.refactorlog" />
    </ItemGroup>
    <ItemGroup>
    <ContentRemove="Scripts\RunPostScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunPreScriptsGenerated.sql" />
    <ContentRemove="Scripts\RunReferenceDataScriptsGenerated.sql" />
    <ContentRemove="Scripts\Script.PostDeployment.sql" />
    <ContentRemove="Scripts\Script.PreDeployment.sql" />
    </ItemGroup>
  7. Rebuild your .Net Standard Class Library project and verify if the following files have been generated within the Script subfolder:

    • RunPostScriptsGenerated.sql
    • RunPreScriptsGenerated.sql
    • RunReferenceDataScriptsGenerated.sql

Extend .gitignore

It's recommended to add the auto-generated files to the git ignore file:

 {SQL-Server-Database-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{SQL-Server-Database-Project-Path}/Scripts/RunPostScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunReferenceDataScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPreScriptsGenerated.sql
{Net-Standard-Project-Path}/Scripts/RunPostScriptsGenerated.sql

Configuration

The extension can be easily adapted to your needs by using a json configuration file. The configuration file must be placed beside the SSDT project file named ssdt.migration.scripts.json The following snipped shows all available options where each of the supported script type can be individually configured.

{
"PreScripts": {
"ScriptBaseDirectory": "<Value>",
"ScriptNamePattern": "<Value>",
"ScriptRecursiveSearch": "<Value>",
"GeneratedScriptPath": "<Value>",
"ExecutionFilterMode": "<Value>",
"ExecutionFilterValue": "<Value>",
"TreatScriptNamePatternMismatchAsError": "<Value>",
"TreatHashMismatchAsError": "<Value>"
},
"PostScripts": {
// ...
},
"ReferenceDataScripts": {
// ...
}
}
ConfigurationDescription
ScriptBaseDirectoryThe base directory where to store the target script type.
ScriptNamePatternThe naming convention pattern used to validate and determination of execution order.
ScriptRecursiveSearchIndicates whether scripts are searched recursively from the base directory
GenerateScriptPathPath to the generated scripts
ExecutionFilterModeThe execution filter mode defines the strategy to use for execution order
ExecutionFilterValueThe corresponding value based on the selected filter mode
TreatScriptNamePatternMismatchAsErrorIndicates how pattern mismatches should be handled. Throws an error if enabled and any mismatch is detected
TreatHashMismatchAsErrorIf set to true any script change of already executed scripts will throw an error (hash based calculation). This rule does not apply to reference data scripts.

Pre Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PreScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPreScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Post Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\PostScripts-
ScriptName Pattern^(\d{14})_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunPostScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

Reference Data Configurations

Default ValueOptions
ScriptBaseDirectory{root}\Scripts\ReferenceDataScripts-
ScriptName Pattern^(\d+)_(.*).sql-
ScriptRecursiveSearchtruetrue | false
GeneratedScriptPath{root}\Scripts\RunReferenceDataScriptsGenerated.sql-
ExecutionFilterModeallall | count | days | date
ExecutionFilterValuenull
TreatScriptNamePatternMismatchAsErrortruetrue | false
TreatHashMismatchAsErrortruetrue | false

About

This extension has been developed by consultants of 4tecture based on their experience from many DevOps projects. Originally it was developed internally without public scope. However, we decided to make this open source so others can benefit, too.

Feedback is very welcome. Please open an issue on GitHub or send us a message through our website.

About

No description, website, or topics provided.

Resources

Stars

21 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages