Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary length constraints from VARCHAR(N) columns #1077

Open
nscuro opened this issue Feb 14, 2024 · 1 comment · Fixed by DependencyTrack/hyades-apiserver#579
Assignees
Labels
component/api-server p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/M Medium effort technical debt

Comments

@nscuro
Copy link
Member

nscuro commented Feb 14, 2024

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 nscuro added technical debt p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/S Small effort component/api-server labels Feb 14, 2024
@sahibamittal sahibamittal self-assigned this Feb 14, 2024
@sahibamittal sahibamittal added size/M Medium effort and removed size/S Small effort labels Feb 16, 2024
@nscuro
Copy link
Member Author

nscuro commented Feb 28, 2024

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

@nscuro nscuro reopened this Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/api-server p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/M Medium effort technical debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants