Skip to content

Conversation

@quaff
Copy link
Contributor

@quaff quaff commented Oct 31, 2024

[Please describe here what your change is about]


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-18784

@quaff
Copy link
Contributor Author

quaff commented Oct 31, 2024

@gavinking WDYT?

@gavinking
Copy link
Member

@gavinking WDYT?

I'm not sure I agree with the concept.

We don't recommend running TableMigrator on your production database, so it's a tool mainly for use in more development-oriented contexts.

In that context I would say it would be annoying if adding @Column(length=20) to my entity would not result in any change.

But, well, this merits further discussion.

@quaff
Copy link
Contributor Author

quaff commented Oct 31, 2024

@gavinking WDYT?

I'm not sure I agree with the concept.

We don't recommend running TableMigrator on your production database, so it's a tool mainly for use in more development-oriented contexts.

In that context I would say it would be annoying if adding @Column(length=20) to my entity would not result in any change.

But, well, this merits further discussion.

It's annoying development too, It's kind of regression because I can do that in early version.

@gavinking
Copy link
Member

I don't see how it can be annoying in development. Why would you want to develop against a schema that disagrees with what you have explicitly specified in your mapping annotations?

If there is disagreement there, I would want to know about it!

@quaff
Copy link
Contributor Author

quaff commented Oct 31, 2024

I don't see how it can be annoying in development. Why would you want to develop against a schema that disagrees with what you have explicitly specified in your mapping annotations?

If there is disagreement there, I would want to know about it!

I didn’t specify @column explicitly, the length defaults to 255

@quaff
Copy link
Contributor Author

quaff commented Oct 31, 2024

Perhaps we should check the required length is default length

@gavinking
Copy link
Member

Perhaps we should check the required length is default length

Yeah, I was wondering that too.

Actually, @sebersole, I believe we now have ways to distinguish an unset/defaulted length from an explicitly-set length=255, is that right?

@quaff quaff changed the title HHH-18784 TableMigrator shouldn't alter column length if actual is greater than required HHH-18784 TableMigrator shouldn't alter column length if actual is greater than default Nov 1, 2024
@quaff quaff changed the title HHH-18784 TableMigrator shouldn't alter column length if actual is greater than default HHH-18784 TableMigrator shouldn't alter column length if length is not explicitly-set Nov 1, 2024
@quaff
Copy link
Contributor Author

quaff commented Nov 1, 2024

Perhaps we should check the required length is default length

Yeah, I was wondering that too.

Actually, @sebersole, I believe we now have ways to distinguish an unset/defaulted length from an explicitly-set length=255, is that right?

@gavinking Please review the updated PR, column will not be modified if @Column is not explicitly-set, but there is no way to distinguish between @Column and @Column(length=255).

@gavinking
Copy link
Member

there is no way to distinguish between @column and @column(length=255).

I believe that Steve now has a way to do that in hibernate-models.

@quaff
Copy link
Contributor Author

quaff commented Nov 1, 2024

there is no way to distinguish between @column and @column(length=255).

I believe that Steve now has a way to do that in hibernate-models.

I inspected org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation, I don't think hibernate-models can handle this currently, It should retain a map of explicit attributes.


@Before
public void setUp() throws IOException {
output = File.createTempFile( "update_script", ".sql" );

Check warning

Code scanning / CodeQL

Local information disclosure in a temporary directory Medium test

Local information disclosure vulnerability due to use of file readable by other local users.
@sebersole
Copy link
Member

sebersole commented Nov 1, 2024

I believe that Steve now has a way to do that in hibernate-models.

No, I initially did, when using Jandex (which does understand this distinction). But everyone else disagreed with that so I rempoved it.

@gavinking
Copy link
Member

Well, OK, then, given that we can't distinguish an explicit length=255, I guess I'm just -1 on making this change.

@sebersole
Copy link
Member

It should retain a map of explicit attributes.

The problem is the same. We don't know which values are explicit (again, unless using Jandex). Java makes default and eplicit values indistinguishable.

@sebersole
Copy link
Member

Rejecting this one

@sebersole sebersole closed this Nov 1, 2024
@quaff
Copy link
Contributor Author

quaff commented Nov 4, 2024

Rejecting this one

I think this PR is worthy to merge, It distinguish @Column present or not at least.

@gavinking
Copy link
Member

@quaff We never treat a missing annotation as different to a missing annotation member for the JPA mapping annotations.

@quaff
Copy link
Contributor Author

quaff commented Nov 4, 2024

@quaff We never treat a missing annotation as different to a missing annotation member for the JPA mapping annotations.

I agree that, but I'm requesting special treat for schema migration here, the unit tests in this PR should pass.

@gavinking
Copy link
Member

And that's precisely the sort of ad hoc hacked-in special case which I'm thoroughly against. How am I supposed to explain to a user that "oh, it behaves one way with the @Column annotation but a different way without it", even though the actual inferred schema is identical. That's terrible. There's no way the user would expect that behavior.

Again, schema migration is a limited tool with very limited capabilities, which is supposed to assist at development time. It's not a replacement for something like Flyway or whatever, and we've never promoted it as such.

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

Successfully merging this pull request may close these issues.

3 participants