--
--


SET SESSION AUTHORIZATION 'postgres';

--
-- TOC entry 2 (OID 0)
-- Name: oneunified; Type: DATABASE; Schema: -; Owner: oneunified
--

CREATE DATABASE oneunified WITH TEMPLATE = template0 ENCODING = 'UNICODE';


\connect oneunified postgres


--
-- TOC entry 4 (OID 2200)
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
GRANT ALL ON SCHEMA public TO PUBLIC;


SET SESSION AUTHORIZATION 'oneunified';


--
-- TOC entry 5 (OID 37168)
-- Name: location; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE "location" (
    locationid serial NOT NULL,
    self integer,
    name text NOT NULL,
    description text,
    url text
) WITHOUT OIDS;


--
-- TOC entry 6 (OID 37176)
-- Name: organization; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE organization (
    organizationid serial NOT NULL,
    asn integer,
    name text NOT NULL,
    whoisid text,
    description text,
    url text
) WITHOUT OIDS;


--
-- TOC entry 7 (OID 37184)
-- Name: address; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE address (
    addressid serial NOT NULL,
    self integer,
    address inet NOT NULL,
    name text,
    organizationid integer NOT NULL,
    description text,
    url text
) WITHOUT OIDS;


--
-- TOC entry 8 (OID 37192)
-- Name: circuit; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE circuit (
    circuitid serial NOT NULL,
    self integer,
    name text NOT NULL,
    addressid integer,
    description text,
    url text
) WITHOUT OIDS;


--
-- TOC entry 9 (OID 37200)
-- Name: host; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE host (
    hostid serial NOT NULL,
    name text NOT NULL,
    locationid integer NOT NULL,
    description text,
    url1 text,
    url2 text
) WITHOUT OIDS;


--
-- TOC entry 10 (OID 37208)
-- Name: port; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE port (
    portid serial NOT NULL,
    addressid integer NOT NULL,
    port smallint NOT NULL,
    portend smallint,
    name text NOT NULL,
    description text,
    url text
) WITHOUT OIDS;


--
-- TOC entry 11 (OID 37214)
-- Name: ianaiftype; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE ianaiftype (
    ianaiftypeid integer NOT NULL,
    name text NOT NULL,
    description text
) WITHOUT OIDS;


--
-- TOC entry 12 (OID 37221)
-- Name: interface; Type: TABLE; Schema: public; Owner: oneunified
--

CREATE TABLE interface (
    interfaceid serial NOT NULL,
    self integer,
    ianaiftypeid integer NOT NULL,
    circuitid integer,
    addressid integer,
    name text NOT NULL,
    mac macaddr,
    hostid integer,
    description text,
    fqdn text,
    url text
) WITHOUT OIDS;


--
-- TOC entry 13 (OID 37227)
-- Name: ndx_location_name; Type: INDEX; Schema: public; Owner: oneunified
--

CREATE UNIQUE INDEX ndx_location_name ON "location" USING btree (name);


--
-- TOC entry 17 (OID 37228)
-- Name: ndx_address_address; Type: INDEX; Schema: public; Owner: oneunified
--

CREATE UNIQUE INDEX ndx_address_address ON address USING btree (address);


--
-- TOC entry 22 (OID 37229)
-- Name: ndx_host_name; Type: INDEX; Schema: public; Owner: oneunified
--

CREATE INDEX ndx_host_name ON host USING btree (name);


--
-- TOC entry 14 (OID 37230)
-- Name: pk_location_locationid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY "location"
    ADD CONSTRAINT pk_location_locationid PRIMARY KEY (locationid);


--
-- TOC entry 16 (OID 37232)
-- Name: pk_organization_organizationid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY organization
    ADD CONSTRAINT pk_organization_organizationid PRIMARY KEY (organizationid);


--
-- TOC entry 18 (OID 37234)
-- Name: pk_address_addressid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY address
    ADD CONSTRAINT pk_address_addressid PRIMARY KEY (addressid);


--
-- TOC entry 19 (OID 37236)
-- Name: unique_address_address; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY address
    ADD CONSTRAINT unique_address_address UNIQUE (address);


--
-- TOC entry 20 (OID 37238)
-- Name: pk_circuit_circuitid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY circuit
    ADD CONSTRAINT pk_circuit_circuitid PRIMARY KEY (circuitid);


--
-- TOC entry 21 (OID 37240)
-- Name: unique_circuit_circuitid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY circuit
    ADD CONSTRAINT unique_circuit_circuitid UNIQUE (circuitid);


--
-- TOC entry 15 (OID 37242)
-- Name: unique_location_locationid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY "location"
    ADD CONSTRAINT unique_location_locationid UNIQUE (locationid);


--
-- TOC entry 23 (OID 37244)
-- Name: pk_host_hostid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY host
    ADD CONSTRAINT pk_host_hostid PRIMARY KEY (hostid);


--
-- TOC entry 24 (OID 37246)
-- Name: pk_port_portid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY port
    ADD CONSTRAINT pk_port_portid PRIMARY KEY (portid);


--
-- TOC entry 25 (OID 37248)
-- Name: pk_ianaiftype_ianaiftypeid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY ianaiftype
    ADD CONSTRAINT pk_ianaiftype_ianaiftypeid PRIMARY KEY (ianaiftypeid);


--
-- TOC entry 26 (OID 37250)
-- Name: pk_interface_interfaceid; Type: CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY interface
    ADD CONSTRAINT pk_interface_interfaceid PRIMARY KEY (interfaceid);


--
-- TOC entry 27 (OID 37252)
-- Name: fk_address_organizationid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY address
    ADD CONSTRAINT fk_address_organizationid FOREIGN KEY (organizationid) REFERENCES organization(organizationid) ON UPDATE CASCADE;


--
-- TOC entry 28 (OID 37256)
-- Name: fk_circuit_addressid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY circuit
    ADD CONSTRAINT fk_circuit_addressid FOREIGN KEY (addressid) REFERENCES address(addressid) ON UPDATE CASCADE;


--
-- TOC entry 29 (OID 37260)
-- Name: fk_host_locationid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY host
    ADD CONSTRAINT fk_host_locationid FOREIGN KEY (locationid) REFERENCES "location"(locationid) ON UPDATE CASCADE;


--
-- TOC entry 30 (OID 37264)
-- Name: fk_port_addressid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY port
    ADD CONSTRAINT fk_port_addressid FOREIGN KEY (addressid) REFERENCES address(addressid) ON UPDATE CASCADE;


--
-- TOC entry 31 (OID 37268)
-- Name: fk_interface_ianaiftypeid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY interface
    ADD CONSTRAINT fk_interface_ianaiftypeid FOREIGN KEY (ianaiftypeid) REFERENCES ianaiftype(ianaiftypeid) ON UPDATE CASCADE;


--
-- TOC entry 32 (OID 37272)
-- Name: fk_interface_addressid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY interface
    ADD CONSTRAINT fk_interface_addressid FOREIGN KEY (addressid) REFERENCES address(addressid) ON UPDATE CASCADE;


--
-- TOC entry 33 (OID 37276)
-- Name: fk_interface_circuitid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY interface
    ADD CONSTRAINT fk_interface_circuitid FOREIGN KEY (circuitid) REFERENCES circuit(circuitid) ON UPDATE CASCADE;


--
-- TOC entry 34 (OID 37280)
-- Name: fk_interface_hostid; Type: FK CONSTRAINT; Schema: public; Owner: oneunified
--

ALTER TABLE ONLY interface
    ADD CONSTRAINT fk_interface_hostid FOREIGN KEY (hostid) REFERENCES host(hostid) ON UPDATE CASCADE;


SET SESSION AUTHORIZATION 'postgres';

--
-- TOC entry 3 (OID 2200)
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
--

COMMENT ON SCHEMA public IS 'Standard public schema';


