Skip to content

Commit 0870a5d

Browse files
committed
fix(mysql): deprecate column width/zerofill
1 parent 34fedaf commit 0870a5d

File tree

13 files changed

+77
-33
lines changed

13 files changed

+77
-33
lines changed

docs/docs/entity/1-entities.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,6 @@ For example:
336336
@Column("varchar", { length: 200 })
337337
```
338338

339-
or
340-
341-
```typescript
342-
@Column({ type: "int", width: 200 })
343-
```
344-
345339
> Note about `bigint` type: `bigint` column type, used in SQL databases, doesn't fit into the regular `number` type and maps property to a `string` instead.
346340
347341
### Column types for `mysql` / `mariadb`
@@ -609,7 +603,6 @@ List of available options in `ColumnOptions`:
609603
You can change it by specifying your own name.
610604

611605
- `length: number` - Column type's length. For example if you want to create `varchar(150)` type you specify column type and length options.
612-
- `width: number` - column type's display width. Used only for [MySQL integer types](https://dev.mysql.com/doc/refman/5.7/en/integer-types.html)
613606
- `onUpdate: string` - `ON UPDATE` trigger. Used only in [MySQL](https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html).
614607
- `nullable: boolean` - Makes column `NULL` or `NOT NULL` in the database. By default column is `nullable: false`.
615608
- `update: boolean` - Indicates if column value is updated by "save" operation. If false, you'll be able to write this value only when you first time insert the object. Default value is `true`.
@@ -622,7 +615,6 @@ List of available options in `ColumnOptions`:
622615
- `precision: number` - The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum
623616
number of digits that are stored for the values. Used in some column types.
624617
- `scale: number` - The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number of digits to the right of the decimal point and must not be greater than precision. Used in some column types.
625-
- `zerofill: boolean` - Puts `ZEROFILL` attribute on to a numeric column. Used only in MySQL. If `true`, MySQL automatically adds the `UNSIGNED` attribute to this column.
626618
- `unsigned: boolean` - Puts `UNSIGNED` attribute on to a numeric column. Used only in MySQL.
627619
- `charset: string` - Defines a column character set. Not supported by all database types.
628620
- `collation: string` - Defines a column collation.

docs/docs/getting-started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,13 +771,13 @@ If you run the app, you'll see a newly generated table, and it will contain a co
771771
+-------------+--------------+----------------------------+
772772
| photo_metadata |
773773
+-------------+--------------+----------------------------+
774-
| id | int(11) | PRIMARY KEY AUTO_INCREMENT |
775-
| height | int(11) | |
776-
| width | int(11) | |
774+
| id | int | PRIMARY KEY AUTO_INCREMENT |
775+
| height | int | |
776+
| width | int | |
777777
| comment | varchar(255) | |
778778
| compressed | boolean | |
779779
| orientation | varchar(255) | |
780-
| photoId | int(11) | FOREIGN KEY |
780+
| photoId | int | FOREIGN KEY |
781781
+-------------+--------------+----------------------------+
782782
```
783783

docs/docs/help/3-decorator-reference.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class User {
134134
You can change it by specifying your own name.
135135
- `length: string|number` - Column type's length. For example, if you want to create `varchar(150)` type
136136
you specify column type and length options.
137-
- `width: number` - column type's display width. Used only for [MySQL integer types](https://dev.mysql.com/doc/refman/5.7/en/integer-types.html)
137+
- `width: number` - column type's display width. Used only for [MySQL integer types](https://dev.mysql.com/doc/refman/5.7/en/integer-types.html). _Deprecated_ in newer MySQL versions, will be removed from TypeORM in an upcoming version.
138138
- `onUpdate: string` - `ON UPDATE` trigger. Used only in [MySQL](https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html).
139139
- `nullable: boolean` - determines whether the column can become `NULL` or always has to be `NOT NULL`. By default column is `nullable: false`.
140140
- `update: boolean` - Indicates if column value is updated by "save" operation. If false, you'll be able to write this value only when you first time insert the object.
@@ -150,8 +150,7 @@ export class User {
150150
- `scale: number` - The scale for a decimal (exact numeric) column (applies only for decimal column),
151151
which represents the number of digits to the right of the decimal point and must not be greater than precision.
152152
Used in some column types.
153-
- `zerofill: boolean` - Puts `ZEROFILL` attribute on to a numeric column. Used only in MySQL.
154-
If `true`, MySQL automatically adds the `UNSIGNED` attribute to this column.
153+
- `zerofill: boolean` - Puts `ZEROFILL` attribute on to a numeric column. Used only in MySQL. If `true`, MySQL automatically adds the `UNSIGNED` attribute to this column. _Deprecated_ in newer MySQL versions, will be removed from TypeORM in an upcoming version. Use a character column and the `LPAD` function as suggested by MySQL.
155154
- `unsigned: boolean` - Puts `UNSIGNED` attribute on to a numeric column. Used only in MySQL.
156155
- `charset: string` - Defines a column character set. Not supported by all database types.
157156
- `collation: string` - Defines a column collation.

src/decorator/columns/Column.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
SpatialColumnType,
66
WithLengthColumnType,
77
WithPrecisionColumnType,
8-
WithWidthColumnType,
8+
WithSignColumnType,
99
} from "../../driver/types/ColumnTypes"
1010
import { ColumnMetadataArgs } from "../../metadata-args/ColumnMetadataArgs"
1111
import { ColumnCommonOptions } from "../options/ColumnCommonOptions"
@@ -17,7 +17,7 @@ import { ColumnEmbeddedOptions } from "../options/ColumnEmbeddedOptions"
1717
import { EmbeddedMetadataArgs } from "../../metadata-args/EmbeddedMetadataArgs"
1818
import { ColumnTypeUndefinedError } from "../../error/ColumnTypeUndefinedError"
1919
import { ColumnHstoreOptions } from "../options/ColumnHstoreOptions"
20-
import { ColumnWithWidthOptions } from "../options/ColumnWithWidthOptions"
20+
import { ColumnWithSignOptions } from "../options/ColumnWithSignOptions"
2121
import { GeneratedMetadataArgs } from "../../metadata-args/GeneratedMetadataArgs"
2222
import { ColumnOptions } from "../options/ColumnOptions"
2323

@@ -65,8 +65,8 @@ export function Column(
6565
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
6666
*/
6767
export function Column(
68-
type: WithWidthColumnType,
69-
options?: ColumnCommonOptions & ColumnWithWidthOptions,
68+
type: WithSignColumnType,
69+
options?: ColumnCommonOptions & ColumnWithSignOptions,
7070
): PropertyDecorator
7171

7272
/**

src/decorator/options/ColumnNumericOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ export interface ColumnNumericOptions {
1717
/**
1818
* Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
1919
* If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column
20+
* @deprecated No longer supported in newer MySQL versions, will be removed
21+
* from TypeORM in an upcoming version. Use a character column and the
22+
* `LPAD` function as suggested by MySQL
2023
*/
2124
zerofill?: boolean
2225

2326
/**
2427
* Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
28+
* @deprecated MySQL only supports unsigned integers in newer versions.
2529
*/
2630
unsigned?: boolean
2731
}

src/decorator/options/ColumnOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export interface ColumnOptions extends ColumnCommonOptions {
2525
/**
2626
* Column type's display width. Used only on some column types in MySQL.
2727
* For example, INT(4) specifies an INT with a display width of four digits.
28+
* @deprecated No longer supported in newer MySQL versions, will be removed
29+
* from TypeORM in an upcoming version. Use a character column and the
30+
* `LPAD` function as suggested by MySQL
2831
*/
2932
width?: number
3033

@@ -105,6 +108,9 @@ export interface ColumnOptions extends ColumnCommonOptions {
105108
/**
106109
* Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
107110
* If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to this column
111+
* @deprecated No longer supported in newer MySQL versions, will be removed
112+
* from TypeORM in an upcoming version. Use a character column and the
113+
* `LPAD` function as suggested by MySQL
108114
*/
109115
zerofill?: boolean
110116

src/decorator/options/ColumnWithWidthOptions.ts renamed to src/decorator/options/ColumnWithSignOptions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
/**
22
* Options for columns that can define a length of the column type.
33
*/
4-
export interface ColumnWithWidthOptions {
4+
export interface ColumnWithSignOptions {
55
/**
66
* Column type's display width. Used only on some column types in MySQL.
77
* For example, INT(4) specifies an INT with a display width of four digits.
8+
* @deprecated No longer supported in newer MySQL versions, will be removed
9+
* from TypeORM in an upcoming version. Use a character column and the
10+
* `LPAD` function as suggested by MySQL
811
*/
912
width?: number
1013

1114
/**
1215
* Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
1316
* If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to this column
17+
* @deprecated No longer supported in newer MySQL versions, will be removed
18+
* from TypeORM in an upcoming version. Use a character column and the
19+
* `LPAD` function as suggested by MySQL
1420
*/
1521
zerofill?: boolean
1622

src/decorator/options/PrimaryGeneratedColumnNumericOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export interface PrimaryGeneratedColumnNumericOptions {
2222
/**
2323
* Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
2424
* If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column
25+
* @deprecated No longer supported in newer MySQL versions, will be removed
26+
* from TypeORM in an upcoming version. Use a character column and the
27+
* `LPAD` function as suggested by MySQL
2528
*/
2629
zerofill?: boolean
2730

src/driver/mysql/MysqlQueryRunner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,6 +3389,7 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
33893389

33903390
/**
33913391
* Checks if column display width is by default.
3392+
* @deprecated MySQL no longer supports column width in newer versions.
33923393
*/
33933394
protected isDefaultColumnWidth(
33943395
table: Table,

src/driver/spanner/SpannerDriver.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@ export class SpannerDriver implements Driver {
112112
*/
113113
withLengthColumnTypes: ColumnType[] = ["string", "bytes"]
114114

115-
/**
116-
* Gets list of column data types that support length by a driver.
117-
*/
118-
withWidthColumnTypes: ColumnType[] = []
119-
120115
/**
121116
* Gets list of column data types that support precision by a driver.
122117
*/

0 commit comments

Comments
 (0)