-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schema/inspect: support inspect for non-database resource (#1586)
- Loading branch information
Showing
8 changed files
with
213 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
only mysql8 | ||
|
||
# inspect without dev-db will failed | ||
! atlas schema inspect -u file://a.sql | ||
stderr 'Error: --dev-url cannot be empty' | ||
|
||
# inspect file to HCL | ||
atlas schema inspect -u file://a.sql --dev-url URL > inspected.hcl | ||
cmp inspected.hcl script_cli_inspect.hcl | ||
|
||
# inspect file to SQL | ||
atlas schema inspect -u file://a.sql --dev-url URL --format '{{ sql . }}' > inspected.sql | ||
cmp inspected.sql script_cli_inspect.sql | ||
|
||
-- a.sql -- | ||
create table users ( | ||
id int NOT NULL, | ||
PRIMARY KEY (id) | ||
) | ||
|
||
-- script_cli_inspect.hcl -- | ||
table "users" { | ||
schema = schema.script_cli_inspect_file | ||
column "id" { | ||
null = false | ||
type = int | ||
} | ||
primary_key { | ||
columns = [column.id] | ||
} | ||
} | ||
schema "script_cli_inspect_file" { | ||
charset = "utf8mb4" | ||
collate = "utf8mb4_0900_ai_ci" | ||
} | ||
-- script_cli_inspect.sql -- | ||
-- Create "users" table | ||
CREATE TABLE `users` (`id` int NOT NULL, PRIMARY KEY (`id`)) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; |
34 changes: 34 additions & 0 deletions
34
internal/integration/testdata/postgres/cli-inspect-file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# inspect without dev-db will failed | ||
! atlas schema inspect -u file://a.sql | ||
stderr 'Error: --dev-url cannot be empty' | ||
|
||
# inspect file to HCL | ||
atlas schema inspect -u file://a.sql --dev-url URL > inspected.hcl | ||
cmp inspected.hcl script_cli_inspect.hcl | ||
|
||
# inspect file to SQL | ||
atlas schema inspect -u file://a.sql --dev-url URL --format '{{ sql . }}' > inspected.sql | ||
cmp inspected.sql script_cli_inspect.sql | ||
|
||
-- a.sql -- | ||
create table users ( | ||
id int NOT NULL, | ||
PRIMARY KEY (id) | ||
) | ||
|
||
-- script_cli_inspect.hcl -- | ||
table "users" { | ||
schema = schema.script_cli_inspect_file | ||
column "id" { | ||
null = false | ||
type = integer | ||
} | ||
primary_key { | ||
columns = [column.id] | ||
} | ||
} | ||
schema "script_cli_inspect_file" { | ||
} | ||
-- script_cli_inspect.sql -- | ||
-- Create "users" table | ||
CREATE TABLE "users" ("id" integer NOT NULL, PRIMARY KEY ("id")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
apply 1.hcl | ||
|
||
# test url flag | ||
atlas schema inspect -u URL > inspected.hcl | ||
cmp inspected.hcl script_cli_inspect.hcl | ||
|
||
# test exclude flag on table. | ||
atlas schema inspect -u URL --exclude "users" > inspected.hcl | ||
cmp inspected.hcl notable.hcl | ||
|
||
# test exclude flag on column. | ||
atlas schema inspect -u URL --exclude "*.[ab]*" > inspected.hcl | ||
cmp inspected.hcl id.hcl | ||
|
||
# test exclude flag on column. | ||
atlas schema inspect -u URL --exclude "*.*" > inspected.hcl | ||
cmp inspected.hcl nocolumn.hcl | ||
|
||
|
||
-- 1.hcl -- | ||
table "users" { | ||
schema = schema.$db | ||
column "id" { | ||
null = false | ||
type = int | ||
} | ||
column "a" { | ||
null = false | ||
type = int | ||
} | ||
column "b" { | ||
null = false | ||
type = int | ||
} | ||
column "ab" { | ||
null = false | ||
type = int | ||
} | ||
column "ac" { | ||
null = false | ||
type = int4 | ||
} | ||
} | ||
schema "$db" { | ||
} | ||
|
||
-- script_cli_inspect.hcl -- | ||
table "users" { | ||
schema = schema.script_cli_inspect | ||
column "id" { | ||
null = false | ||
type = integer | ||
} | ||
column "a" { | ||
null = false | ||
type = integer | ||
} | ||
column "b" { | ||
null = false | ||
type = integer | ||
} | ||
column "ab" { | ||
null = false | ||
type = integer | ||
} | ||
column "ac" { | ||
null = false | ||
type = integer | ||
} | ||
} | ||
schema "script_cli_inspect" { | ||
} | ||
-- empty.hcl -- | ||
-- notable.hcl -- | ||
schema "script_cli_inspect" { | ||
} | ||
-- id.hcl -- | ||
table "users" { | ||
schema = schema.script_cli_inspect | ||
column "id" { | ||
null = false | ||
type = integer | ||
} | ||
} | ||
schema "script_cli_inspect" { | ||
} | ||
-- nocolumn.hcl -- | ||
table "users" { | ||
schema = schema.script_cli_inspect | ||
} | ||
schema "script_cli_inspect" { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.