diff --git a/src/Arcus.Scripting.Sql/Scripts/Invoke-AzSqlDatabaseMigration.ps1 b/src/Arcus.Scripting.Sql/Scripts/Invoke-AzSqlDatabaseMigration.ps1 index b487ac80..869acfcd 100644 --- a/src/Arcus.Scripting.Sql/Scripts/Invoke-AzSqlDatabaseMigration.ps1 +++ b/src/Arcus.Scripting.Sql/Scripts/Invoke-AzSqlDatabaseMigration.ps1 @@ -140,8 +140,8 @@ for ($i = 0; $i -lt $files.Count; $i++) { $migrationDescription = $migrationDescription.Substring(0, 256) } - $updateVersionQuery = "INSERT INTO [$DatabaseSchema].[DatabaseVersion] ([MajorVersionNumber], [MinorVersionNumber], [PatchVersionNumber], [MigrationDescription], [MigrationDate]) " + - "SELECT $($scriptVersionNumber.MajorVersionNumber), $($scriptVersionNumber.MinorVersionNumber), $($scriptVersionNumber.PatchVersionNumber), '$migrationDescription', getdate()" + $updateVersionQuery = "INSERT INTO [$DatabaseSchema].[DatabaseVersion] ([MajorVersionNumber], [MinorVersionNumber], [PatchVersionNumber], [MigrationDescription], [MigrationDate]) " + + "SELECT $($scriptVersionNumber.MajorVersionNumber), $($scriptVersionNumber.MinorVersionNumber), $($scriptVersionNumber.PatchVersionNumber), '$migrationDescription', getdate()" Execute-DbCommand $params $updateVersionQuery diff --git a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Sql.tests.ps1 b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Sql.tests.ps1 index fcc8f444..d04661df 100644 --- a/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Sql.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Integration/Arcus.Scripting.Sql.tests.ps1 @@ -2,14 +2,14 @@ Import-Module SqlServer Import-Module -Name $PSScriptRoot\..\Arcus.Scripting.Sql -ErrorAction Stop function global:Run-AzSqlCommand ($params, $command) { - Invoke-Sqlcmd @params -Query $command -Verbose -QueryTimeout 180 -ErrorAction Stop -ErrorVariable err + Invoke-Sqlcmd @params -Query $command -Verbose -QueryTimeout 180 -ConnectionTimeout 60 -ErrorAction Stop -ErrorVariable err if ($err) { throw ($err) } } function global:Run-AzSqlQuery ($params, $query) { - $result = Invoke-Sqlcmd @params -Query $query -Verbose -ErrorAction Stop -ErrorVariable err + $result = Invoke-Sqlcmd @params -Query $query -Verbose -ConnectionTimeout 60 -ErrorAction Stop -ErrorVariable err if ($err) { throw ($err) } @@ -17,70 +17,124 @@ function global:Run-AzSqlQuery ($params, $query) { } function global:Drop-AzSqlDatabaseTable ($params, $databaseTable, $schema = "dbo") { - Run-AzSqlCommand $params "DROP TABLE [$schema].[$databaseTable]" + Run-AzSqlCommand $params "DROP TABLE IF EXISTS [$schema].[$databaseTable]" } function global:Get-AzSqlDatabaseVersion ($params, $schema = "dbo") { $row = Run-AzSqlQuery $params "SELECT TOP 1 MajorVersionNumber, MinorVersionNumber, PatchVersionNumber FROM [$schema].[DatabaseVersion] ORDER BY MajorVersionNumber DESC, MinorVersionNumber DESC, PatchVersionNumber DESC" $version = [DatabaseVersion]::new() - if ($row -ne $row) { + if (($null -ne $row) -and ($null -ne $row.ItemArray) -and ($row.ItemArray.Length -ge 3) ) { $version = [DatabaseVersion]::new( - [convert]::ToInt32($databaseVersionNumberDataRow.ItemArray[0]), - [convert]::ToInt32($databaseVersionNumberDataRow.ItemArray[1]), - [convert]::ToInt32($databaseVersionNumberDataRow.ItemArray[2])) + [convert]::ToInt32($row.ItemArray[0]), + [convert]::ToInt32($row.ItemArray[1]), + [convert]::ToInt32($row.ItemArray[2])) } return $version } +function global:AssertDatabaseVersion ($row, [DatabaseVersion]$expectedVersion) { + [convert]::ToInt32($row.ItemArray[0]) | Should -Be $expectedVersion.MajorVersionNumber + [convert]::ToInt32($row.ItemArray[1]) | Should -Be $expectedVersion.MinorVersionNumber + [convert]::ToInt32($row.ItemArray[2]) | Should -Be $expectedVersion.PatchVersionNumber +} + +function global:Create-MigrationTable ($params) { + $createTable = "CREATE TABLE dbo.[DatabaseVersion] " + + "( " + + " [MajorVersionNumber] INT NOT NULL, " + + " [MinorVersionNumber] INT NOT NULL, " + + " [PatchVersionNumber] INT NOT NULL, " + + " [MigrationDescription] [nvarchar](256) NOT NULL, " + + " [MigrationDate] DATETIME NOT NULL " + + " CONSTRAINT [PK_DatabaseVersion] PRIMARY KEY CLUSTERED ([MajorVersionNumber],[MinorVersionNumber],[PatchVersionNumber]) " + + " WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) " + + ")" + + Run-AzSqlCommand $params $createTable +} + +function global:TableExists($params, $tableName) { + $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '$tableName' AND TABLE_CATALOG = '$($params.Database)'" + + if ($result.ItemArray[0] -eq 1) { + return $true + } + + return $false +} + +function global:ColumnExists($params, $tableName, $columnName) { + $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$tableName' AND COLUMN_NAME = '$columnName'" + + if ($result.ItemArray[0] -eq 1) { + return $true + } + + return $false +} + + InModuleScope Arcus.Scripting.Sql { Describe "Arcus Azure SQL integration tests" { - BeforeEach { + BeforeAll { + $filePath = "$PSScriptRoot\appsettings.json" [string]$appsettings = Get-Content $filePath $config = ConvertFrom-Json $appsettings $params = @{ - 'ServerInstance' = $config.Arcus.Sql.ServerName - 'Database' = $config.Arcus.Sql.DatabaseName - 'Username' = $config.Arcus.Sql.UserName - 'Password' = $config.Arcus.Sql.Password - 'OutputSqlErrors' = $true - 'AbortOnError' = $true + 'ServerInstance' = $config.Arcus.Sql.ServerName + 'Database' = $config.Arcus.Sql.DatabaseName + 'Username' = $config.Arcus.Sql.UserName + 'Password' = $config.Arcus.Sql.Password + 'OutputSqlErrors' = $true + 'AbortOnError' = $true } & $PSScriptRoot\Connect-AzAccountFromConfig.ps1 -config $config + + # Try to open a connection to the SQL database, so that the + # Azure Database that can be paused, is starting up. This should + # avoid having timeout errors during the test themselves. + try { + Write-Host "Execute dummy SQL statement to make sure the Azure SQL DB is resumed." + Invoke-Sqlcmd @params -Query "SELECT TOP 1 FROM INFORMATION_SCHEMA.TABLES" -ConnectionTimeout 60 -Verbose + } + catch { + # We don't care if an exception is thrown; we just want to 'activate' the Azure SQL database + } + } + AfterEach { + Drop-AzSqlDatabaseTable $params "DatabaseVersion" } Context "DatabaseVersion table" { It "Invoke first SQL migration on empty database creates new DatabaseVersion table" { # Arrange { Get-AzSqlDatabaseVersion $params } | Should -Throw - try { - # Act - Invoke-AzSqlDatabaseMigration ` - -ServerName $config.Arcus.Sql.ServerName ` - -DatabaseName $config.Arcus.Sql.DatabaseName ` - -Username $config.Arcus.Sql.Username ` - -Password $config.Arcus.Sql.Password ` - -ScriptsFolder "$PSScriptRoot\SqlScripts" + # Act + Invoke-AzSqlDatabaseMigration ` + -ServerName $config.Arcus.Sql.ServerName ` + -DatabaseName $config.Arcus.Sql.DatabaseName ` + -Username $config.Arcus.Sql.Username ` + -Password $config.Arcus.Sql.Password ` + -ScriptsFolder "$PSScriptRoot\SqlScripts" - # Assert - $version = Get-AzSqlDatabaseVersion $params - $version.MajorVersionNumber | Should -Be 0 - $version.MinorVersionNumber | Should -Be 0 - $version.PatchVersionNumber | Should -Be 0 - } finally { - Drop-AzSqlDatabaseTable $params "DatabaseVersion" - } + # Assert + $version = Get-AzSqlDatabaseVersion $params + $version.MajorVersionNumber | Should -Be 1 + $version.MinorVersionNumber | Should -Be 0 + $version.PatchVersionNumber | Should -Be 0 } It "Invoke first SQL migration with custom schema on empty database creates new DataVersion table with custom schema" { # Arrange { Get-AzSqlDatabaseVersion $params } | Should -Throw - $customSchema = "custom" - Run-AzSqlCommand $params "CREATE SCHEMA $customSchema" try { + $customSchema = "custom" + Run-AzSqlCommand $params "CREATE SCHEMA $customSchema" + # Act Invoke-AzSqlDatabaseMigration ` -ServerName $config.Arcus.Sql.ServerName ` @@ -92,10 +146,11 @@ InModuleScope Arcus.Scripting.Sql { # Assert $version = Get-AzSqlDatabaseVersion $params $customSchema - $version.MajorVersionNumber | Should -Be 0 + $version.MajorVersionNumber | Should -Be 1 $version.MinorVersionNumber | Should -Be 0 $version.PatchVersionNumber | Should -Be 0 - } finally { + } + finally { Drop-AzSqlDatabaseTable $params "DatabaseVersion" $customSchema Run-AzSqlCommand $params "DROP SCHEMA $customSchema" } @@ -112,34 +167,158 @@ InModuleScope Arcus.Scripting.Sql { WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ` ) " Run-AzSqlCommand $params $createOldDatabaseVersionTable + + # Act + Invoke-AzSqlDatabaseMigration ` + -ServerName $config.Arcus.Sql.ServerName ` + -DatabaseName $config.Arcus.Sql.DatabaseName ` + -Username $config.Arcus.Sql.Username ` + -Password $config.Arcus.Sql.Password ` + -ScriptsFolder "$PSScriptRoot\SqlScripts" + + # Assert + $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'MajorVersionNumber' AND TABLE_SCHEMA = 'dbo'" + $result.ItemArray[0] | Should -Be 1 -Because "MajorVersionNumber column should be present" + $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'MinorVersionNumber' AND TABLE_SCHEMA = 'dbo'" + $result.ItemArray[0] | Should -Be 1 -Because "MinorVersionNumber column should be present" + $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'PatchVersionNumber' AND TABLE_SCHEMA = 'dbo'" + $result.ItemArray[0] | Should -Be 1 -Because "PatchVersionNumber column should be present" + $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'CurrentVersionNumber' AND TABLE_SCHEMA = 'dbo'" + $result.ItemArray[0] | Should -Be 0 -Because "CurrentVersionNumber column should no longer be present with new table-structure" + + $version = Get-AzSqlDatabaseVersion $params + $version.MajorVersionNumber | Should -Be 1 + $version.MinorVersionNumber | Should -Be 0 + $version.PatchVersionNumber | Should -Be 0 + } + } + Context "Migrations - Happy Path" { + It "Multiple migrations are invoked in the correct order, ignoring lower version migrations" { + # Arrange: Create the DatabaseVersion table and pre-populate it + Create-MigrationTable $params + + $addBaselineRecord = "INSERT INTO [DatabaseVersion] ([MajorVersionNumber], [MinorVersionNumber], [PatchVersionNumber], [MigrationDescription], [MigrationDate]) SELECT 0, 0, 1, 'Baseline', getdate()" + + Run-AzSqlCommand $params $addBaselineRecord try { - # Act + # Act: execute the specified migration-scripts Invoke-AzSqlDatabaseMigration ` -ServerName $config.Arcus.Sql.ServerName ` -DatabaseName $config.Arcus.Sql.DatabaseName ` -Username $config.Arcus.Sql.Username ` -Password $config.Arcus.Sql.Password ` - -ScriptsFolder "$PSScriptRoot\SqlScripts" + -ScriptsFolder "$PSScriptRoot\SqlScripts\MigrationScriptsAreSuccessfullyExecuted" # Assert - $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'MajorVersionNumber'" - $result.ItemArray[0] | Should -Be 1 - $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'MinorVersionNumber'" - $result.ItemArray[0] | Should -Be 1 - $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'PatchVersionNumber'" - $result.ItemArray[0] | Should -Be 1 - $result = Run-AzSqlQuery $params "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'DatabaseVersion' AND COLUMN_NAME = 'CurrentVersionNumber'" - $result.ItemArray[0] | Should -Be 0 + # The MigrationScriptsAreSuccessfullyExecuted folder contains a file which has version-number 0.0.1 + # That migration-file creates the table 'NonExistingTable', however, when setting up this testcase + # we have inserted a record in the DatabaseVersion-table which indicates that this version/migration-file was already + # executed. If the Invoke-AzSqlDatabaseMigration script runs correctly, it should skip the migration-file with version 0.0.1 + # which means that the table 'NonExistingTable' should not exist in the DB. + # If it does exist in the DB, then it means that the 0.0.1 migration-script was executed anyway. + $result = TableExists $params 'NonExistingTable' + $result | Should -Be $false -Because 'DatabaseVersion was initialized with version that introduced this table, so script should not have been executed' + + # A migration-script in the MigrationScriptsAreSuccessfullyExecuted folder contains a migration-file + # that creates the Customer table. + # However, there also exists a migration-script with a higher version in that folder which renames the + # Customer table to 'Person'. This means that the Customer table should not exist anymore. + $result = TableExists $params 'Customer' + $result | Should -Be $false -Because 'Customer table should have been renamed' + # The Customer table was renamed to Person + $result = TableExists $params 'Person' + $result | Should -Be $true -Because 'migration-script renamed Customer table to Person table' + + # After the Customer table has been renamed to Person, another migration-script + # should have added a new column (Address) to the Person table. + $result = ColumnExists $params 'Person' 'Address' + $result | Should -Be $true -Because 'Migration script added additional Address column to table' + $version = Get-AzSqlDatabaseVersion $params - $version.MajorVersionNumber | Should -Be 0 + $version.MajorVersionNumber | Should -Be 1 $version.MinorVersionNumber | Should -Be 0 $version.PatchVersionNumber | Should -Be 0 - } finally { - Drop-AzSqlDatabaseTable $params "DatabaseVersion" } + finally { + Drop-AzSqlDatabaseTable $params "Person" + Drop-AzSqlDatabaseTable $params "Customer" + } + } + } + Context "Migrations - Unhappy path" { + It "Multiple migrations are invoked until error encountered" { + + # Act and arrange: execute the specified migration-scripts + { Invoke-AzSqlDatabaseMigration ` + -ServerName $config.Arcus.Sql.ServerName ` + -DatabaseName $config.Arcus.Sql.DatabaseName ` + -Username $config.Arcus.Sql.Username ` + -Password $config.Arcus.Sql.Password ` + -ScriptsFolder "$PSScriptRoot\SqlScripts\MigrationStopsOnError" } | Should -Throw + + $version = Get-AzSqlDatabaseVersion $params + $version.MajorVersionNumber | Should -Be 1 -Because "latest successfull migration-script has major version number 1" + $version.MinorVersionNumber | Should -Be 0 -Because "latest successfull migration-script has major version number 0" + $version.PatchVersionNumber | Should -Be 0 -Because "latest successfull migration-script has major version number 0" } } + Context "MigrationScripts - naming convention" { + It "Old script naming convention is still supported" { + + # Act: execute migration-scripts where the naming convention of those files + # is a mix between the old (versionnumber_description.sql) naming convention + # and the new (major.minor.patch_description.sql) naming convention. + Invoke-AzSqlDatabaseMigration ` + -ServerName $config.Arcus.Sql.ServerName ` + -DatabaseName $config.Arcus.Sql.DatabaseName ` + -Username $config.Arcus.Sql.Username ` + -Password $config.Arcus.Sql.Password ` + -ScriptsFolder "$PSScriptRoot\SqlScripts\OldMigrationScriptsAreStillSupported" + + $version = Get-AzSqlDatabaseVersion $params + $version.MajorVersionNumber | Should -Be 2 -Because "latest migration-script has version number 2" + $version.MinorVersionNumber | Should -Be 0 -Because "Old migration scripts are used that do not have a minor version number" + $version.PatchVersionNumber | Should -Be 0 -Because "Old migration scripts are used that do not have a patch version number" + } + It "Combination of old and new migration-script naming convention is supported" { + try { + # Act and arrange: execute the specified migration-scripts + Invoke-AzSqlDatabaseMigration ` + -ServerName $config.Arcus.Sql.ServerName ` + -DatabaseName $config.Arcus.Sql.DatabaseName ` + -Username $config.Arcus.Sql.Username ` + -Password $config.Arcus.Sql.Password ` + -ScriptsFolder "$PSScriptRoot\SqlScripts\OldAndNewNamingConventionSupported" + + $version = Get-AzSqlDatabaseVersion $params + $version.MajorVersionNumber | Should -Be 3 -Because "latest migration-script has version number 3" + $version.MinorVersionNumber | Should -Be 0 + $version.PatchVersionNumber | Should -Be 0 + + $versions = Run-AzSqlQuery $params "SELECT MajorVersionNumber, MinorVersionNumber, PatchVersionNumber FROM DatabaseVersion ORDER BY MigrationDate ASC" + + $versions.Length | Should -Be 6 + + $expectedVersions = @( + [DatabaseVersion]::new(0, 0, 1), + [DatabaseVersion]::new(1, 0, 0), + [DatabaseVersion]::new(2, 0, 0), + [DatabaseVersion]::new(2, 0, 1), + [DatabaseVersion]::new(2, 1, 0), + [DatabaseVersion]::new(3, 0, 0) + ) + + for ($i = 0; $i -lt $versions.Length; $i++) { + AssertDatabaseVersion $versions[$i] $expectedVersions[$i] + } + } + finally { + Drop-AzSqlDatabaseTable $params "Person" + Drop-AzSqlDatabaseTable $params "Customer" + } + } + } } } diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.0.1_baseline.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.0.1_baseline.sql new file mode 100644 index 00000000..ef032c8b --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.0.1_baseline.sql @@ -0,0 +1,5 @@ +CREATE TABLE NonExistingTable +( + [Id] INT, + [Description] NVARCHAR(20) +) \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.1.0_AddCustomerTable.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.1.0_AddCustomerTable.sql new file mode 100644 index 00000000..4cb58376 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.1.0_AddCustomerTable.sql @@ -0,0 +1,5 @@ +CREATE TABLE [Customer] +( + [Id] INT, + [Name] NVARCHAR(20) +) \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.2.0_AlterCustomerTable.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.2.0_AlterCustomerTable.sql new file mode 100644 index 00000000..7382f7e2 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/0.2.0_AlterCustomerTable.sql @@ -0,0 +1,2 @@ +ALTER TABLE [Customer] + ADD [Address] NVARCHAR(255) \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/1.0.0_RenameCustomerTable.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/1.0.0_RenameCustomerTable.sql new file mode 100644 index 00000000..e4568494 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationScriptsAreSuccessfullyExecuted/1.0.0_RenameCustomerTable.sql @@ -0,0 +1 @@ +sp_rename [Customer], [Person] \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.0.0_initialversion.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.0.0_initialversion.sql new file mode 100644 index 00000000..e767914d --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.0.0_initialversion.sql @@ -0,0 +1 @@ +SELECT * FROM INFORMATION_SCHEMA.TABLES \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.1.0_erroneousmigration.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.1.0_erroneousmigration.sql new file mode 100644 index 00000000..1891acc0 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.1.0_erroneousmigration.sql @@ -0,0 +1 @@ +SELECT * FROM NonExistingTable \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.2.0_latestversion.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/MigrationStopsOnError/1.2.0_latestversion.sql new file mode 100644 index 00000000..e69de29b diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/0.0.1_baseline.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/0.0.1_baseline.sql new file mode 100644 index 00000000..65f7e3b5 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/0.0.1_baseline.sql @@ -0,0 +1,5 @@ +CREATE TABLE [Person] +( + [Id] INT, + [Name] VARCHAR(50) +) \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/1_version.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/1_version.sql new file mode 100644 index 00000000..424a482e --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/1_version.sql @@ -0,0 +1 @@ +sp_rename 'Person', 'Customer' \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2.0.1_version.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2.0.1_version.sql new file mode 100644 index 00000000..6e1b344e --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2.0.1_version.sql @@ -0,0 +1,4 @@ +INSERT INTO [Customer] +([Id], [Name], [Address]) +VALUES +(1, 'Name', 'Street') \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2.1.0_version.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2.1.0_version.sql new file mode 100644 index 00000000..39595945 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2.1.0_version.sql @@ -0,0 +1,2 @@ +ALTER TABLE [Customer] + ALTER COLUMN [Address] VARCHAR(250) NOT NULL \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2_version.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2_version.sql new file mode 100644 index 00000000..cf25f8c2 --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/2_version.sql @@ -0,0 +1,2 @@ +ALTER TABLE Customer + ADD [Address] VARCHAR(250) \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/3_version.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/3_version.sql new file mode 100644 index 00000000..757eb3db --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldAndNewNamingConventionSupported/3_version.sql @@ -0,0 +1,2 @@ +ALTER TABLE [Customer] + DROP COLUMN [Address] \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldMigrationScriptsAreStillSupported/1_EmptyMigration.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldMigrationScriptsAreStillSupported/1_EmptyMigration.sql new file mode 100644 index 00000000..e767914d --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldMigrationScriptsAreStillSupported/1_EmptyMigration.sql @@ -0,0 +1 @@ +SELECT * FROM INFORMATION_SCHEMA.TABLES \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldMigrationScriptsAreStillSupported/2_AnotherEmptyMigration.sql b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldMigrationScriptsAreStillSupported/2_AnotherEmptyMigration.sql new file mode 100644 index 00000000..e767914d --- /dev/null +++ b/src/Arcus.Scripting.Tests.Integration/SqlScripts/OldMigrationScriptsAreStillSupported/2_AnotherEmptyMigration.sql @@ -0,0 +1 @@ +SELECT * FROM INFORMATION_SCHEMA.TABLES \ No newline at end of file