Skip to content

Commit

Permalink
chore: added sqlserver tests (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm authored Jan 25, 2024
1 parent 30bf516 commit 7ca5089
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
integration-tests:
strategy:
matrix:
dialect: [ mysql, postgres, sqlite ]
dialect: [ mysql, postgres, sqlite, mssql ]
language: [ js, ts ]
runs-on: ubuntu-latest
steps:
Expand All @@ -84,6 +84,8 @@ jobs:
working-directory: ./${{ matrix.language }}/testdata
run: |
atlas migrate diff --env sequelize -c "file://atlas-standalone.hcl" --var dialect=${{ matrix.dialect }}
env:
ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }}
- name: Verify migrations generated
run: |
status=$(git status --porcelain)
Expand All @@ -97,6 +99,8 @@ jobs:
working-directory: ./${{ matrix.language }}/testdata
run: |
atlas migrate diff --env sequelize -c "file://atlas-script.hcl" --var dialect=${{ matrix.dialect }}
env:
ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }}
- name: Verify migrations generated
run: |
status=$(git status --porcelain)
Expand Down
1 change: 1 addition & 0 deletions js/testdata/atlas-script.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ locals {
dev_url = {
mysql = "docker://mysql/8/dev"
postgres = "docker://postgres/15"
mssql = "docker://sqlserver/2022-latest"
sqlite = "sqlite://file::memory:?cache=shared"
}[var.dialect]
}
Expand Down
1 change: 1 addition & 0 deletions js/testdata/atlas-standalone.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ locals {
dev_url = {
mysql = "docker://mysql/8/dev"
postgres = "docker://postgres/15"
mssql = "docker://sqlserver/2022-latest"
sqlite = "sqlite://file::memory:?cache=shared"
}[var.dialect]
}
Expand Down
58 changes: 58 additions & 0 deletions js/testdata/migrations/mssql/20240125063717.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Create "Ingredients" table
CREATE TABLE [Ingredients] (
[id] int IDENTITY (1, 1) NOT NULL,
[name] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[createdAt] datetimeoffset(7) NOT NULL,
[updatedAt] datetimeoffset(7) NOT NULL,
[deletedAt] datetimeoffset(7) NULL,
CONSTRAINT [PK_Ingredients] PRIMARY KEY CLUSTERED ([id] ASC)
);
-- Create "RecipeIngredients" table
CREATE TABLE [RecipeIngredients] (
[recipeId] int NOT NULL,
[ingredientId] int NOT NULL,
[meassurementAmount] int NOT NULL,
[meassurementType] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[createdAt] datetimeoffset(7) NOT NULL,
[updatedAt] datetimeoffset(7) NOT NULL,
[deletedAt] datetimeoffset(7) NULL,
CONSTRAINT [PK_RecipeIngredients] PRIMARY KEY CLUSTERED ([ingredientId] ASC)
);
-- Create index "recipe_ingredients_meassurement_type_meassurement_amount" to table: "RecipeIngredients"
CREATE UNIQUE NONCLUSTERED INDEX [recipe_ingredients_meassurement_type_meassurement_amount] ON [RecipeIngredients] ([meassurementType] ASC, [meassurementAmount] ASC);
-- Create "Recipes" table
CREATE TABLE [Recipes] (
[id] int IDENTITY (1, 1) NOT NULL,
[title] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[description] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[instructions] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[userId] int NOT NULL,
[meal] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[createdAt] datetimeoffset(7) NOT NULL,
[updatedAt] datetimeoffset(7) NOT NULL,
[deletedAt] datetimeoffset(7) NULL,
CONSTRAINT [PK_Recipes] PRIMARY KEY CLUSTERED ([id] ASC),
CONSTRAINT [CK__Recipes__meal__24B26D99] CHECK ([meal]=N'dessert' OR [meal]=N'dinner' OR [meal]=N'lunch' OR [meal]=N'breakfast')
);
-- Create "Users" table
CREATE TABLE [Users] (
[id] int IDENTITY (1, 1) NOT NULL,
[name] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[recipeId] int NOT NULL,
[createdAt] datetimeoffset(7) NOT NULL,
[updatedAt] datetimeoffset(7) NOT NULL,
[deletedAt] datetimeoffset(7) NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED ([id] ASC)
);
-- Modify "RecipeIngredients" table
ALTER TABLE [RecipeIngredients] ADD
CONSTRAINT [FK__RecipeIng__ingre__2882FE7D] FOREIGN KEY ([ingredientId]) REFERENCES [Ingredients] ([id]) ON UPDATE NO ACTION ON DELETE CASCADE;
-- Modify "RecipeIngredients" table
ALTER TABLE [RecipeIngredients] ADD
CONSTRAINT [FK__RecipeIng__recip__278EDA44] FOREIGN KEY ([recipeId]) REFERENCES [Recipes] ([id]) ON UPDATE NO ACTION ON DELETE CASCADE;
-- Modify "Recipes" table
ALTER TABLE [Recipes] ADD
CONSTRAINT [FK__Recipes__userId__297722B6] FOREIGN KEY ([userId]) REFERENCES [Users] ([id]) ON UPDATE NO ACTION ON DELETE CASCADE;
-- Modify "Users" table
ALTER TABLE [Users] ADD
CONSTRAINT [FK__Users__recipeId__2A6B46EF] FOREIGN KEY ([recipeId]) REFERENCES [Recipes] ([id]) ON UPDATE NO ACTION ON DELETE NO ACTION;
2 changes: 2 additions & 0 deletions js/testdata/migrations/mssql/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:t50PTQpKOaHIuiXnAubYw31bV1R/qE41TJW+02+yO0Q=
20240125063717.sql h1:S5GLiSBdZWdEANYRKyFROvOxU1i3szOlcfhO8R3qJDs=
2 changes: 1 addition & 1 deletion js/testdata/migrations/mysql/20231225122102.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ ALTER TABLE `RecipeIngredients` ADD CONSTRAINT `RecipeIngredients_ibfk_1` FOREIG
-- Modify "Recipes" table
ALTER TABLE `Recipes` ADD CONSTRAINT `Recipes_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `Users` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;
-- Modify "Users" table
ALTER TABLE `Users` ADD CONSTRAINT `Users_ibfk_1` FOREIGN KEY (`recipeId`) REFERENCES `Recipes` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE `Users` ADD CONSTRAINT `Users_ibfk_1` FOREIGN KEY (`recipeId`) REFERENCES `Recipes` (`id`) ON UPDATE CASCADE ON DELETE NO ACTION;
4 changes: 2 additions & 2 deletions js/testdata/migrations/mysql/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
h1:OgZsNGmgX9py3k61Yf+DCuyflbFmgILvTDvwJBdVvho=
20231225122102.sql h1:ClhnG2UKDb5t+dwNFT6lcEGeXAG9AXvlwUzq4RwWnUQ=
h1:ZMbeDJy9/UBOrkKW6GTUOpxw4xCokB8VnOcX/dKx4Ok=
20231225122102.sql h1:Gkocec7Hymg6mDLibLeLshwK/qvMWyOJN6MQNcUc67M=
2 changes: 1 addition & 1 deletion js/testdata/migrations/postgres/20231225122022.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ ALTER TABLE "public"."Recipes" ADD
CONSTRAINT "Recipes_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."Users" ("id") ON UPDATE CASCADE ON DELETE CASCADE;
-- Modify "Users" table
ALTER TABLE "public"."Users" ADD
CONSTRAINT "Users_recipeId_fkey" FOREIGN KEY ("recipeId") REFERENCES "public"."Recipes" ("id") ON UPDATE CASCADE ON DELETE CASCADE;
CONSTRAINT "Users_recipeId_fkey" FOREIGN KEY ("recipeId") REFERENCES "public"."Recipes" ("id") ON UPDATE CASCADE ON DELETE NO ACTION;
4 changes: 2 additions & 2 deletions js/testdata/migrations/postgres/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
h1:kv5cFbgcvOA0iW5aiYEf+uQBNZWzgW7SQ3ESNF8G7AM=
20231225122022.sql h1:vB3ZaP+BqXaKCVjtxtuH++OOA1r/EvpuPf7t88i5QJ8=
h1:hXrIihYHMGg9tBMY5e9sKtwvu/T/tFFvXHC9BHi40To=
20231225122022.sql h1:ckN+59j8Sq8OgJjgVVdPdLsWGgAp8Xb4fjuC+YlX2vM=
2 changes: 1 addition & 1 deletion js/testdata/migrations/sqlite/20231225122837.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ CREATE TABLE `Users` (
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
`deletedAt` datetime NULL,
CONSTRAINT `0` FOREIGN KEY (`recipeId`) REFERENCES `Recipes` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
CONSTRAINT `0` FOREIGN KEY (`recipeId`) REFERENCES `Recipes` (`id`) ON UPDATE CASCADE ON DELETE NO ACTION
);
4 changes: 2 additions & 2 deletions js/testdata/migrations/sqlite/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
h1:tInqZl0Eg+lKPRULTifvfDQozfbKgzUDFbipWDlVw/w=
20231225122837.sql h1:x4/DEpFPl2hmd78T7wgkaxcUwYkyD5kqyaqjXOkOCIs=
h1:1O5jNja57eN4F511oqxrd6evCvvIDyM6kaqzRygx7hg=
20231225122837.sql h1:8nxlw6ktQ/RbpEBPSYv8JqdEUATjPOBVIZt2tro5Ock=
2 changes: 2 additions & 0 deletions js/testdata/models/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module.exports = function (sequelize, DataTypes) {
Recipe.hasMany(models.User, {
foreignKey: "recipeId",
as: "users",
// sequelize defaults to CASCADE, which cause circular dependency for MSSQL
onDelete: "NO ACTION",
});
};

Expand Down
1 change: 1 addition & 0 deletions ts/testdata/atlas-script.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ locals {
dev_url = {
mysql = "docker://mysql/8/dev"
postgres = "docker://postgres/15"
mssql = "docker://sqlserver/2022-latest"
sqlite = "sqlite://file::memory:?cache=shared"
}[var.dialect]
}
Expand Down
1 change: 1 addition & 0 deletions ts/testdata/atlas-standalone.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ locals {
dev_url = {
mysql = "docker://mysql/8/dev"
postgres = "docker://postgres/15"
mssql = "docker://sqlserver/2022-latest"
sqlite = "sqlite://file::memory:?cache=shared"
}[var.dialect]
}
Expand Down
35 changes: 35 additions & 0 deletions ts/testdata/migrations/mssql/20240125063755.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Create "contact" table
CREATE TABLE [contact] (
[id] int IDENTITY (1, 1) NOT NULL,
[name] nvarchar(45) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[alias] nvarchar(45) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[created_at] datetimeoffset(7) NOT NULL,
[updated_at] datetimeoffset(7) NOT NULL,
CONSTRAINT [PK_contact] PRIMARY KEY CLUSTERED ([id] ASC)
);
-- Create index "name-alias" to table: "contact"
CREATE UNIQUE NONCLUSTERED INDEX [name-alias] ON [contact] ([name] ASC, [alias] ASC);
-- Create "email" table
CREATE TABLE [email] (
[id] int IDENTITY (1, 1) NOT NULL,
[email] nvarchar(60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[subscription] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[contact_id] int NOT NULL,
[created_at] datetimeoffset(7) NOT NULL,
[updated_at] datetimeoffset(7) NOT NULL,
CONSTRAINT [PK_email] PRIMARY KEY CLUSTERED ([id] ASC),

CONSTRAINT [FK__email__contact_i__23BE4960] FOREIGN KEY ([contact_id]) REFERENCES [contact] ([id]) ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT [CK__email__subscript__22CA2527] CHECK ([subscription]=N'premium' OR [subscription]=N'basic' OR [subscription]=N'free')
);
-- Create "phone" table
CREATE TABLE [phone] (
[id] int IDENTITY (1, 1) NOT NULL,
[phone] nvarchar(20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[contact_id] int NOT NULL,
[created_at] datetimeoffset(7) NOT NULL,
[updated_at] datetimeoffset(7) NOT NULL,
CONSTRAINT [PK_phone] PRIMARY KEY CLUSTERED ([id] ASC),

CONSTRAINT [FK__phone__contact_i__269AB60B] FOREIGN KEY ([contact_id]) REFERENCES [contact] ([id]) ON UPDATE NO ACTION ON DELETE CASCADE
);
2 changes: 2 additions & 0 deletions ts/testdata/migrations/mssql/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:TPNUI1REUblqUeMJvck7gUOqKsgdW3rQFOSCO4o+Rcc=
20240125063755.sql h1:P2/Rns5QC+V8A/DzmleyT5/dyTh66pAbKF4cVpz2RIU=

0 comments on commit 7ca5089

Please sign in to comment.