Skip to content

Commit

Permalink
Fix ALTER TABLE ADD COLUMN nullability
Browse files Browse the repository at this point in the history
Columns added by `ALTER TABLE ADD COLUMN` are nullable by default.
For the `pgroll` `Column` type, these means we need to set `Nullable` to
`true` by default.
  • Loading branch information
andrew-farries committed Dec 19, 2024
1 parent e1ba0af commit 9a04cd5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/sql2pgroll/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,9 @@ func convertAlterTableAddColumn(stmt *pgq.AlterTableStmt, cmd *pgq.AlterTableCmd

operation := &migrations.OpAddColumn{
Column: migrations.Column{
Name: columnDef.GetColname(),
Type: columnType,
Name: columnDef.GetColname(),
Type: columnType,
Nullable: true,
},
Table: getQualifiedRelationName(stmt.GetRelation()),
Up: PlaceHolderSQL,
Expand All @@ -430,8 +431,11 @@ func convertAlterTableAddColumn(stmt *pgq.AlterTableStmt, cmd *pgq.AlterTableCmd
switch constraint.GetConstraint().GetContype() {
case pgq.ConstrType_CONSTR_NULL:
operation.Column.Nullable = true
case pgq.ConstrType_CONSTR_NOTNULL:
operation.Column.Nullable = false
case pgq.ConstrType_CONSTR_PRIMARY:
operation.Column.Pk = true
operation.Column.Nullable = false
case pgq.ConstrType_CONSTR_UNIQUE:
operation.Column.Unique = true
case pgq.ConstrType_CONSTR_CHECK:
Expand Down

0 comments on commit 9a04cd5

Please sign in to comment.