From 77d13f9eba11a989b98a6f62af1e8eec3d6ff49a Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Thu, 25 Jan 2024 00:47:47 +0700 Subject: [PATCH 1/2] chore: added sqlserver test --- .github/workflows/ci.yaml | 2 +- testdata/atlas-script.hcl | 1 + testdata/atlas-standalone.hcl | 1 + testdata/js/atlas-script.hcl | 1 + testdata/js/atlas-standalone.hcl | 1 + .../js/migrations/mssql/20240125041939.sql | 26 ++++++++++++++++ testdata/js/migrations/mssql/atlas.sum | 2 ++ testdata/ts/atlas-script.hcl | 1 + testdata/ts/atlas-standalone.hcl | 4 ++- testdata/ts/entities/mssql/Blog.ts | 14 +++++++++ testdata/ts/entities/mssql/User.ts | 31 +++++++++++++++++++ testdata/ts/load-entities.ts | 8 ++++- .../ts/migrations/mssql/20240125045258.sql | 22 +++++++++++++ testdata/ts/migrations/mssql/atlas.sum | 2 ++ 14 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 testdata/js/migrations/mssql/20240125041939.sql create mode 100644 testdata/js/migrations/mssql/atlas.sum create mode 100644 testdata/ts/entities/mssql/Blog.ts create mode 100644 testdata/ts/entities/mssql/User.ts create mode 100644 testdata/ts/migrations/mssql/20240125045258.sql create mode 100644 testdata/ts/migrations/mssql/atlas.sum diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0e19948..153bbfc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,7 +37,7 @@ jobs: integration-tests: strategy: matrix: - dialect: [ mysql, postgres, sqlite ] + dialect: [ mysql, postgres, sqlite, mssql ] language: [ ts, js ] runs-on: ubuntu-latest steps: diff --git a/testdata/atlas-script.hcl b/testdata/atlas-script.hcl index 644ec3b..c040709 100644 --- a/testdata/atlas-script.hcl +++ b/testdata/atlas-script.hcl @@ -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] } diff --git a/testdata/atlas-standalone.hcl b/testdata/atlas-standalone.hcl index 147b8db..16d0439 100644 --- a/testdata/atlas-standalone.hcl +++ b/testdata/atlas-standalone.hcl @@ -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] } diff --git a/testdata/js/atlas-script.hcl b/testdata/js/atlas-script.hcl index 5bcc281..7eb6fc6 100644 --- a/testdata/js/atlas-script.hcl +++ b/testdata/js/atlas-script.hcl @@ -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] } diff --git a/testdata/js/atlas-standalone.hcl b/testdata/js/atlas-standalone.hcl index 3a221fd..a3e0cc5 100644 --- a/testdata/js/atlas-standalone.hcl +++ b/testdata/js/atlas-standalone.hcl @@ -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] } diff --git a/testdata/js/migrations/mssql/20240125041939.sql b/testdata/js/migrations/mssql/20240125041939.sql new file mode 100644 index 0000000..9363f25 --- /dev/null +++ b/testdata/js/migrations/mssql/20240125041939.sql @@ -0,0 +1,26 @@ +-- Create "post" table +CREATE TABLE [post] ( + [id] int IDENTITY (1, 1) NOT NULL, + [title] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [text] text NOT NULL, + CONSTRAINT [PK_post] PRIMARY KEY CLUSTERED ([id] ASC) +); +-- Create "category" table +CREATE TABLE [category] ( + [id] int IDENTITY (1, 1) NOT NULL, + [name] varchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + CONSTRAINT [PK_category] PRIMARY KEY CLUSTERED ([id] ASC) +); +-- Create "post_categories_category" table +CREATE TABLE [post_categories_category] ( + [postId] int NOT NULL, + [categoryId] int NOT NULL, + CONSTRAINT [PK_post_categories_category] PRIMARY KEY CLUSTERED ([categoryId] ASC), + + CONSTRAINT [FK_93b566d522b73cb8bc46f7405bd] FOREIGN KEY ([postId]) REFERENCES [post] ([id]) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT [FK_a5e63f80ca58e7296d5864bd2d3] FOREIGN KEY ([categoryId]) REFERENCES [category] ([id]) ON UPDATE CASCADE ON DELETE CASCADE +); +-- Create index "IDX_93b566d522b73cb8bc46f7405b" to table: "post_categories_category" +CREATE NONCLUSTERED INDEX [IDX_93b566d522b73cb8bc46f7405b] ON [post_categories_category] ([postId] ASC); +-- Create index "IDX_a5e63f80ca58e7296d5864bd2d" to table: "post_categories_category" +CREATE NONCLUSTERED INDEX [IDX_a5e63f80ca58e7296d5864bd2d] ON [post_categories_category] ([categoryId] ASC); diff --git a/testdata/js/migrations/mssql/atlas.sum b/testdata/js/migrations/mssql/atlas.sum new file mode 100644 index 0000000..62a8d2a --- /dev/null +++ b/testdata/js/migrations/mssql/atlas.sum @@ -0,0 +1,2 @@ +h1:Cok5H0mFL8wy3aOhd5fa1DJyrJpGTRSARCt+ciizliQ= +20240125041939.sql h1:qY0tAPL1r5wyprDyjWSCGuM/N7HQJQa2SkukT74eOKc= diff --git a/testdata/ts/atlas-script.hcl b/testdata/ts/atlas-script.hcl index eb4c86e..c3c57b6 100644 --- a/testdata/ts/atlas-script.hcl +++ b/testdata/ts/atlas-script.hcl @@ -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] } diff --git a/testdata/ts/atlas-standalone.hcl b/testdata/ts/atlas-standalone.hcl index 13b35d2..c2c56e2 100644 --- a/testdata/ts/atlas-standalone.hcl +++ b/testdata/ts/atlas-standalone.hcl @@ -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] } @@ -15,7 +16,8 @@ data "external_schema" "typeorm" { "npx", "../..", "load", - "--path", var.dialect == "sqlite" ? "./entities/sqlite" : "./entities", + "--path", var.dialect == "sqlite" ? "./entities/sqlite" : + var.dialect == "mssql" ? "./entities/mssql": "./entities", "--dialect", var.dialect, ] } diff --git a/testdata/ts/entities/mssql/Blog.ts b/testdata/ts/entities/mssql/Blog.ts new file mode 100644 index 0000000..0d5bf5c --- /dev/null +++ b/testdata/ts/entities/mssql/Blog.ts @@ -0,0 +1,14 @@ +import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { User } from "./User"; + +@Entity() +export class Blog { + @PrimaryGeneratedColumn() + id: number; + + @Column() + title: string; + + @ManyToOne(() => User, (user) => user.blogs) + user: User; +} diff --git a/testdata/ts/entities/mssql/User.ts b/testdata/ts/entities/mssql/User.ts new file mode 100644 index 0000000..4c3e08e --- /dev/null +++ b/testdata/ts/entities/mssql/User.ts @@ -0,0 +1,31 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + OneToMany, + Check, + Index, + Unique, +} from "typeorm"; +import { Blog } from "./Blog"; + +@Entity() +@Unique(["firstName", "lastName"]) +@Check(`"age" > 6`) +export class User { + @PrimaryGeneratedColumn() + id: number; + + @Column() + firstName: string; + + @Column() + lastName: string; + + @Column() + @Index("IDX_USER_AGE") + age: number; + + @OneToMany(() => Blog, (blog) => blog.user) + blogs: Blog[]; +} diff --git a/testdata/ts/load-entities.ts b/testdata/ts/load-entities.ts index 9e9d90f..d711665 100644 --- a/testdata/ts/load-entities.ts +++ b/testdata/ts/load-entities.ts @@ -5,13 +5,19 @@ import { User } from "./entities/User"; import { Blog } from "./entities/Blog"; import { User as SqliteUser } from "./entities/sqlite/User"; import { Blog as SqliteBlog } from "./entities/sqlite/Blog"; +import { User as MssqlUser } from "./entities/mssql/User"; +import { Blog as MssqlBlog } from "./entities/mssql/Blog"; // parse the second argument as the dialect const dialect = process.argv[2] as Dialect; // sqlite does not support enum, so we need to load different entities if (dialect === "sqlite") { - loadEntities("sqlite", [SqliteUser, SqliteBlog]).then((sql) => { + loadEntities(dialect, [SqliteUser, SqliteBlog]).then((sql) => { + console.log(sql); + }); +} else if (dialect === "mssql") { + loadEntities(dialect, [MssqlUser, MssqlBlog]).then((sql) => { console.log(sql); }); } else { diff --git a/testdata/ts/migrations/mssql/20240125045258.sql b/testdata/ts/migrations/mssql/20240125045258.sql new file mode 100644 index 0000000..cb6881a --- /dev/null +++ b/testdata/ts/migrations/mssql/20240125045258.sql @@ -0,0 +1,22 @@ +-- Create "user" table +CREATE TABLE [user] ( + [id] int IDENTITY (1, 1) NOT NULL, + [firstName] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [lastName] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [age] int NOT NULL, + CONSTRAINT [PK_user] PRIMARY KEY CLUSTERED ([id] ASC), + CONSTRAINT [CHK_70c8a9c9c39b98f399c28b8700] CHECK ([age]>(6)) +); +-- Create index "UQ_c322cd2084cd4b1b2813a900320" to table: "user" +CREATE UNIQUE NONCLUSTERED INDEX [UQ_c322cd2084cd4b1b2813a900320] ON [user] ([firstName] ASC, [lastName] ASC); +-- Create index "IDX_USER_AGE" to table: "user" +CREATE NONCLUSTERED INDEX [IDX_USER_AGE] ON [user] ([age] ASC); +-- Create "blog" table +CREATE TABLE [blog] ( + [id] int IDENTITY (1, 1) NOT NULL, + [title] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [userId] int NULL, + CONSTRAINT [PK_blog] PRIMARY KEY CLUSTERED ([id] ASC), + + CONSTRAINT [FK_fc46ede0f7ab797b7ffacb5c08d] FOREIGN KEY ([userId]) REFERENCES [user] ([id]) ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/testdata/ts/migrations/mssql/atlas.sum b/testdata/ts/migrations/mssql/atlas.sum new file mode 100644 index 0000000..01693e0 --- /dev/null +++ b/testdata/ts/migrations/mssql/atlas.sum @@ -0,0 +1,2 @@ +h1:RttYKFvIO0I5AcfQfxpOdvqSdy1C5vLag5z1urqW2dA= +20240125045258.sql h1:6SYUcn7Agxms48l28WZOCdg45oHlRrCjNWzFozlVKTI= From 3ca494e3e5193487cec88ad3f36bb84bbd03d247 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Thu, 25 Jan 2024 00:57:08 +0700 Subject: [PATCH 2/2] chore: fixed login-require with token --- .github/workflows/ci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 153bbfc..de66eaa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -58,6 +58,8 @@ jobs: working-directory: ./testdata/${{ matrix.language }} run: | atlas migrate diff --env typeorm -c "file://atlas-standalone.hcl" --var dialect=${{ matrix.dialect }} + env: + ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }} - name: Verify migrations generated run: | status=$(git status --porcelain) @@ -71,6 +73,8 @@ jobs: working-directory: ./testdata/${{ matrix.language }} run: | atlas migrate diff --env typeorm -c "file://atlas-script.hcl" --var dialect=${{ matrix.dialect }} + env: + ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }} - name: Verify migrations generated run: | status=$(git status --porcelain)