Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added sqlserver test #11

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions 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 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
1 change: 1 addition & 0 deletions testdata/js/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 testdata/js/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
26 changes: 26 additions & 0 deletions testdata/js/migrations/mssql/20240125041939.sql
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions testdata/js/migrations/mssql/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:Cok5H0mFL8wy3aOhd5fa1DJyrJpGTRSARCt+ciizliQ=
20240125041939.sql h1:qY0tAPL1r5wyprDyjWSCGuM/N7HQJQa2SkukT74eOKc=
1 change: 1 addition & 0 deletions testdata/ts/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
4 changes: 3 additions & 1 deletion testdata/ts/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 All @@ -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,
]
}
Expand Down
14 changes: 14 additions & 0 deletions testdata/ts/entities/mssql/Blog.ts
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 31 additions & 0 deletions testdata/ts/entities/mssql/User.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
8 changes: 7 additions & 1 deletion testdata/ts/load-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions testdata/ts/migrations/mssql/20240125045258.sql
Original file line number Diff line number Diff line change
@@ -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
);
2 changes: 2 additions & 0 deletions testdata/ts/migrations/mssql/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:RttYKFvIO0I5AcfQfxpOdvqSdy1C5vLag5z1urqW2dA=
20240125045258.sql h1:6SYUcn7Agxms48l28WZOCdg45oHlRrCjNWzFozlVKTI=
Loading