Repository navigation
fix: preserve typmods on timestamp, time, interval and bit columns (#699) - #723
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
[Medium impact] The change reaches PostgreSQL schema inspection and the plans generated from it. Fix fixed-length bit conversions before merging; the generated migration fails on populated columns. Findings
SummaryPreserves precision, interval fields, and bit lengths when inspecting columns.
Reviews (1) · Last reviewed commit: "fix: preserve typmods on timestamp, time..." · Reviewed by Greptile |
|
|
||
| ALTER TABLE user_pending_permissions ALTER COLUMN slot TYPE interval day to second(2) USING slot::interval day to second(2); | ||
|
|
||
| ALTER TABLE user_pending_permissions ALTER COLUMN flags TYPE bit(5); |
There was a problem hiding this comment.
Changing a populated bit(3) column to bit(5) produces this statement without USING. PostgreSQL does not pad existing bit strings during this implicit conversion, so three-bit values make the migration fail.
Update needsUsingClause to handle fixed-length bit changes and emit USING flags::bit(5). Add a test that applies the migration to existing rows.
Co-Authored-By: Tianzhou <t@bytebase.com>
Co-Authored-By: Tianzhou <t@bytebase.com>
Summary
Fixes #699.
resolved_typeinGetColumns/GetColumnsForSchemaused the bareudt_namefor everypg_catalogbase type, relying oncharacter_maximum_length/numeric_precisionfor modifiers. Date/time and bit-string typmods aren't exposed there, sotimestamp(3),timetz(1),interval hour to minute,bit(3),varbit(4), ... were dumped bare (a replayedbitisbit(1)) and plan saw no difference.When
atttypmod >= 0:Columns without a modifier (
atttypmod = -1) are unchanged. varchar/numeric/char keep their existing path. A typmod change now producesALTER COLUMN ... TYPE.needsUsingClauseadds an explicit cast when wideningbit(n): assignment coercion rejects bit strings of a different length, sobit(3)→bit(5)would fail on a populated table; the explicit cast zero-pads. Narrowing gets no cast (it would silently drop bits) and fails on data, like varchar narrowing.ir/queries/queries.sql.gowas updated by hand to mirrorqueries.sql(sqlc generate needs a live DB).Test: extended
create_table/alter_column_typeswith typmod changes on every affected type, an unchangedtimestamp(3)column (no diff), an addedtimestamp(0)column, and a populated row so thebitwidening is applied against data. Before the fix plan only emittedADD COLUMN added_at timestamp. Note theinterval→interval day to second(2)change gets a redundant but validUSINGclause.Link to Devin session: https://app.devin.ai/sessions/314326a464fb4b3c9fbe6ccc32736cdf
Open in Devin Desktop: https://app.devin.ai/desktop/session/314326a464fb4b3c9fbe6ccc32736cdf?variant=devin
Requested by: @tianzhou
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work