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: support for quoted identifiers in concurrent index creation #1852

Merged
merged 1 commit into from
Jul 12, 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
7 changes: 6 additions & 1 deletion cmd/atlas/internal/sqlparse/pgparse/pgparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package pgparse

import (
"fmt"
"strconv"

"ariga.io/atlas/cmd/atlas/internal/sqlparse/parseutil"
"ariga.io/atlas/sql/migrate"
Expand Down Expand Up @@ -104,7 +105,11 @@ func (p *Parser) FixChange(_ migrate.Driver, s string, changes schema.Changes) (
if err != nil {
return nil, err
}
i := schema.Changes(modify.Changes).IndexAddIndex(stmt.Name.String())
name := stmt.Name.String()
if uname, err := strconv.Unquote(name); err == nil {
name = uname
}
i := schema.Changes(modify.Changes).IndexAddIndex(name)
if i == -1 {
return nil, fmt.Errorf("AddIndex %q command not found", stmt.Name)
}
Expand Down
17 changes: 17 additions & 0 deletions cmd/atlas/internal/sqlparse/pgparse/pgparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ func TestFixChange_CreateIndexCon(t *testing.T) {
},
changes,
)
// Support quoted identifiers.
changes, err = p.FixChange(
nil,
`CREATE INDEX CONCURRENTLY "i1" ON t1 (c1)`,
schema.Changes{
&schema.ModifyTable{
T: schema.NewTable("t1"),
Changes: schema.Changes{
&schema.AddIndex{I: schema.NewIndex("i1")},
},
},
},
)
require.NoError(t, err)
m, ok := changes[0].(*schema.ModifyTable)
require.True(t, ok)
require.Equal(t, &postgres.Concurrently{}, m.Changes[0].(*schema.AddIndex).Extra[0])
}

func TestFixChange_RenameTable(t *testing.T) {
Expand Down
Loading