-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
TRUNK-6276: Fix ValidateHibernateMappingsDatabaseIT test errors when running with MySQL #4806
base: master
Are you sure you want to change the base?
Conversation
5542fbf
to
f0493e6
Compare
@@ -38,7 +39,8 @@ public abstract class BaseOpenmrsMetadata extends BaseOpenmrsObject implements O | |||
@Field | |||
private String name; | |||
|
|||
@Column(name = "description", length = 255) | |||
@Column(name = "description", columnDefinition = "text") | |||
@Lob |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think a description of length 255 is a Lob.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some tables use text
for the description
field, while others use varchar
. Defining description
as text
in the superclass and overriding it as varchar
in the child classes when necessary helps mitigate compatibility issues between H2 and MySQL during tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the majority of the descriptions are small, it does not make sense to me making it a LOB in the base class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't include lob here we'll get an error when running ValidHibernateMappings with H2.
Schema-validation: wrong column type encountered in column [description] in table [order_type]; found [clob (Types#CLOB)], but expecting [text (Types#VARCHAR)]
if we set this to "varchar" and try to override to "text" when necessary we still get the error as we can't add @Lob
for overrides.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this again, which object would need text that is too big to require a LOB, for just a mere description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tables like global_property, order_type, and form use text
for description
.
Should we update the tables that use text
for description to something like varchar(1024)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do so. I cannot think of a reason why any of those would require a LOB. Let us change them.
825ffc0
to
e133bab
Compare
@@ -38,7 +39,7 @@ public abstract class BaseOpenmrsMetadata extends BaseOpenmrsObject implements O | |||
@Field | |||
private String name; | |||
|
|||
@Column(name = "description", length = 255) | |||
@Column(name = "description", length = 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we leave the default as 255?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the PR.
e133bab
to
9a8ee4c
Compare
@@ -38,7 +39,7 @@ public abstract class BaseOpenmrsMetadata extends BaseOpenmrsObject implements O | |||
@Field | |||
private String name; | |||
|
|||
@Column(name = "description", length = 255) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the default length be 255?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default length of varchar is set to 255 by JPA, so there's no need to explicitly define it
@@ -32,7 +33,8 @@ | |||
@Table(name = "patient_identifier_type") | |||
@Audited | |||
@AttributeOverrides({ | |||
@AttributeOverride(name = "name", column = @Column(name = "name", nullable = false, length = 50)) | |||
@AttributeOverride(name = "name", column = @Column(name = "name", nullable = false, length = 50)), | |||
@AttributeOverride(name = "description", column = @Column(name = "description", columnDefinition = "text")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should a patient identifier type description have a column definition of text?
@@ -31,6 +33,9 @@ | |||
@Entity | |||
@Table(name = "person_attribute_type") | |||
@Audited | |||
@AttributeOverrides({ | |||
@AttributeOverride(name = "description", column = @Column(name = "description", columnDefinition = "text")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above
9a8ee4c
to
1624f24
Compare
@dkayiwa I updated the PR |
@AttributeOverride(name = "attributes", column = @Column(name = "location_id")) | ||
@AttributeOverrides(value = { | ||
@AttributeOverride(name = "attributes", column = @Column(name = "location_id")), | ||
@AttributeOverride(name = "description", column = @Column(name = "description", columnDefinition = "varchar(255)", length = 255)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to duplicate the above length?
1624f24
to
d686dc5
Compare
@@ -32,7 +32,7 @@ | |||
@Table(name = "patient_identifier_type") | |||
@Audited | |||
@AttributeOverrides({ | |||
@AttributeOverride(name = "name", column = @Column(name = "name", nullable = false, length = 50)) | |||
@AttributeOverride(name = "name", column = @Column(name = "name", nullable = false, length = 50)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this extra comma needed?
@@ -28,6 +31,9 @@ | |||
@Entity | |||
@Table(name = "serialized_object") | |||
@Audited | |||
@AttributeOverrides(value = { | |||
@AttributeOverride(name = "description", column = @Column(name = "description", length = 5000)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also be text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, why should a description be that large?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create table serialized_object
(
serialized_object_id int auto_increment
primary key,
name varchar(255) not null,
description varchar(5000) null,
type varchar(255) not null,
subtype varchar(255) not null,
serialization_class varchar(255) not null,
serialized_data mediumtext not null,
date_created datetime not null,
creator int not null,
date_changed datetime null,
changed_by int null,
retired tinyint(1) default 0 not null,
date_retired datetime null,
retired_by int null,
retire_reason varchar(1000) null,
uuid char(38) not null,
constraint uuid
unique (uuid),
constraint serialized_object_changed_by
foreign key (changed_by) references users (user_id),
constraint serialized_object_creator
foreign key (creator) references users (user_id),
constraint serialized_object_retired_by
foreign key (retired_by) references users (user_id)
);
DDL for this table looks like this. What do you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like that was a typo 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be text
or varchar
?
…running with MySQL
d686dc5
to
31090f0
Compare
@@ -46,7 +46,9 @@ | |||
|
|||
<property name="voidReason" type="java.lang.String" column="void_reason" length="255" /> | |||
|
|||
<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" /> | |||
<property name="uuid" type="java.lang.String" unique="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the changes on uuids, were they failing on any of the databases?
Description of what I changed
Issue I worked on
see https://openmrs.atlassian.net/browse/TRUNK-6276
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amend
I have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amend
I ran
mvn clean package
right before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master