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

TRUNK-6276: Fix ValidateHibernateMappingsDatabaseIT test errors when running with MySQL #4806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wikumChamith
Copy link
Member

@wikumChamith wikumChamith commented Oct 27, 2024

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 and
    added 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

@wikumChamith wikumChamith force-pushed the TRUNK-6276 branch 2 times, most recently from 5542fbf to f0493e6 Compare October 29, 2024 06:27
@@ -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
Copy link
Member

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.

Copy link
Member Author

@wikumChamith wikumChamith Oct 29, 2024

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

Copy link
Member

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.

Copy link
Member Author

@wikumChamith wikumChamith Oct 29, 2024

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.

Copy link
Member

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?

Copy link
Member Author

@wikumChamith wikumChamith Oct 29, 2024

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)?

Copy link
Member

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.

@wikumChamith wikumChamith force-pushed the TRUNK-6276 branch 2 times, most recently from 825ffc0 to e133bab Compare October 29, 2024 12:24
@@ -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)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the PR.

@@ -38,7 +39,7 @@ public abstract class BaseOpenmrsMetadata extends BaseOpenmrsObject implements O
@Field
private String name;

@Column(name = "description", length = 255)
Copy link
Member

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?

Copy link
Member Author

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"))
Copy link
Member

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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above

@wikumChamith
Copy link
Member Author

@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))
Copy link
Member

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?

@@ -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)),
Copy link
Member

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))
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

@wikumChamith wikumChamith Oct 29, 2024

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?

Copy link
Member

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 😊

Copy link
Member Author

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 ?

@@ -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">
Copy link
Member

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?

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.

2 participants