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

Database check constraints are not updated when Java enums are #4446

Open
2 tasks done
nscuro opened this issue Dec 8, 2024 · 0 comments
Open
2 tasks done

Database check constraints are not updated when Java enums are #4446

nscuro opened this issue Dec 8, 2024 · 0 comments
Labels
defect Something isn't working p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/M Medium effort
Milestone

Comments

@nscuro
Copy link
Member

nscuro commented Dec 8, 2024

Current Behavior

We make use of auto-generated CHECK constraints for enum values. For example, for Project#classifier:

@Persistent
@Column(name = "CLASSIFIER", jdbcType = "VARCHAR")
@Index(name = "PROJECT_CLASSIFIER_IDX")
@Extension(vendorName = "datanucleus", key = "enum-check-constraint", value = "true")
private Classifier classifier;

Unfortunately, the CHECK constraint is only generated when the schema is initially created, but then never updated again as new values are added to the respective enum. As reported via Slack:

[...] we've noticed a discrepancy in the database constraint COMPONENT_CLASSIFIER_check across the instances (all of them using PostgreSQL). In particular, one instance includes DEVICE_DRIVER as an allowed value, while another instance does not. While it's possible to manually adjust this, shouldn't this be handled automatically by the database migrations?

The correct way to update a constraint is to drop and re-create it. DataNucleus does not do this, so it has to be a manual change performed by us.

Unfortunately, DataNucleus does not provide a means to specify a name for the generated CHECK constraint, which makes addressing it tricky. While in PostgreSQL the generated name is still predictable (see quote above), it is not for MSSQL:

Image

In such cases, we need to discover the correct constraint somehow.

Steps to Reproduce

N/A

Expected Behavior

Identity existing constraints affected by this issue. Drop and re-create them as part of a dedicated migration.

Dependency-Track Version

4.13.0-SNAPSHOT

Dependency-Track Distribution

Container Image, Executable WAR

Database Server

N/A

Database Server Version

No response

Browser

N/A

Checklist

@nscuro nscuro added defect Something isn't working p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/M Medium effort labels Dec 8, 2024
@nscuro nscuro added this to the 4.12.3 milestone Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something isn't working p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/M Medium effort
Projects
None yet
Development

No branches or pull requests

1 participant