     event       varchar(255) not null,
     active      boolean      not null,
     json_data   text         not null
-);
-
-CREATE SEQUENCE meta_error_registry_id_seq;
-
-CREATE TABLE meta_error_registry
+    );
+
+CREATE SEQUENCE IF NOT EXISTS meta_error_registry_id_seq;
+
+create table if not exists meta_error_registry
 (
     id              INTEGER DEFAULT nextval('meta_error_registry_id_seq'::regclass) NOT NULL,
     error_code      TEXT                                                            NOT NULL,

    message_id   varchar(255) not null,
    subject      varchar(255) not null,
    published_on timestamp    not null
);
create index event_published_subject_date on event_published (subject, published_on);
create index event_published_created_on on event_published (created_on);

-- --------------------------------------------------------------------------------------------------------------
-- schema for queue dao
-- --------------------------------------------------------------------------------------------------------------
create table queue
(
    id         bigserial primary key,
    created_on timestamp    not null default now(),
    queue_name varchar(255) not null
);
create unique index queue_name on queue (queue_name);
alter table queue
    add constraint queue_name unique using index queue_name;

create table queue_message
(
    id         bigserial primary key,
    queue_name varchar(255) not null,
    message_id varchar(255) not null,
    version    bigint       not null default 0,
    popped     boolean      not null default false,
    unacked    boolean      not null default false,
    deliver_on timestamp,
    unack_on   timestamp,
    payload    text,
    priority   int          not null default 0
);
create unique index queue_name_msg on queue_message (queue_name, message_id);
alter table queue_message
    add constraint queue_name_msg unique using index queue_name_msg;
create index queue_message_deliver_on on queue_message (deliver_on);
create index queue_message_unack_on on queue_message (unack_on);
create index queue_message_message_id on queue_message (message_id);

    message_id varchar(255) not null,
    receipt    text,
    json_data  text
    );
create index if not exists event_message_created_on on event_message (created_on);

create table if not exists event_execution
(
    id           bigserial
    primary key,
    created_on   timestamp default now() not null,
    modified_on  timestamp default now() not null,
    handler_name varchar(255)            not null,
    event_name   varchar(255)            not null,
    message_id   varchar(255)            not null,
    execution_id varchar(255)            not null,
    status       varchar(255)            not null,
    subject      varchar(255)            not null,
    received_on  timestamp,
    accepted_on  timestamp,
    started_on   timestamp,
    processed_on timestamp,
    constraint event_execution_fields
    unique (handler_name, event_name, message_id, execution_id)
    );
create index if not exists event_execution_combo ON event_execution (subject, received_on);

create table if not exists event_published
(
    id           bigserial primary key,
    created_on   timestamp    not null default now(),
