hyades icon indicating copy to clipboard operation
hyades copied to clipboard

Remove unnecessary length constraints from `VARCHAR(N)` columns

Open nscuro opened this issue 1 year ago • 1 comments

For historical reasons, the database schema still has lots of VARCHAR(N) columns, where the length is artificially restricted.

It makes sense for values where the maximum length is known (e.g. hashes), but for most columns it doesn't. The constraints in question can cause issues when importing BOMs that contain fields with values longer than what DT can store in its database. Truncating values prior to storage is not a good option.

By focusing on PostgreSQL only, we are no longer limited by the RDBMSes capability to deal with and / or index TEXT columns of arbitrary length. Postgres treats VARCHAR(N) and TEXT the same behind the scenes, whereas other RDBMSes treat them differently.

Create a database migration that converts VARCHAR(N) columns to TEXT to lift the artificial length constraints. Keep the constraints for columns where the maximum value length is known, e.g. SHA256.

[!NOTE] In order to make the schema changes effective, corresponding @Size annotations must be removed from the Java classes as well. Otherwise the Java code will enforce constraints that no longer exist in the database.

nscuro avatar Feb 14 '24 15:02 nscuro

Re-opening because we had to temporarily roll back this change.

nscuro avatar Feb 28 '24 11:02 nscuro