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) ,
    payload        TEXT                       ,
    metadata       TEXT                        ,
    timestamp      timestamp DEFAULT (CURRENT_TIMESTAMP),
    PRIMARY KEY (aggregate_type, aggregate_id, sequence)
);

CREATE
    USER
    'demo_user'@'localhost'
IDENTIFIED BY
    'password';

GRANT
    ALL
ON
    demo.*
TO
    'demo_user'@'localhost';
