Enforce limit on text columns
Coming from https://gitlab.com/gitlab-org/gitlab-ce/issues/64505, we want to enforce a limit on the length of text data. For string
types, this can be done with varchar(N)
. For the Postgres text
type, this can be done with a table CHECK
constraint.
The benefit to using text
with a CHECK
constraint is, that it's straight-forward to change the limit later - without rewriting the whole table. With varchar(N)
, changing N
leads to a rewrite of the table which may be unacceptable.
The proposal here is to:
- Implement
CHECK
constraints for limiting the size oftext
columns - Enforce placing a limit on
text
columns with rubocop - Disallow using
varchar(N)
, i.e.string
columns in favor of usingtext
always.
From a Postgres perspective, there's only little difference between varchar
and text
(except the possibility to limit the size of a varchar). Both are varlena
types internally and use the same code. There's a good background read comparing textual datatypes.