Skip to content
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
14 changes: 2 additions & 12 deletions server/ast/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,9 @@ func nodeAlterTableCmds(
}
vitessDdlCmds = append(vitessDdlCmds, statement)

// Postgres (unlike MySQL) allows an inline FK constraint
// when altering a table to add a column. GMS doesn't support
// this directly in the ALTER TABLE ADD COLUMN DDL command,
// so we break this out into a separate DDL command.
// If inline constraints have been specified, set the ConstraintAction so that they get processed
if len(statement.TableSpec.Constraints) > 0 {
vitessDdlCmds = append(vitessDdlCmds,
&vitess.DDL{
Action: "alter",
ConstraintAction: "add",
Table: tableName,
IfExists: ifExists,
TableSpec: statement.TableSpec,
})
statement.ConstraintAction = vitess.AddStr
}

case *tree.AlterTableDropColumn:
Expand Down
16 changes: 16 additions & 0 deletions testing/go/alter_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ func TestAlterTable(t *testing.T) {
},
},
},
{
Name: "Add column with inline check constraint",
SetUpScript: []string{
"CREATE TABLE test1 (a INT, b INT);",
},
Assertions: []ScriptTestAssertion{
{
Query: "ALTER TABLE test1 ADD COLUMN c INT NOT NULL DEFAULT 42 CONSTRAINT chk1 CHECK (c > 0);",
Expected: []sql.Row{},
},
{
Query: "INSERT INTO test1 VALUES (2, 2, -2);",
ExpectedErr: `Check constraint "chk1" violated`,
},
},
},
{
Name: "Drop Column",
SetUpScript: []string{
Expand Down