Skip to content

Commit

Permalink
tests: add atlas migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luantranminh committed Aug 9, 2024
1 parent 96f75c4 commit 93df070
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
dialect: [mysql, postgres, sqlserver, sqlite]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -83,6 +84,22 @@ jobs:
shell: pwsh
working-directory: ./src/Atlas.Provider.Demo
run: dotnet atlas-ef -- sqlserver
- name: Check migrations for ${{ matrix.dialect }}
shell: pwsh
working-directory: ./src/Atlas.Provider.Demo
run: |
atlas migrate diff --env ef --var dialect=${{ matrix.dialect }}
env:
ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }}
- name: Verify migrations generated
run: |
status=$(git status --porcelain)
if [ -n "$status" ]; then
echo "you need to run 'atlas migrate diff --env ef' and commit the changes"
echo "$status"
git --no-pager diff
exit 1
fi
test:
name: Test (${{ matrix.os }})
Expand Down
33 changes: 33 additions & 0 deletions src/Atlas.Provider.Demo/atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variable "dialect" {
type = string
}

locals {
dev_url = {
mysql = "docker://mysql/8/dev"
postgres = "docker://postgres/15"
sqlserver = "docker://sqlserver/2022-latest"
sqlite = "sqlite://file::memory:?cache=shared"
}[var.dialect]
}

data "external_schema" "ef" {
program = [
"dotnet",
"atlas-ef",
"--", var.dialect,
]
}

env "ef" {
src = data.external_schema.ef.url
dev = local.dev_url
migration {
dir = "file://migrations/${var.dialect}"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
21 changes: 21 additions & 0 deletions src/Atlas.Provider.Demo/migrations/mysql/20240801062628.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Create "Blogs" table
CREATE TABLE `Blogs` (
`BlogId` int NOT NULL AUTO_INCREMENT,
`Url` varchar(200) NOT NULL,
`Rating` decimal(5,2) NOT NULL,
`Title` longtext NOT NULL,
`Content` longtext NOT NULL,
`Author` varchar(200) NOT NULL DEFAULT "Anonymous",
PRIMARY KEY (`BlogId`),
UNIQUE INDEX `AK_Blogs_Url` (`Url`)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
-- Create "Post" table
CREATE TABLE `Post` (
`PostId` int NOT NULL AUTO_INCREMENT,
`Title` longtext NOT NULL,
`Content` longtext NOT NULL,
`BlogUrl` varchar(200) NULL,
PRIMARY KEY (`PostId`),
INDEX `IX_Post_BlogUrl` (`BlogUrl`),
CONSTRAINT `FK_Post_Blogs_BlogUrl` FOREIGN KEY (`BlogUrl`) REFERENCES `Blogs` (`Url`) ON UPDATE NO ACTION ON DELETE NO ACTION
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
2 changes: 2 additions & 0 deletions src/Atlas.Provider.Demo/migrations/mysql/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:5fH6Rflvu1KK+Ic9C3Gmh6xB+7/BGljfGnQRQxQJlEE=
20240801062628.sql h1:Fe+/2wnZoHlL8dkd4M+AUQ5HDN8MWOqO+HYRiKNgVkg=
22 changes: 22 additions & 0 deletions src/Atlas.Provider.Demo/migrations/postgres/20240801063041.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Create "Blogs" table
CREATE TABLE "public"."Blogs" (
"BlogId" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Url" character varying(200) NOT NULL,
"Rating" numeric(5,2) NOT NULL,
"Title" text NOT NULL,
"Content" text NOT NULL,
"Author" character varying(200) NOT NULL DEFAULT 'Anonymous',
PRIMARY KEY ("BlogId"),
CONSTRAINT "AK_Blogs_Url" UNIQUE ("Url")
);
-- Create "Post" table
CREATE TABLE "public"."Post" (
"PostId" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"Title" text NOT NULL,
"Content" text NOT NULL,
"BlogUrl" character varying(200) NULL,
PRIMARY KEY ("PostId"),
CONSTRAINT "FK_Post_Blogs_BlogUrl" FOREIGN KEY ("BlogUrl") REFERENCES "public"."Blogs" ("Url") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create index "IX_Post_BlogUrl" to table: "Post"
CREATE INDEX "IX_Post_BlogUrl" ON "public"."Post" ("BlogUrl");
2 changes: 2 additions & 0 deletions src/Atlas.Provider.Demo/migrations/postgres/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:RrEgzMnaMIrwlUtSCD34giSU1V37NUy1RCt+3sGsULg=
20240801063041.sql h1:TeGzHV6ca+FPLdTm5X4jiMyXCui1YzmSjKKPtxorAi0=
21 changes: 21 additions & 0 deletions src/Atlas.Provider.Demo/migrations/sqlite/20240801062611.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Create "Blogs" table
CREATE TABLE `Blogs` (
`BlogId` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
`Url` varchar NOT NULL,
`Rating` decimal NOT NULL,
`Title` text NOT NULL,
`Content` text NOT NULL,
`Author` text NOT NULL DEFAULT 'Anonymous'
);
-- Create index "Blogs_Url" to table: "Blogs"
CREATE UNIQUE INDEX `Blogs_Url` ON `Blogs` (`Url`);
-- Create "Post" table
CREATE TABLE `Post` (
`PostId` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
`Title` text NOT NULL,
`Content` text NOT NULL,
`BlogUrl` varchar NULL,
CONSTRAINT `FK_Post_Blogs_BlogUrl` FOREIGN KEY (`BlogUrl`) REFERENCES `Blogs` (`Url`) ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create index "IX_Post_BlogUrl" to table: "Post"
CREATE INDEX `IX_Post_BlogUrl` ON `Post` (`BlogUrl`);
2 changes: 2 additions & 0 deletions src/Atlas.Provider.Demo/migrations/sqlite/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:FKhd6jUc7x8NeX2WnSlOWvU5WNPx+Kwk9lEN55FmWP4=
20240801062611.sql h1:Znct9We6Htoro7hiw4Ax77hxq+Uh9A1Cib8i1n6Lr3s=
24 changes: 24 additions & 0 deletions src/Atlas.Provider.Demo/migrations/sqlserver/20240801063009.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Create "Blogs" table
CREATE TABLE [Blogs] (
[BlogId] int IDENTITY (1, 1) NOT NULL,
[Url] varchar(200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Rating] decimal(5,2) NOT NULL,
[Title] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Content] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Author] nvarchar(200) COLLATE SQL_Latin1_General_CP1_CI_AS CONSTRAINT [DF__Blogs__Author__21D600EE] DEFAULT N'Anonymous' NOT NULL,
CONSTRAINT [PK_Blogs] PRIMARY KEY CLUSTERED ([BlogId] ASC)
);
-- Create index "AK_Blogs_Url" to table: "Blogs"
CREATE UNIQUE NONCLUSTERED INDEX [AK_Blogs_Url] ON [Blogs] ([Url] ASC);
-- Create "Post" table
CREATE TABLE [Post] (
[PostId] int IDENTITY (1, 1) NOT NULL,
[Title] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Content] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BlogUrl] varchar(200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_Post] PRIMARY KEY CLUSTERED ([PostId] ASC),

CONSTRAINT [FK_Post_Blogs_BlogUrl] FOREIGN KEY ([BlogUrl]) REFERENCES [Blogs] ([Url]) ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create index "IX_Post_BlogUrl" to table: "Post"
CREATE NONCLUSTERED INDEX [IX_Post_BlogUrl] ON [Post] ([BlogUrl] ASC);
2 changes: 2 additions & 0 deletions src/Atlas.Provider.Demo/migrations/sqlserver/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:zyMNceRFu+qrN01W99yPXWFCSWJQYv2LKfa3VV8TVoU=
20240801063009.sql h1:wB+DJtwaX6nTqMV0QjYuXZcjqP7GmgeAv7tzn/baYME=

0 comments on commit 93df070

Please sign in to comment.