--
-- PostgreSQL database dump
--

-- Dumped from database version 12.4
-- Dumped by pg_dump version 12.4

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: new_edge(integer, integer, integer); Type: FUNCTION; Schema: public; Owner: noah
--

CREATE FUNCTION public.new_edge(from_id integer, to_id integer, exploit integer) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE
  myid INTEGER;
BEGIN
  IF NOT EXISTS (SELECT 1 FROM edge WHERE from_node = from_id AND to_node = to_id AND exploit_id = exploit) THEN
    INSERT INTO edge VALUES (DEFAULT, from_id, to_id, exploit) RETURNING id INTO myid;
  ELSE
    SELECT id INTO myid FROM edge WHERE from_node = from_id AND to_node = to_id AND exploit_id = exploit;
  END IF;

  RETURN myid;
END;
$$;


ALTER FUNCTION public.new_edge(from_id integer, to_id integer, exploit integer) OWNER TO noah;

--
-- Name: new_factbase(text); Type: FUNCTION; Schema: public; Owner: noah
--

CREATE FUNCTION public.new_factbase(myhash text) RETURNS integer
    LANGUAGE plpgsql
    AS $$
DECLARE
  myid INTEGER;
BEGIN
  IF NOT EXISTS (SELECT 1 FROM factbase WHERE hash = myhash) THEN
    INSERT INTO factbase VALUES (DEFAULT, myhash) RETURNING id INTO myid;
  ELSE
    SELECT id INTO myid FROM factbase WHERE hash = myhash;
  END IF;

  RETURN myid;
END;
$$;


ALTER FUNCTION public.new_factbase(myhash text) OWNER TO noah;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: asset; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.asset (
    id integer NOT NULL,
    name text
);


ALTER TABLE public.asset OWNER TO noah;

--
-- Name: asset_id_seq; Type: SEQUENCE; Schema: public; Owner: noah
--

CREATE SEQUENCE public.asset_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.asset_id_seq OWNER TO noah;

--
-- Name: asset_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: noah
--

ALTER SEQUENCE public.asset_id_seq OWNED BY public.asset.id;


--
-- Name: edge; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.edge (
    id integer NOT NULL,
    from_node integer,
    to_node integer,
    exploit_id integer
);


ALTER TABLE public.edge OWNER TO noah;

--
-- Name: edge_asset_binding; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.edge_asset_binding (
    edge_id integer,
    exploit_param integer,
    asset_id integer
);


ALTER TABLE public.edge_asset_binding OWNER TO noah;

--
-- Name: edge_id_seq; Type: SEQUENCE; Schema: public; Owner: noah
--

CREATE SEQUENCE public.edge_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.edge_id_seq OWNER TO noah;

--
-- Name: edge_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: noah
--

ALTER SEQUENCE public.edge_id_seq OWNED BY public.edge.id;


--
-- Name: exploit; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.exploit (
    id integer NOT NULL,
    name text,
    params integer,
    "group" text
);


ALTER TABLE public.exploit OWNER TO noah;

--
-- Name: exploit_id_seq; Type: SEQUENCE; Schema: public; Owner: noah
--

CREATE SEQUENCE public.exploit_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.exploit_id_seq OWNER TO noah;

--
-- Name: exploit_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: noah
--

ALTER SEQUENCE public.exploit_id_seq OWNED BY public.exploit.id;


--
-- Name: exploit_postcondition; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.exploit_postcondition (
    id integer NOT NULL,
    exploit_id integer,
    type integer,
    param1 integer,
    param2 integer,
    property text,
    value text,
    op text,
    dir text,
    action text
);


ALTER TABLE public.exploit_postcondition OWNER TO noah;

--
-- Name: exploit_postcondition_id_seq; Type: SEQUENCE; Schema: public; Owner: noah
--

CREATE SEQUENCE public.exploit_postcondition_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.exploit_postcondition_id_seq OWNER TO noah;

--
-- Name: exploit_postcondition_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: noah
--

ALTER SEQUENCE public.exploit_postcondition_id_seq OWNED BY public.exploit_postcondition.id;


--
-- Name: exploit_precondition; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.exploit_precondition (
    id integer NOT NULL,
    exploit_id integer,
    type integer,
    param1 integer,
    param2 integer,
    property text,
    value text,
    op text,
    dir text
);


ALTER TABLE public.exploit_precondition OWNER TO noah;

--
-- Name: exploit_precondition_id_seq; Type: SEQUENCE; Schema: public; Owner: noah
--

CREATE SEQUENCE public.exploit_precondition_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.exploit_precondition_id_seq OWNER TO noah;

--
-- Name: exploit_precondition_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: noah
--

ALTER SEQUENCE public.exploit_precondition_id_seq OWNED BY public.exploit_precondition.id;


--
-- Name: factbase; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.factbase (
    id integer NOT NULL,
    hash text
);


ALTER TABLE public.factbase OWNER TO noah;

--
-- Name: factbase_id_seq; Type: SEQUENCE; Schema: public; Owner: noah
--

CREATE SEQUENCE public.factbase_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.factbase_id_seq OWNER TO noah;

--
-- Name: factbase_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: noah
--

ALTER SEQUENCE public.factbase_id_seq OWNED BY public.factbase.id;


--
-- Name: factbase_item; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.factbase_item (
    factbase_id integer NOT NULL,
    f bigint NOT NULL,
    type text NOT NULL
);


ALTER TABLE public.factbase_item OWNER TO noah;

--
-- Name: keyvalue; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.keyvalue (
    id integer NOT NULL,
    property text
);


ALTER TABLE public.keyvalue OWNER TO noah;

--
-- Name: quality; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.quality (
    asset_id integer NOT NULL,
    property text NOT NULL,
    op text,
    value text
);


ALTER TABLE public.quality OWNER TO noah;

CREATE TABLE public.unex_state_q (
	fid integer NOT NULL,
	asset_id integer NOT NULL,
	property text NOT NULL,
	op text,
	value text
);

ALTER TABLE public.unex_state_q OWNER TO noah;

--
-- Name: topology; Type: TABLE; Schema: public; Owner: noah
--

CREATE TABLE public.topology (
    asset_from_id integer NOT NULL,
    asset_to_id integer NOT NULL,
    direction text,
    property text NOT NULL,
    op text,
    value text
);

CREATE TABLE public.unex_state_t (
	fid integer NOT NULL,
	asset_from_id integer NOT NULL,
    asset_to_id integer NOT NULL,
    direction text,
    property text NOT NULL,
    op text,
    value text
);

ALTER TABLE public.unex_state_t OWNER TO noah;


ALTER TABLE public.topology OWNER TO noah;

--
-- Name: asset id; Type: DEFAULT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.asset ALTER COLUMN id SET DEFAULT nextval('public.asset_id_seq'::regclass);


--
-- Name: edge id; Type: DEFAULT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge ALTER COLUMN id SET DEFAULT nextval('public.edge_id_seq'::regclass);


--
-- Name: exploit id; Type: DEFAULT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit ALTER COLUMN id SET DEFAULT nextval('public.exploit_id_seq'::regclass);


--
-- Name: exploit_postcondition id; Type: DEFAULT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit_postcondition ALTER COLUMN id SET DEFAULT nextval('public.exploit_postcondition_id_seq'::regclass);


--
-- Name: exploit_precondition id; Type: DEFAULT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit_precondition ALTER COLUMN id SET DEFAULT nextval('public.exploit_precondition_id_seq'::regclass);


--
-- Name: factbase id; Type: DEFAULT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.factbase ALTER COLUMN id SET DEFAULT nextval('public.factbase_id_seq'::regclass);


--
-- Name: asset asset_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.asset
    ADD CONSTRAINT asset_pkey PRIMARY KEY (id);


--
-- Name: edge edge_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge
    ADD CONSTRAINT edge_pkey PRIMARY KEY (id);


--
-- Name: exploit exploit_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit
    ADD CONSTRAINT exploit_pkey PRIMARY KEY (id);


--
-- Name: exploit_postcondition exploit_postcondition_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit_postcondition
    ADD CONSTRAINT exploit_postcondition_pkey PRIMARY KEY (id);


--
-- Name: exploit_precondition exploit_precondition_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit_precondition
    ADD CONSTRAINT exploit_precondition_pkey PRIMARY KEY (id);


--
-- Name: factbase_item factbase_item_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.factbase_item
    ADD CONSTRAINT factbase_item_pkey PRIMARY KEY (factbase_id, f, type);


--
-- Name: factbase factbase_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.factbase
    ADD CONSTRAINT factbase_pkey PRIMARY KEY (id);


--
-- Name: keyvalue keyvalue_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.keyvalue
    ADD CONSTRAINT keyvalue_pkey PRIMARY KEY (id);


--
-- Name: quality quality_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.quality
    ADD CONSTRAINT quality_pkey PRIMARY KEY (asset_id, property);


--
-- Name: topology topology_pkey; Type: CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.topology
    ADD CONSTRAINT topology_pkey PRIMARY KEY (asset_from_id, asset_to_id, property);


--
-- Name: edge_asset_binding edge_asset_binding_asset_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge_asset_binding
    ADD CONSTRAINT edge_asset_binding_asset_id_fkey FOREIGN KEY (asset_id) REFERENCES public.asset(id);


--
-- Name: edge_asset_binding edge_asset_binding_edge_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge_asset_binding
    ADD CONSTRAINT edge_asset_binding_edge_id_fkey FOREIGN KEY (edge_id) REFERENCES public.edge(id);


--
-- Name: edge edge_exploit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge
    ADD CONSTRAINT edge_exploit_id_fkey FOREIGN KEY (exploit_id) REFERENCES public.exploit(id);


--
-- Name: edge edge_from_node_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge
    ADD CONSTRAINT edge_from_node_fkey FOREIGN KEY (from_node) REFERENCES public.factbase(id);


--
-- Name: edge edge_to_node_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.edge
    ADD CONSTRAINT edge_to_node_fkey FOREIGN KEY (to_node) REFERENCES public.factbase(id);


--
-- Name: exploit_postcondition exploit_postcondition_exploit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit_postcondition
    ADD CONSTRAINT exploit_postcondition_exploit_id_fkey FOREIGN KEY (exploit_id) REFERENCES public.exploit(id);


--
-- Name: exploit_precondition exploit_precondition_exploit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.exploit_precondition
    ADD CONSTRAINT exploit_precondition_exploit_id_fkey FOREIGN KEY (exploit_id) REFERENCES public.exploit(id);


--
-- Name: factbase_item factbase_item_factbase_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.factbase_item
    ADD CONSTRAINT factbase_item_factbase_id_fkey FOREIGN KEY (factbase_id) REFERENCES public.factbase(id);


--
-- Name: quality quality_asset_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.quality
    ADD CONSTRAINT quality_asset_id_fkey FOREIGN KEY (asset_id) REFERENCES public.asset(id);


--
-- Name: topology topology_asset_from_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.topology
    ADD CONSTRAINT topology_asset_from_id_fkey FOREIGN KEY (asset_from_id) REFERENCES public.asset(id);


--
-- Name: topology topology_asset_to_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: noah
--

ALTER TABLE ONLY public.topology
    ADD CONSTRAINT topology_asset_to_id_fkey FOREIGN KEY (asset_to_id) REFERENCES public.asset(id);


--
-- Name: TABLE asset; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.asset TO ag_gen;


--
-- Name: TABLE edge; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.edge TO ag_gen;


--
-- Name: TABLE edge_asset_binding; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.edge_asset_binding TO ag_gen;


--
-- Name: TABLE exploit; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.exploit TO ag_gen;


--
-- Name: TABLE exploit_postcondition; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.exploit_postcondition TO ag_gen;


--
-- Name: TABLE exploit_precondition; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.exploit_precondition TO ag_gen;


--
-- Name: TABLE factbase; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.factbase TO ag_gen;


--
-- Name: TABLE factbase_item; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.factbase_item TO ag_gen;


--
-- Name: TABLE keyvalue; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.keyvalue TO ag_gen;


--
-- Name: TABLE quality; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.quality TO ag_gen;

GRANT ALL ON TABLE public.unex_state_q TO ag_gen;

--
-- Name: TABLE topology; Type: ACL; Schema: public; Owner: noah
--

GRANT ALL ON TABLE public.topology TO ag_gen;

GRANT ALL ON TABLE public.unex_state_t TO ag_gen;


--
-- PostgreSQL database dump complete
--

