mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
26 lines
1.2 KiB
MySQL
26 lines
1.2 KiB
MySQL
|
CREATE TABLE IF NOT EXISTS eventstore.events (
|
||
|
id UUID DEFAULT gen_random_uuid()
|
||
|
, event_type TEXT NOT NULL
|
||
|
, aggregate_type TEXT NOT NULL
|
||
|
, aggregate_id TEXT NOT NULL
|
||
|
, aggregate_version TEXT NOT NULL
|
||
|
, event_sequence BIGINT NOT NULL
|
||
|
, previous_aggregate_sequence BIGINT
|
||
|
, previous_aggregate_type_sequence INT8
|
||
|
, creation_date TIMESTAMPTZ NOT NULL DEFAULT now()
|
||
|
, event_data JSONB
|
||
|
, editor_user TEXT NOT NULL
|
||
|
, editor_service TEXT NOT NULL
|
||
|
, resource_owner TEXT NOT NULL
|
||
|
, instance_id TEXT NOT NULL
|
||
|
|
||
|
, PRIMARY KEY (event_sequence, instance_id)
|
||
|
, CONSTRAINT previous_sequence_unique UNIQUE(previous_aggregate_sequence, instance_id)
|
||
|
, CONSTRAINT prev_agg_type_seq_unique UNIQUE(previous_aggregate_type_sequence, instance_id)
|
||
|
);
|
||
|
|
||
|
CREATE INDEX IF NOT EXISTS agg_type_agg_id ON eventstore.events (aggregate_type, aggregate_id, instance_id);
|
||
|
CREATE INDEX IF NOT EXISTS agg_type ON eventstore.events (aggregate_type, instance_id);
|
||
|
CREATE INDEX IF NOT EXISTS agg_type_seq ON eventstore.events (aggregate_type, event_sequence DESC, instance_id);
|
||
|
CREATE INDEX IF NOT EXISTS max_sequence ON eventstore.events (aggregate_type, aggregate_id, event_sequence DESC, instance_id);
|