Skip to content

Commit

Permalink
cmd/atlas: support for quoted identifiers in concurrent index creation (
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Jul 12, 2023
1 parent ec77562 commit a2c67c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit a2c67c6

Please sign in to comment.