[FEATURE] Support switching between non-coercible types via drop/add
Describe the bug
Incompatible cast does not result in DROP COLUMN followed by ADD COLUMN.
This is occurring for me with all hazards allowed and plan validation disabled.
Error: executing migration statement. the database maybe be in a dirty state:
{ALTER TABLE "public"."activity" ALTER COLUMN "ts" SET DATA TYPE timestamp with
time zone using "ts"::timestamp with time zone 3s 3s
[ACQUIRES_ACCESS_EXCLUSIVE_LOCK: This will completely lock the table while the data
is being re-written. The duration of this conversion depends on if the type conversion
is trivial or not. A non-trivial conversion will require a table rewrite. A trivial
conversion is one where the binary values are coercible and the column contents are not
changing.]}:
ERROR: cannot cast type integer to timestamp with time zone (SQLSTATE 42846)
Expected behavior
DROP then ADD
To Reproduce
Change a column type from integer to timestamptz.
Context pg-schema-diff version: 5fe8259b82bd784644224a861cce575339a45a59 pg-schema-diff usage: CLI Postgres version: 14
This isn't so much a bug as it is a limitation. We have not accounted for incompatible types when doing data type migrations. Instead, you will need a schema that removes the column and a schema that adds the column with the new type. I can make this feature request.
Relates to #52 .
Ideally, we have some way that given to two types x and y, we know (1) if they are coercible and (2) the binary is coercible, i.e., does not require a full table scan.