Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

3.1 KB
Raw Blame
## Timeline events get an entity_id so serialization and remote sync can key them on a stable, portable
## identifier instead of a per-instance row id. The shape mirrors 20260723_backfill_entity_ids: add the column
## nullable, backfill it, then add NOT NULL and UNIQUE. All three dialect variants of the backfill live in one
## changeset so every database executes (and records) it — a changeset whose only change is dbms-filtered away
## never reaches the changelog, which breaks consolidation.
##
## On MariaDB before 10.10, timeline_event.timestamp has an implicit ON UPDATE, so the backfill would reset every
## event's date. The changeset before the backfill drops it (as v48.00-010 did); the backfill keeps its checksum.

databaseChangeLog:
  - changeSet:
      id: v65.h1c4r5
      author: havenchyk
      comment: Add a portable entity ID to timeline events
      changes:
        - addColumn:
            tableName: timeline_event
            columns:
              - column:
                  name: entity_id
                  type: char(21)
                  remarks: NanoID used to identify the event across instances
                  constraints:
                    nullable: true
      rollback:
        - dropColumn:
            tableName: timeline_event
            columnName: entity_id

  - changeSet:
      id: v65.m2xncr
      author: havenchyk
      comment: Remove ON UPDATE from timeline_event.timestamp on mysql, mariadb
      preConditions:
        - onFail: MARK_RAN
        - dbms:
            type: mysql,mariadb
      changes:
        - sql:
            sql: ALTER TABLE `timeline_event` MODIFY `timestamp` timestamp(6) NOT NULL DEFAULT current_timestamp(6) COMMENT 'When the event happened';
      rollback: []

  - changeSet:
      id: v65.zvhbd7
      author: havenchyk
      comment: Backfill entity IDs for existing timeline events
      changes:
        - sql:
            dbms: postgresql
            sql: UPDATE timeline_event SET entity_id = substr(replace(gen_random_uuid()::text, '-', ''), 1, 21) WHERE entity_id IS NULL;
        - sql:
            dbms: mysql,mariadb
            sql: UPDATE timeline_event SET entity_id = substr(replace(uuid(), '-', ''), 1, 21) WHERE entity_id IS NULL;
        - sql:
            dbms: h2
            sql: UPDATE timeline_event SET entity_id = substr(replace(cast(random_uuid() as varchar), '-', ''), 1, 21) WHERE entity_id IS NULL;
      rollback: []

  - changeSet:
      id: v65.0npr54
      author: havenchyk
      comment: Require an entity ID on timeline events
      changes:
        - addNotNullConstraint:
            tableName: timeline_event
            columnName: entity_id
            columnDataType: char(21)

  - changeSet:
      id: v65.lpm4z3
      author: havenchyk
      comment: entity_id is unique on timeline events
      changes:
        - addUniqueConstraint:
            tableName: timeline_event
            columnNames: entity_id
            constraintName: uq_timeline_event_entity_id
      rollback:
        - dropUniqueConstraint:
            tableName: timeline_event
            constraintName: uq_timeline_event_entity_id