Skip to content

Commit

Permalink
Add missing precision to DATETIME columns
Browse files Browse the repository at this point in the history
Hibernate 4 uses that information to truncate fractional seconds
accordingly. We want to preserve the milliseconds of the java.util.Date
object, so 3 is adequate.
  • Loading branch information
arteymix committed Dec 3, 2022
1 parent 5658b1e commit 2bce979
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 12 deletions.
16 changes: 15 additions & 1 deletion gemma-core/src/main/resources/sql/migrations/db.1.29.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ alter table GENE_SET modify column AUDIT_TRAIL_FK BIGINT not null;
alter table EXTERNAL_DATABASE
add column EXTERNAL_DATABASE_FK BIGINT after DATABASE_SUPPLIER_FK;
alter table EXTERNAL_DATABASE
add constraint EXTERNAL_DATABASE_FKC foreign key (EXTERNAL_DATABASE_FK) references EXTERNAL_DATABASE (ID);
add constraint EXTERNAL_DATABASE_FKC foreign key (EXTERNAL_DATABASE_FK) references EXTERNAL_DATABASE (ID);

-- add precision to our datetime to match that of java.util.Date
alter table PHENOTYPE_ASSOCIATION modify column LAST_UPDATED DATETIME(3);
alter table AUDIT_EVENT modify column DATE DATETIME(3);
alter table CONTACT modify column SIGNUP_TOKEN_DATESTAMP DATETIME(3);
alter table JOB_INFO
modify column START_TIME DATETIME(3),
modify column END_TIME DATETIME(3);
alter table CURATION_DETAILS modify column LAST_UPDATED DATETIME(3);
alter table EXTERNAL_DATABASE modify column LAST_UPDATED DATETIME(3);
alter table BIO_ASSAY modify column PROCESSING_DATE DATETIME(3);

-- initially stored as a DATETIME, but publication time is just not a thing
alter table BIBLIOGRAPHIC_REFERENCE modify column PUBLICATION_DATE DATE;
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<column name="STRENGTH" not-null="false" unique="false" sql-type="DOUBLE"/>
</property>
<property name="lastUpdated" type="java.util.Date">
<column name="LAST_UPDATED" not-null="true" unique="false" sql-type="DATETIME"/>
<column name="LAST_UPDATED" not-null="true" unique="false" sql-type="DATETIME(3)"/>
</property>
<many-to-one name="gene" class="ubic.gemma.model.genome.Gene" cascade="none" lazy="false" fetch="join">
<column name="GENE_FK" not-null="false" sql-type="BIGINT"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<generator class="native"/>
</id>
<property access="field" name="date" type="java.util.Date">
<column name="DATE" not-null="true" sql-type="DATETIME"/>
<column name="DATE" not-null="true" sql-type="DATETIME(3)"/>
</property>
<property access="field" name="action"
type="ubic.gemma.model.common.auditAndSecurity.AuditActionEnum">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<column name="SIGNUP_TOKEN" not-null="false" unique="false" sql-type="VARCHAR(255)"/>
</property>
<property name="signupTokenDatestamp" type="java.util.Date">
<column name="SIGNUP_TOKEN_DATESTAMP" not-null="false" unique="false" sql-type="DATETIME"/>
<column name="SIGNUP_TOKEN_DATESTAMP" not-null="false" unique="false" sql-type="DATETIME(3)"/>
</property>
<set name="jobs" lazy="true" fetch="select" inverse="true">
<cache usage="read-write"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<column name="FAILED_MESSAGE" not-null="false" unique="false" sql-type="text"/>
</property>
<property name="startTime" type="java.util.Date">
<column name="START_TIME" not-null="true" unique="false" sql-type="DATETIME"/>
<column name="START_TIME" not-null="true" unique="false" sql-type="DATETIME(3)"/>
</property>
<property name="endTime" type="java.util.Date">
<column name="END_TIME" not-null="false" unique="false" sql-type="DATETIME"/>
<column name="END_TIME" not-null="false" unique="false" sql-type="DATETIME(3)"/>
</property>
<property name="phases" type="java.lang.Integer">
<column name="PHASES" not-null="true" unique="false" sql-type="INTEGER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<column name="NOTE_AUDIT_EVENT_FK" not-null="false" sql-type="BIGINT" unique="true"/>
</many-to-one>
<property name="lastUpdated" type="java.util.Date">
<column name="LAST_UPDATED" not-null="false" unique="false" sql-type="DATETIME"/>
<column name="LAST_UPDATED" not-null="false" unique="false" sql-type="DATETIME(3)"/>
</property>
<property name="troubled" type="java.lang.Boolean">
<column name="TROUBLED" not-null="true" unique="false" sql-type="TINYINT"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<column name="CITATION" not-null="false" unique="false" sql-type="text"/>
</property>
<property name="publicationDate" type="java.util.Date">
<column name="PUBLICATION_DATE" not-null="false" unique="false" sql-type="DATETIME"/>
<column name="PUBLICATION_DATE" not-null="false" unique="false" sql-type="DATE"/>
</property>
<property name="annotatedAbstract" type="org.hibernate.type.MaterializedClobType">
<column name="ANNOTATED_ABSTRACT" not-null="false" unique="false" sql-type="text"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<property name="releaseUrl" type="java.net.URL">
<column name="RELEASE_URL" not-null="false" unique="false" sql-type="VARCHAR(255)"/>
</property>
<property name="lastUpdated" type="java.util.Date">
<column name="LAST_UPDATED" not-null="false" unique="false" sql-type="DATETIME"/>
<property name="lastUpdated" type="java.util.Date" precision="4">
<column name="LAST_UPDATED" not-null="false" unique="false" sql-type="DATETIME(3)"/>
</property>
<many-to-one name="databaseSupplier" class="ubic.gemma.model.common.auditAndSecurity.Contact" cascade="none"
lazy="proxy" fetch="select">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<column name="DESCRIPTION" not-null="false" unique="false" sql-type="text"/>
</property>
<property name="processingDate" type="java.util.Date">
<column name="PROCESSING_DATE" not-null="false" unique="false" sql-type="DATETIME"/>
<column name="PROCESSING_DATE" not-null="false" unique="false" sql-type="DATETIME(3)"/>
</property>
<property name="sequenceReadCount" type="java.lang.Integer">
<column name="SEQUENCE_READ_COUNT" not-null="false" unique="false" sql-type="INTEGER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void test() {
assertThat( ed ).isNotNull();
assertThat( ed.getLastUpdated() )
.isNotNull()
.isBetween( DateUtils.round( beforeUpdateDate, Calendar.SECOND ), DateUtils.round( new Date(), Calendar.SECOND ), true, true );
.isBetween( beforeUpdateDate, new Date(), true, true );

List<AuditEvent> auditEvents = ed.getAuditTrail().getEvents();
assertThat( auditEvents ).hasSizeGreaterThanOrEqualTo( 2 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public void testUpdateReleaseDetails() throws MalformedURLException {
tuple( AuditAction.UPDATE, currentUser ) ); // from AuditAdvice on update()
assertThat( externalDatabase.getAuditTrail().getEvents().get( 1 ).getNote() )
.isEqualTo( "Yep" );
// make sure that the last updated date is properly stored
Date lastUpdated = externalDatabase.getLastUpdated();
assertThat( lastUpdated ).isNotNull();
externalDatabase = externalDatabaseService.find( externalDatabase );
assertThat( externalDatabase ).isNotNull();
assertThat( externalDatabase.getLastUpdated() ).isNotNull();
assertThat( externalDatabase.getLastUpdated().getTime() )
.isEqualTo( lastUpdated.getTime() );
}

@Test
Expand Down

0 comments on commit 2bce979

Please sign in to comment.