Testing migration with rename column that has constraint
Weird things seem to happen when you rename a table column that has a constraint on it. I need to test to find out exactly what is happening, but it looks like the changes to the column are fine, but the updates to the constaint are not being detected. This means that when the schema is generated after the migration file is created, it has the wrong constraint details on the column.
An example, a table participant
was created with a column owner
:
{
"name": "participant",
"cols": [
{
"name": "id",
"ordinal_position": 1,
"default": null,
"not_null": true,
"data_type": "serial",
"length": null
},
{
"name": "apircode",
"ordinal_position": 2,
"default": null,
"not_null": true,
"data_type": "varchar",
"length": 10
},
{
"name": "owner",
"ordinal_position": 3,
"default": null,
"not_null": true,
"data_type": "integer",
"length": null
}
]
}
Later, the owner
column was renamed to client_account_id
and the constraint changed from referencing the user
table to reference the client_account
table:
"alter": {
"owner": {
"name": "client_account_id",
"ordinal_position": 3,
"default": null,
"not_null": true,
"data_type": "integer",
"length": null
}
}
In this case, the changes to the constraint were not detected and added to the migration file. The constraint actually should have been removed and a new one created in it's place.