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
CHECKconstraints for limiting the size oftextcolumns - Enforce placing a limit on
textcolumns with rubocop - Disallow using
varchar(N), i.e.stringcolumns in favor of usingtextalways.
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.