CREATE DATABASE demo;
USE demo;

-- a single table is used for all events in the cqrs system
CREATE TABLE events
(
    aggregate_type VARCHAR(256)                 NOT NULL,
    aggregate_id   VARCHAR(256)                 NOT NULL,
    sequence       bigint CHECK (sequence >= 0) NOT NULL,
    payload        TEXT                         NOT NULL,
    metadata       TEXT                         NOT NULL,
    timestamp      timestamp DEFAULT (CURRENT_TIMESTAMP),
    PRIMARY KEY (aggregate_type, aggregate_id, sequence)
);

CREATE
    USER
    'demo_user'@'%'
IDENTIFIED BY
    'demo_pass';

GRANT
    ALL privileges
ON
    demo.*
TO
    'demo_user'@'%';

FLUSH PRIVILEGES;
