Description
This is to make you aware of the issue. I don't have a full fix yet.
autoincrement fields map to serial (for int) and bigserial (for int64) pseudo-types.
serial and bigserial are kind of like macros that expand into integer and bigint.
https://www.postgresql.org/docs/9.1/datatype-numeric.html
"The data types serial and bigserial are not true types, but merely a notational convenience
for creating unique identifier columns (similar to the AUTO_INCREMENT property supported by some other databases)."
int64 autoincrement is generated as bigserial, which in postgres automatically translates to:
CREATE SEQUENCE tablename_colname_seq;
CREATE TABLE tablename (
colname bigint DEFAULT nextval('tablename_colname_seq')::regclass NOT NULL
);
ALTER SEQUENCE tablename_colname_seq OWNED BY tablename.colname;
This interferes with the diff code in multiple ways:
- Changes the type
- Adds NOT NULL
- Adds a DEFAULT
I'm not sure whether the diff code pays attention to the ALTER SEQUENCE yet.
https://github.com/uptrace/bun/blob/master/migrate/diff.go#L277
func (d detector) equalColumns(col1, col2 sqlschema.Column) bool {
return d.cmpType(col1, col2) &&
col1.GetDefaultValue() == col2.GetDefaultValue() &&
col1.GetIsNullable() == col2.GetIsNullable() &&
col1.GetIsAutoIncrement() == col2.GetIsAutoIncrement() &&
col1.GetIsIdentity() == col2.GetIsIdentity()
}
The comparison function passed for postgres doesn't tolerate the type change.