CREATE TABLE IF NOT EXISTS UserActions (
    Id INTEGER PRIMARY KEY AUTOINCREMENT,
    UserId TEXT NOT NULL,
    ActionType TEXT NOT NULL,
    ActionAtUtc TEXT NOT NULL,
    Source TEXT NULL,
    CorrelationId TEXT NULL,
    MetadataJson TEXT NULL
);

CREATE INDEX IF NOT EXISTS IX_UserActions_UserId_ActionAtUtc
ON UserActions(UserId, ActionAtUtc);

CREATE INDEX IF NOT EXISTS IX_UserActions_UserId_ActionType
ON UserActions(UserId, ActionType);

CREATE INDEX IF NOT EXISTS IX_UserActions_ActionType
ON UserActions(ActionType);