CREATE TABLE IF NOT EXISTS {{PREFIX}}trip_changes (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  trip_id BIGINT UNSIGNED NOT NULL,
  user_id BIGINT UNSIGNED NOT NULL,
  change_type VARCHAR(60) NOT NULL,
  message VARCHAR(500) NOT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  notification_decided_at DATETIME NULL,
  notification_skipped_by BIGINT UNSIGNED NULL,
  notified_at DATETIME NULL,
  notified_by BIGINT UNSIGNED NULL,
  PRIMARY KEY (id),
  KEY idx_trip_changes_trip (trip_id, created_at),
  CONSTRAINT fk_trip_changes_trip FOREIGN KEY (trip_id) REFERENCES {{PREFIX}}trips(id) ON DELETE CASCADE,
  CONSTRAINT fk_trip_changes_user FOREIGN KEY (user_id) REFERENCES {{PREFIX}}users(id) ON DELETE CASCADE,
  CONSTRAINT fk_trip_changes_skip_user FOREIGN KEY (notification_skipped_by) REFERENCES {{PREFIX}}users(id) ON DELETE SET NULL,
  CONSTRAINT fk_trip_changes_notify_user FOREIGN KEY (notified_by) REFERENCES {{PREFIX}}users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
