CREATE SEQUENCE decaying_models_seq;

CREATE TABLE IF NOT EXISTS decaying_models (
    id int NOT NULL DEFAULT NEXTVAL ('decaying_models_seq'),
    uuid varchar(40) DEFAULT NULL,
    name varchar(255) NOT NULL,
    parameters text,
    attribute_types text,
    description text,
    org_id int,
    enabled smallint NOT NULL DEFAULT 0,
    all_orgs smallint NOT NULL DEFAULT 1,
    ref text,
    formula varchar(255) NOT NULL,
    version varchar(255) NOT NULL DEFAULT '',
    "default" smallint NOT NULL DEFAULT 0,
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18000_uuid ON decaying_models (uuid);
CREATE INDEX idx_18000_name ON decaying_models (name);
CREATE INDEX idx_18000_org_id ON decaying_models (org_id);
CREATE INDEX idx_18000_enabled ON decaying_models (enabled);
CREATE INDEX idx_18000_all_orgs ON decaying_models (all_orgs);
CREATE INDEX idx_18000_version ON decaying_models (version);

CREATE SEQUENCE decaying_model_mappings_seq;

CREATE TABLE IF NOT EXISTS decaying_model_mappings (
    id int NOT NULL DEFAULT NEXTVAL ('decaying_model_mappings_seq'),
    attribute_type varchar(255) NOT NULL,
    model_id int NOT NULL,
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18010_model_id ON decaying_model_mappings (model_id);

CREATE SEQUENCE event_graph_seq;

CREATE TABLE IF NOT EXISTS event_graph (
    id int NOT NULL DEFAULT NEXTVAL ('event_graph_seq'),
    event_id int NOT NULL,
    user_id int NOT NULL,
    org_id int NOT NULL,
    timestamp int NOT NULL DEFAULT 0,
    network_name varchar(255),
    network_json TEXT NOT NULL,
    preview_img TEXT,
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18020_event_id ON event_graph (event_id);
CREATE INDEX idx_18020_user_id ON event_graph (user_id);
CREATE INDEX idx_18020_org_id ON event_graph (org_id);
CREATE INDEX idx_18020_timestamp ON event_graph (timestamp);

CREATE SEQUENCE notification_logs_seq;

CREATE TABLE IF NOT EXISTS notification_logs (
    id int NOT NULL DEFAULT NEXTVAL ('notification_logs_seq'),
    org_id int NOT NULL,
    type varchar(255) NOT NULL,
    timestamp int NOT NULL DEFAULT 0,
    PRIMARY KEY (id)
)  ;

CREATE INDEX idx_18030_org_id ON notification_logs (org_id);
CREATE INDEX idx_18030_type ON notification_logs (type);

CREATE SEQUENCE rest_client_histories_seq;

CREATE TABLE IF NOT EXISTS rest_client_histories (
    id int NOT NULL DEFAULT NEXTVAL ('rest_client_histories_seq'),
    org_id int NOT NULL,
    user_id int NOT NULL,
    headers text,
    body text,
    url text,
    http_method varchar(255),
    timestamp int NOT NULL DEFAULT 0,
    use_full_path smallint DEFAULT 0,
    show_result smallint DEFAULT 0,
    skip_ssl smallint DEFAULT 0,
    outcome int NOT NULL,
    bookmark smallint NOT NULL DEFAUlT 0,
    bookmark_name varchar(255) NULL DEFAULT '',
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18040_org_id ON rest_client_histories (org_id);
CREATE INDEX idx_18040_user_id ON rest_client_histories (user_id);
CREATE INDEX idx_18040_timestamp ON rest_client_histories (timestamp);

CREATE SEQUENCE tag_collections_seq;

CREATE TABLE IF NOT EXISTS tag_collections (
    id int NOT NULL DEFAULT NEXTVAL ('tag_collections_seq'),
    uuid varchar(40) DEFAULT NULL,
    user_id int NOT NULL,
    org_id int NOT NULL,
    name varchar(255) NOT NULL,
    description TEXT NOT NULL,
    all_orgs smallint NOT NULL DEFAULT 0,
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18050_uuid ON tag_collections (uuid);
CREATE INDEX idx_18050_user_id ON tag_collections (user_id);
CREATE INDEX idx_18050_org_id ON tag_collections (org_id);

CREATE SEQUENCE tag_collection_tags_seq;

CREATE TABLE IF NOT EXISTS tag_collection_tags (
    id int NOT NULL DEFAULT NEXTVAL ('tag_collection_tags_seq'),
    tag_collection_id int NOT NULL,
    tag_id int NOT NULL,
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18060_uuid ON tag_collection_tags (tag_collection_id);
CREATE INDEX idx_18060_user_id ON tag_collection_tags (tag_id);

CREATE SEQUENCE user_settings_seq;

CREATE TABLE IF NOT EXISTS user_settings (
    id int NOT NULL DEFAULT NEXTVAL ('user_settings_seq'),
    setting varchar(255) NOT NULL,
    value text NOT NULL,
    user_id int NOT NULL,
    timestamp int NOT NULL
   ,
    PRIMARY KEY (id)
) ;

CREATE INDEX idx_18070_setting ON user_settings (setting);
CREATE INDEX idx_18070_user_id ON user_settings (user_id);
CREATE INDEX idx_18070_timestamp ON user_settings (timestamp);

CREATE SEQUENCE public.bruteforces_id_seq;