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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 77 additions & 56 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,84 @@ name: Build with Maven

# trigger build on branches that *should* support both Java 8 and Java 11
on:
push:
branches:
- master
- 2.4.x
- 2.5.x
- 2.6.x
pull_request:
branches:
- master
- 2.4.x
- 2.5.x
- 2.6.x
workflow_dispatch:
push:
branches:
- master
- 2.4.x
- 2.5.x
- 2.6.x
pull_request:
branches:
- master
- 2.4.x
- 2.5.x
- 2.6.x
workflow_dispatch:

permissions: read-all

jobs:
build:
strategy:
matrix:
platform:
- ubuntu-latest
java-version:
- 8
- 11
- 17
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
cache: 'maven'
- name: Install dependencies
run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode --show-version --file pom.xml
- name: Build with Maven
run: mvn clean install --batch-mode && mvn test -Pskip-default-test -Pintegration-test --batch-mode --file pom.xml
# this is necessary to populate the environment variables for Coveralls properly
- name: Set branch name and PR number
id: refs
if: ${{ matrix.java-version == '8' }}
continue-on-error: true
env:
BRANCH_NAME_OR_REF: ${{ github.head_ref || github.ref }}
run: |
echo "::set-output name=branch_name::${BRANCH_NAME_OR_REF#refs/heads/}"
echo "::set-output name=pr_number::$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")"
- name: Update coverage data
# only send coverage data for Java 8
if: ${{ matrix.java-version == '8' && steps.refs.outcome == 'success' }}
continue-on-error: true
env:
CI_NAME: Github
CI_BUILD_NUMBER: ${{ github.run_id }}
CI_BUILD_URL: https://github.com/${{ github.repository }}/commit/${{ github.event.after }}/checks
CI_BRANCH: ${{ steps.refs.outputs.branch_name }}
CI_PULL_REQUEST: ${{ steps.refs.outputs.pr_number }}
run: mvn jacoco:report coveralls:report --batch-mode --file pom.xml --no-transfer-progress -DrepoToken=${{ secrets.COVERALLS_TOKEN }}
build:
strategy:
matrix:
platform:
- ubuntu-latest
java-version:
- 8
- 11
- 17
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
cache: 'maven'
- name: Install dependencies
run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode --show-version --file pom.xml
- name: Build with Maven
run: mvn clean install --batch-mode && mvn test -Pskip-default-test -Pintegration-test --batch-mode --file pom.xml
# this is necessary to populate the environment variables for Coveralls properly
- name: Set branch name and PR number
id: refs
if: ${{ matrix.java-version == '8' }}
continue-on-error: true
env:
BRANCH_NAME_OR_REF: ${{ github.head_ref || github.ref }}
run: |
echo "::set-output name=branch_name::${BRANCH_NAME_OR_REF#refs/heads/}"
echo "::set-output name=pr_number::$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")"
- name: Update coverage data
# only send coverage data for Java 8
if: ${{ matrix.java-version == '8' && steps.refs.outcome == 'success' }}
continue-on-error: true
env:
CI_NAME: Github
CI_BUILD_NUMBER: ${{ github.run_id }}
CI_BUILD_URL: https://github.com/${{ github.repository }}/commit/${{ github.event.after }}/checks
CI_BRANCH: ${{ steps.refs.outputs.branch_name }}
CI_PULL_REQUEST: ${{ steps.refs.outputs.pr_number }}
run: mvn jacoco:report coveralls:report --batch-mode --file pom.xml --no-transfer-progress -DrepoToken=${{ secrets.COVERALLS_TOKEN }}

build_with_mysql:
strategy:
matrix:
platform:
- ubuntu-latest
java-version:
- 8
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
cache: 'maven'
- name: Install dependencies
run: mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true --batch-mode --show-version --file pom.xml
- name: Build with Maven with external database
run: mvn clean install --batch-mode && mvn test -DuseInMemoryDatabase=false -Pskip-default-test -Pintegration-test --batch-mode --file pom.xml
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/BaseOpenmrsMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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

@Column(name = "description")
private String description;

@ManyToOne(optional = false)
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/BaseOpenmrsObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@Audited
public abstract class BaseOpenmrsObject implements Serializable, OpenmrsObject {

@Column(name = "uuid", unique = true, nullable = false, length = 38, updatable = false)
@Column(name = "uuid", unique = true, nullable = false, length = 38, updatable = false, columnDefinition = "char")
private String uuid = UUID.randomUUID().toString();

/**
Expand Down
5 changes: 4 additions & 1 deletion api/src/main/java/org/openmrs/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.openmrs.api.context.Context;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand Down Expand Up @@ -47,7 +48,9 @@
@Entity
@Table(name = "location")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@AttributeOverride(name = "attributes", column = @Column(name = "location_id"))
@AttributeOverrides(value = {
@AttributeOverride(name = "attributes", column = @Column(name = "location_id"))
})
@Audited
public class Location extends BaseCustomizableMetadata<LocationAttribute> implements java.io.Serializable, Attributable<Location>, Address {

Expand Down
4 changes: 3 additions & 1 deletion api/src/main/java/org/openmrs/MedicationDispense.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Date;
Expand Down Expand Up @@ -191,7 +192,8 @@ public class MedicationDispense extends BaseFormRecordableOpenmrsData {
* FHIR:DosageInstructions.patientInstructions
* Relates to drugOrder.dosingInstructions
*/
@Column(name = "dosing_instructions", length=65535)
@Column(name = "dosing_instructions", columnDefinition = "text")
@Lob
private String dosingInstructions;

/**
Expand Down
3 changes: 0 additions & 3 deletions api/src/main/java/org/openmrs/OrderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -30,7 +28,6 @@
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/org/openmrs/ProgramAttributeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.openmrs.attribute.AttributeType;
import org.openmrs.attribute.BaseAttributeType;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -26,6 +28,9 @@
@Entity
@Table(name = "program_attribute_type")
@Audited
@AttributeOverrides(value = {
@AttributeOverride(name = "description", column = @Column(name = "description", length = 1024))
})
public class ProgramAttributeType extends BaseAttributeType<PatientProgram> implements AttributeType<PatientProgram> {

@Id
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/ProviderAttributeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@Table(name = "provider_attribute_type")
@Audited
@AttributeOverrides(value = {
@AttributeOverride(name = "description", column = @Column(name = "description", length = 1024))
@AttributeOverride(name = "description", column = @Column(name = "description", length = 1024 ))
})
public class ProviderAttributeType extends BaseAttributeType<Provider> implements AttributeType<Provider> {

Expand Down
9 changes: 8 additions & 1 deletion api/src/main/java/org/openmrs/api/db/SerializedObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
import org.openmrs.BaseChangeableOpenmrsMetadata;
import org.openmrs.serialization.OpenmrsSerializer;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

/**
Expand All @@ -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 ?

})
public class SerializedObject extends BaseChangeableOpenmrsMetadata {

@Id
Expand All @@ -49,7 +55,8 @@ public class SerializedObject extends BaseChangeableOpenmrsMetadata {
@Column(name = "serialization_class", nullable = false, length = 255)
private Class<? extends OpenmrsSerializer> serializationClass;

@Column(name = "serialized_data", length = 16777215)
@Column(name = "serialized_data", columnDefinition = "mediumtext")
@Lob
private String serializedData;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public abstract class BaseAttributeType<OwningType extends Customizable<?>> exte
@Column(name = "datatype", length = 255)
private String datatypeClassname;

@Column(name = "datatype_config", length = 65535 )
@Column(name = "datatype_config", columnDefinition = "text")
@Lob
private String datatypeConfig;

@Column(name = "preferred_handler", length = 255)
private String preferredHandlerClassname;

@Column(name = "handler_config", length = 65535 )
@Column(name = "handler_config", columnDefinition = "text")
@Lob
private String handlerConfig;

Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/org/openmrs/hl7/HL7QueueItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public abstract class HL7QueueItem extends BaseOpenmrsObject {
@JoinColumn(name = "hl7_source")
private HL7Source hl7Source;

@Column(name = "hl7_source_key", length = 1024)
@Column(name = "hl7_source_key", columnDefinition = "text")
@Lob
private String hl7SourceKey;

@Column(name = "hl7_data", nullable = false, columnDefinition = "text")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<many-to-one name="allergy" class="Allergy" column="allergy_id" not-null="true"/>
<many-to-one name="reaction" column="reaction_concept_id" class="org.openmrs.Concept" not-null="true"/>
<property name="reactionNonCoded" type="java.lang.String" column="reaction_non_coded"/>
<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" not-null="true"/>
<property name="uuid" type="java.lang.String" unique="true" not-null="true">
<column name="uuid" sql-type="char(38)" />
</property>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
column="date_created" not-null="true" length="19" />
<many-to-one name="creator" class="org.openmrs.User"
not-null="true" />
<property name="uuid" type="java.lang.String"
column="uuid" length="38" unique="true" />
<property name="uuid" type="java.lang.String" unique="true">
<column name="uuid" sql-type="char(38)" />
</property>
<many-to-one name="retiredBy" class="org.openmrs.User"
column="retired_by" />
<property name="dateRetired" type="java.util.Date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<param name="sequence">clob_datatype_storage_id_seq</param>
</generator>
</id>

<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" />
<property name="uuid" type="java.lang.String" unique="true">
<column name="uuid" sql-type="char(38)" />
</property>
<property name="value" type="materialized_clob" column="value" />

</class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
not-null="true" length="255" />
<property name="description" type="java.lang.String"
not-null="true" length="1000" />

<property name="uuid" type="java.lang.String"
column="uuid" length="38" unique="true" />

<property name="uuid" type="java.lang.String" unique="true">
<column name="uuid" sql-type="char(38)" />
</property>

<set name="memberships" cascade="all-delete-orphan,evict" lazy="true" inverse="true">
<key column="cohort_id" not-null="true"/>
Expand All @@ -52,4 +53,4 @@
</class>

</hibernate-mapping>


Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
column="date_voided" length="19" />
<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">
<column name="uuid" sql-type="char(38)" />
</property>

<many-to-one name="creator" class="User" not-null="true" />
<many-to-one name="voidedBy" class="User" column="voided_by" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
</generator>
</id>

<property name="uuid" type="java.lang.String"
column="uuid" length="38" unique="true" />
<property name="uuid" type="java.lang.String" unique="true">
<column name="uuid" sql-type="char(38)" />
</property>

<property name="retired" type="java.lang.Boolean"
column="retired" length="1" not-null="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
name="answerDrug" class="org.openmrs.Drug" column="answer_drug" />

<property name="dateCreated" type="java.util.Date" column="date_created" not-null="true" />
<many-to-one name="creator" class="User" column="creator" not-null="true"/>

<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" />
<many-to-one name="creator" class="User" column="creator" not-null="true"/>

<property name="uuid" type="java.lang.String" unique="true">
<column name="uuid" sql-type="char(38)" />
</property>
<property name="sortWeight" type="java.lang.Double" column="sort_weight"/>
</class>

Expand Down
Loading
Loading