Skip to content

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

fix: keep timeline event timestamps when backfilling entity IDs on MariaDB (#83986)

Uladzimir Havenchyk977807f1ca4a
diff --git a/resources/migrations/065/20260909_timeline_event_entity_id.yaml b/resources/migrations/065/20260909_timeline_event_entity_id.yaml
index 69752636874..e1fb4775cce 100644
--- a/resources/migrations/065/20260909_timeline_event_entity_id.yaml
+++ b/resources/migrations/065/20260909_timeline_event_entity_id.yaml
@@ -3,6 +3,9 @@
## 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:
@@ -24,6 +27,19 @@ databaseChangeLog:
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
diff --git a/test/metabase/app_db/schema_migrations_test.clj b/test/metabase/app_db/schema_migrations_test.clj
index d5a9b5acf8d..efd2384df29 100644
--- a/test/metabase/app_db/schema_migrations_test.clj
+++ b/test/metabase/app_db/schema_migrations_test.clj
@@ -3730,6 +3730,36 @@
(is (= 3 (count (set entity-ids))))
(is (every? #(and (string? %) (re-matches #"[A-Za-z0-9_-]{21}" %)) entity-ids))))))))
+(deftest timeline-event-timestamp-kept-on-update-test
+ (testing "v65.m2xncr: updating a timeline event keeps its date"
+ (impl/test-migrations ["v65.m2xncr"] [migrate!]
+ (let [user-id (t2/insert-returning-pk! :core_user {:email "[email protected]"
+ :password "password"
+ :date_joined :%now
+ :entity_id (u/generate-nano-id)})
+ timeline-id (t2/insert-returning-pk! :timeline {:name "Crane seasons"
+ :icon "star"
+ :creator_id user-id
+ :created_at :%now
+ :updated_at :%now
+ :entity_id (u/generate-nano-id)})
+ event-id (t2/insert-returning-pk! :timeline_event {:name "Cranes arrive"
+ :archived false
+ :icon "star"
+ :timeline_id timeline-id
+ :creator_id user-id
+ :created_at :%now
+ :updated_at :%now
+ :timestamp #t "2027-03-10T00:00:00Z"
+ :time_matters false
+ :timezone "UTC"
+ :entity_id (u/generate-nano-id)})
+ event-date #(t2/select-one-fn :timestamp :timeline_event :id event-id)
+ before (event-date)]
+ (migrate!)
+ (t2/update! :timeline_event event-id {:archived true})
+ (is (= before (event-date)))))))
+
(deftest add-library-dashboards-section-test
(testing "v65.2026-10-06T16:00:00 through v65.2026-10-06T16:00:02: an existing Library gets a Dashboards section with its permissions"
(impl/test-migrations ["v65.2026-10-06T16:00:00" "v65.2026-10-06T16:00:02"] [migrate!]