Skip to content

Commit

Permalink
fix: drop index
Browse files Browse the repository at this point in the history
  • Loading branch information
thall committed Jul 2, 2021
1 parent c4a9a4f commit 153819e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spanddl/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (d *Database) applyDropIndex(stmt *spansql.DropIndex) (err error) {
}
}()
i := d.indexOfIndex(stmt.Name)
if i != -1 {
if i == -1 {
return fmt.Errorf("index %s does not exist", stmt.Name)
}
d.Indexes = append(d.Indexes[:i], d.Indexes[i+1:]...)
Expand Down
35 changes: 35 additions & 0 deletions spanddl/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,41 @@ func TestDatabase_ApplyDDL(t *testing.T) {
},
},
},
{
name: "drop index",
ddls: []string{
`CREATE TABLE Singers (
SingerId INT64 NOT NULL,
FirstName STRING(1024),
LastName STRING(1024),
SingerInfo BYTES(MAX),
BirthDate DATE,
) PRIMARY KEY(SingerId);`,

`CREATE INDEX SingersByFirstLastName ON Singers(FirstName, LastName)`,

`DROP INDEX SingersByFirstLastName`,
},
expected: &Database{
Tables: []*Table{
{
Name: "Singers",
Columns: []*Column{
{Name: "SingerId", Type: spansql.Type{Base: spansql.Int64}, NotNull: true},
{Name: "FirstName", Type: spansql.Type{Base: spansql.String, Len: 1024}},
{Name: "LastName", Type: spansql.Type{Base: spansql.String, Len: 1024}},
{Name: "SingerInfo", Type: spansql.Type{Base: spansql.Bytes, Len: spansql.MaxLen}},
{Name: "BirthDate", Type: spansql.Type{Base: spansql.Date}},
},
PrimaryKey: []spansql.KeyPart{
{Column: "SingerId"},
},
},
},

Indexes: []*Index{},
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 153819e

Please sign in to comment.