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

Omission of precision and scale Attributes in Schema Generation #4001

Open
Serhiiilnytskyi opened this issue Dec 27, 2024 · 0 comments
Open

Comments

@Serhiiilnytskyi
Copy link

Serhiiilnytskyi commented Dec 27, 2024

Flyway Version: 10.19.0
Client: Command-line, Java API, Maven plugin
Database: postgres(any version)

Problem Statement:

  • When defining a BigDecimal field in a JPA entity with the @column annotation, specifying precision and scale along with a columnDefinition results in Flyway-generated schemas that omit the precision and scale attributes.

Steps to Reproduce:

  • Define a JPA entity with a BigDecimal field annotated as follows:
@Column(CoreConstraints.PRECISION, scale = CoreConstraints.SCALE, columnDefinition = "DEFAULT 0.00", nullable = false)
  • Use Flyway to generate the database schema.
  • Observe that the resulting database column lacks the specified precision, scale and column type.

Expected Behavior:

  • The generated database schema should include the specified precision and scale for the amount column, ensuring accurate data representation.

Actual Behavior:

  • The generated schema defines the amount column without the specified precision and scale, potentially leading to data integrity issues.

Additional Context:

  • Attempts to manually alter the database schema to include the correct precision and scale are reverted by Flyway in subsequent migrations.
  • This behavior persists across different environments and database systems.
  • It’s possible to avoid this behavior by defining everything in the columnDefinition explicitly, as follows:
  @Column(columnDefinition = "DECIMAL(16,2) DEFAULT 0.00", nullable = false)

However, this approach has significant drawbacks:
- It reduces code readability, making it harder for developers to understand the constraints quickly.
- It decreases consistency with other project codebases where precision and scale are specified separately for clarity and maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant