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

cmd/atlas/internal/cmdlog: indent new line in apply log #2288

Merged
merged 1 commit into from
Nov 17, 2023
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
8 changes: 7 additions & 1 deletion cmd/atlas/internal/cmdlog/cmdlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ var (
"upper": strings.ToUpper,
"json": jsonEncode,
"json_merge": jsonMerge,
"indent_ln": indentLn,
})

// MigrateApplyTemplate holds the default template of the 'migrate apply' command.
Expand All @@ -303,7 +304,7 @@ No migration files to execute
Migrating to version {{ cyan .Target }}{{ with .Current }} from {{ cyan . }}{{ end }} ({{ len .Pending }} migrations in total):
{{ range $i, $f := .Applied }}
{{ yellow "--" }} migrating version {{ cyan $f.File.Version }}{{ range $f.Applied }}
{{ cyan "->" }} {{ . }}{{ end }}
{{ cyan "->" }} {{ indent_ln . 7 }}{{ end }}
{{- with .Error }}
{{ redBgWhiteFg .Text }}
{{- else }}
Expand Down Expand Up @@ -905,3 +906,8 @@ func jsonMerge(objects ...string) (string, error) {
func dec(i int) int {
return i - 1
}

func indentLn(input string, indent int) string {
pad := strings.Repeat(" ", indent)
return strings.ReplaceAll(input, "\n", "\n"+pad)
}
21 changes: 18 additions & 3 deletions internal/integration/testdata/sqlite/cli-migrate-apply.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ atlas migrate hash
atlas migrate apply --url URL
stdout 'Migrating to version 2 \(2 migrations in total\):'
stdout '-- migrating version 1'
stdout '-> CREATE TABLE `users` \(`id` integer NOT NULL, `age` integer NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY \(`id`\)\);'
stdout '-> CREATE TABLE `users` \('
stdout ' `id` integer NOT NULL,'
stdout ' `age` integer NOT NULL,'
stdout ' `name` TEXT NOT NULL,'
stdout ' PRIMARY KEY \(`id`\)'
stdout '\);'
stdout '-- migrating version 2'
stdout '-> CREATE TABLE `pets` \(`id` integer NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY \(`id`\)\);'
stdout '-- 2 migrations'
Expand Down Expand Up @@ -117,7 +122,12 @@ atlas schema inspect --url URL --exclude atlas_schema_revisions --exclude users
cmp stdout broken.hcl

-- migrations/1_first.sql --
CREATE TABLE `users` (`id` integer NOT NULL, `age` integer NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY (`id`));
CREATE TABLE `users` (
`id` integer NOT NULL,
`age` integer NOT NULL,
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
);

-- migrations/2_second.sql --
CREATE TABLE `pets` (`id` integer NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY (`id`));
Expand All @@ -140,7 +150,12 @@ table "broken" {
schema "main" {
}
-- users.sql --
CREATE TABLE `users` (`id` integer NOT NULL, `age` integer NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY (`id`))
CREATE TABLE `users` (
`id` integer NOT NULL,
`age` integer NOT NULL,
`name` TEXT NOT NULL,
PRIMARY KEY (`id`)
)

-- pets.sql --
CREATE TABLE `pets` (`id` integer NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY (`id`))
Loading