upgradeType assumes its input was just unmarshaled from bytes that may have been serialized by any previous version of CRDB. It upgrades the object according to the requirements of the latest version by remapping fields and setting required values. This is necessary to preserve backwards- compatibil
()
| 1578 | // setting required values. This is necessary to preserve backwards- |
| 1579 | // compatibility with older formats (e.g. restoring database from old backup). |
| 1580 | func (t *T) upgradeType() error { |
| 1581 | switch t.Family() { |
| 1582 | case IntFamily: |
| 1583 | // Check VisibleType field that was populated in previous versions. |
| 1584 | switch t.InternalType.VisibleType { |
| 1585 | case visibleSMALLINT: |
| 1586 | t.InternalType.Width = 16 |
| 1587 | t.InternalType.Oid = oid.T_int2 |
| 1588 | case visibleINTEGER: |
| 1589 | t.InternalType.Width = 32 |
| 1590 | t.InternalType.Oid = oid.T_int4 |
| 1591 | case visibleBIGINT: |
| 1592 | t.InternalType.Width = 64 |
| 1593 | t.InternalType.Oid = oid.T_int8 |
| 1594 | case visibleBIT, visibleNONE: |
| 1595 | // Pre-2.1 BIT was using IntFamily with arbitrary widths. Clamp them |
| 1596 | // to fixed/known widths. See #34161. |
| 1597 | switch t.Width() { |
| 1598 | case 16: |
| 1599 | t.InternalType.Oid = oid.T_int2 |
| 1600 | case 32: |
| 1601 | t.InternalType.Oid = oid.T_int4 |
| 1602 | default: |
| 1603 | // Assume INT8 if width is 0 or not valid. |
| 1604 | t.InternalType.Oid = oid.T_int8 |
| 1605 | t.InternalType.Width = 64 |
| 1606 | } |
| 1607 | default: |
| 1608 | return errors.AssertionFailedf("unexpected visible type: %d", t.InternalType.VisibleType) |
| 1609 | } |
| 1610 | |
| 1611 | case FloatFamily: |
| 1612 | // Map visible REAL type to 32-bit width. |
| 1613 | switch t.InternalType.VisibleType { |
| 1614 | case visibleREAL: |
| 1615 | t.InternalType.Oid = oid.T_float4 |
| 1616 | t.InternalType.Width = 32 |
| 1617 | case visibleDOUBLE: |
| 1618 | t.InternalType.Oid = oid.T_float8 |
| 1619 | t.InternalType.Width = 64 |
| 1620 | case visibleNONE: |
| 1621 | switch t.Width() { |
| 1622 | case 32: |
| 1623 | t.InternalType.Oid = oid.T_float4 |
| 1624 | case 64: |
| 1625 | t.InternalType.Oid = oid.T_float8 |
| 1626 | default: |
| 1627 | // Pre-2.1 (before Width) there were 3 cases: |
| 1628 | // - VisibleType = DOUBLE PRECISION, Width = 0 -> now clearly FLOAT8 |
| 1629 | // - VisibleType = NONE, Width = 0 -> now clearly FLOAT8 |
| 1630 | // - VisibleType = NONE, Precision > 0 -> we need to derive the width. |
| 1631 | if t.Precision() >= 1 && t.Precision() <= 24 { |
| 1632 | t.InternalType.Oid = oid.T_float4 |
| 1633 | t.InternalType.Width = 32 |
| 1634 | } else { |
| 1635 | t.InternalType.Oid = oid.T_float8 |
| 1636 | t.InternalType.Width = 64 |
| 1637 | } |
no test coverage detected