svdu

Snippets

CLI

Remove AUTO_INCREMENT altering with atlas schema diff

atlas schema diff --to "<TARGET_SCHEMA>" --from "<ORIGINAL_SCHEMA>" --format "{{ sql . \"  \"}}" | sed 's|AUTO_INCREMENT \+[0-9]\+,\?||g'

Java

Automatically set current UTC date time with Hibernate/JPA in Spring Boot

  1. Make sure the field is Instant type.

    @Entity
    @Table(name = "table")
    class T {
     @Column(name = "created_at", nullable = false)
     @CreationTimestamp
     private Instant createdAt;
    }
  2. Forcedly setup hibernate works in UTC time zone:

    #application.properties
    spring.jpa.properties.hibernate.jdbc.timezone=UTC
  3. Set JDBC connection with UTC time zone:

    spring.datasource.url=jdbc:mysql://localhost:3306/db?connectionTimeZone=UTC