-- =============================================================================
-- AXON Table.  All events are saved in this table
-- =============================================================================
CREATE TABLE `domain_event_entry` (
  `global_index`         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `aggregate_identifier` CHAR(36) NOT NULL,
  `event_identifier`     CHAR(36) NOT NULL,
  `sequence_number`      BIGINT UNSIGNED NOT NULL,
  `type`                 VARCHAR(255) DEFAULT NULL,
  `payload_revision`     VARCHAR(255) DEFAULT NULL,
  `payload_type`         VARCHAR(255) NOT NULL,
  `time_stamp`           VARCHAR(255) NOT NULL,
  `meta_data`            BLOB DEFAULT NULL,
  `payload`              BLOB NOT NULL,
  PRIMARY KEY (`global_index`),
  UNIQUE KEY (`aggregate_identifier`, `sequence_number`),
  UNIQUE KEY (`event_identifier`)
);
-- =============================================================================


-- =============================================================================
-- AXON Table.  All snapshots are saved in this table
-- =============================================================================
CREATE TABLE `snapshot_event_entry` (
  `global_index`         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `aggregate_identifier` CHAR(36) NOT NULL,
  `event_identifier`     CHAR(36) NOT NULL,
  `sequence_number`      BIGINT UNSIGNED NOT NULL,
  `type`                 VARCHAR(255) DEFAULT NULL,
  `payload_revision`     VARCHAR(255) DEFAULT NULL,
  `payload_type`         VARCHAR(255) NOT NULL,
  `time_stamp`           VARCHAR(255) NOT NULL,
  `meta_data`            BLOB DEFAULT NULL,
  `payload`              BLOB NOT NULL,
  PRIMARY KEY (`global_index`),
  UNIQUE KEY (`aggregate_identifier`, `sequence_number`),
  UNIQUE KEY (`event_identifier`)
);
-- =============================================================================


-- =============================================================================
-- AXON Table.  All tokens are saved in this table
-- =============================================================================
CREATE TABLE `token_entry` (
  `processor_name`       VARCHAR(255) NOT NULL,
  `segment`              INTEGER UNSIGNED NOT NULL,
  `token`                BLOB DEFAULT NULL,
  `token_type`           VARCHAR(255) DEFAULT NULL,
  `timestamp`            VARCHAR(255) DEFAULT NULL,
  `owner`                VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (`processor_name`, `segment`)
);
-- =============================================================================


-- =============================================================================
-- AXON Table.  All saga are saved in this table
-- =============================================================================
CREATE TABLE `saga_entry` (
  `saga_id`              VARCHAR(255) NOT NULL,
  `revision`             VARCHAR(255),
  `saga_type`            VARCHAR(255),
  `serialized_saga`      BLOB,
  PRIMARY KEY (`saga_id`)
);
-- =============================================================================


-- =============================================================================
-- AXON Table.
-- =============================================================================
CREATE TABLE `association_value_entry` (
  `id`                   BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `association_key`      VARCHAR(255),
  `association_value`    VARCHAR(255),
  `saga_id`              VARCHAR(255),
  `saga_type`            VARCHAR(255),
  PRIMARY KEY (`id`),
  KEY (`association_key`),
  KEY (`saga_id`)
);
-- =============================================================================
