Merge pull request #578 from pingcap/qiuyesuifeng/dev-schema-change
Add/Drop column exist check.
This commit is contained in:
14
ddl/ddl.go
14
ddl/ddl.go
@ -502,7 +502,13 @@ func (d *ddl) AddColumn(ctx context.Context, ti table.Ident, spec *AlterSpecific
|
||||
return errors.Trace(ErrNotExists)
|
||||
}
|
||||
|
||||
var col *column.Col
|
||||
// Check whether added column has existed.
|
||||
colName := spec.Column.Name
|
||||
col := column.FindCol(t.Cols(), colName)
|
||||
if col != nil {
|
||||
return errors.Errorf("column %s already exists", colName)
|
||||
}
|
||||
|
||||
// ingore table constraints now, maybe return error later
|
||||
// we use length(t.Cols()) as the default offset first, later we will change the
|
||||
// column's offset later.
|
||||
@ -536,6 +542,12 @@ func (d *ddl) DropColumn(ctx context.Context, ti table.Ident, colName model.CISt
|
||||
return errors.Trace(ErrNotExists)
|
||||
}
|
||||
|
||||
// Check whether dropped column has existed.
|
||||
col := column.FindCol(t.Cols(), colName.L)
|
||||
if col == nil {
|
||||
return errors.Errorf("column %s doesn’t exist", colName.L)
|
||||
}
|
||||
|
||||
job := &model.Job{
|
||||
SchemaID: schema.ID,
|
||||
TableID: t.Meta().ID,
|
||||
|
||||
@ -190,7 +190,7 @@ LOOP:
|
||||
delete(handles, h)
|
||||
}
|
||||
|
||||
c.Assert(len(handles), Equals, 0)
|
||||
c.Assert(handles, HasLen, 0)
|
||||
}
|
||||
|
||||
func (s *testDBSuite) testDropIndex(c *C) {
|
||||
@ -258,7 +258,7 @@ LOOP:
|
||||
handles[h] = struct{}{}
|
||||
}
|
||||
|
||||
c.Assert(len(handles), Equals, 0)
|
||||
c.Assert(handles, HasLen, 0)
|
||||
}
|
||||
|
||||
func (s *testDBSuite) showColumns(c *C, tableName string) [][]interface{} {
|
||||
|
||||
Reference in New Issue
Block a user