--
--

SET escape_string_warning = off;




--
-- Name: node; Type: TABLE; Schema: public; Owner: woladmin; Tablespace: 
--

CREATE TABLE node (
    node_id integer NOT NULL,
    mac_address character varying(17) NOT NULL,
    date timestamp without time zone NOT NULL,
    type_id smallint DEFAULT 1 NOT NULL,
    subnet_id smallint NOT NULL,
    name character varying(80)
);


ALTER TABLE public.node OWNER TO woladmin;

--
-- Name: node_seq; Type: SEQUENCE; Schema: public; Owner: woladmin
--

CREATE SEQUENCE node_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.node_seq OWNER TO woladmin;

--
-- Name: nodetype; Type: TABLE; Schema: public; Owner: woladmin; Tablespace: 
--

CREATE TABLE nodetype (
    type_id smallint NOT NULL,
    name character varying(20) NOT NULL,
    description character(40)
);


INSERT INTO nodetype (type_id, name, description)
    VALUES (1, 'desktop', 'the desktop computers');
INSERT INTO nodetype (type_id, name, description)
    VALUES (2, 'server', 'the servers');
INSERT INTO nodetype (type_id, name, description)
    VALUES (3, 'net', 'the network gears');
INSERT INTO nodetype (type_id, name, description)
    VALUES (4, 'other', 'others');
INSERT INTO nodetype (type_id, name, description)
    VALUES (5, 'vm', 'the virtual machines');
INSERT INTO nodetype (type_id, name, description)
    VALUES (6, 'unknown', 'the default unknowns');
    
    

ALTER TABLE public.nodetype OWNER TO woladmin;

--
-- Name: nodetype_seq; Type: SEQUENCE; Schema: public; Owner: woladmin
--

CREATE SEQUENCE nodetype_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.nodetype_seq OWNER TO woladmin;

--
-- Name: record; Type: TABLE; Schema: public; Owner: woladmin; Tablespace: 
--

CREATE TABLE record (
    record_id bigint NOT NULL,
    node_id integer NOT NULL,
    recordtime_id integer NOT NULL
);


ALTER TABLE public.record OWNER TO woladmin;

--
-- Name: record_seq; Type: SEQUENCE; Schema: public; Owner: woladmin
--

CREATE SEQUENCE record_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.record_seq OWNER TO woladmin;

--
-- Name: recordtime; Type: TABLE; Schema: public; Owner: woladmin; Tablespace: 
--

CREATE TABLE recordtime (
    recordtime_id integer NOT NULL,
    datetime timestamp without time zone NOT NULL
);


ALTER TABLE public.recordtime OWNER TO woladmin;

--
-- Name: recordtime_seq; Type: SEQUENCE; Schema: public; Owner: woladmin
--

CREATE SEQUENCE recordtime_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.recordtime_seq OWNER TO woladmin;

--
-- Name: subnet; Type: TABLE; Schema: public; Owner: woladmin; Tablespace: 
--

CREATE TABLE subnet (
    subnet_id smallint NOT NULL,
    gateway character varying(15) NOT NULL,
    description character varying(40),
    target integer
);


ALTER TABLE public.subnet OWNER TO woladmin;

--
-- Name: subnet_seq; Type: SEQUENCE; Schema: public; Owner: woladmin
--

CREATE SEQUENCE subnet_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.subnet_seq OWNER TO woladmin;

--
-- Name: pk_node; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY node
    ADD CONSTRAINT pk_node PRIMARY KEY (node_id);


--
-- Name: pk_nodetype; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY nodetype
    ADD CONSTRAINT pk_nodetype PRIMARY KEY (type_id);


--
-- Name: pk_record; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY record
    ADD CONSTRAINT pk_record PRIMARY KEY (record_id);


--
-- Name: pk_recordtime; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY recordtime
    ADD CONSTRAINT pk_recordtime PRIMARY KEY (recordtime_id);


--
-- Name: pk_subnet; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY subnet
    ADD CONSTRAINT pk_subnet PRIMARY KEY (subnet_id);


--
-- Name: unique_gateway; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY subnet
    ADD CONSTRAINT unique_gateway UNIQUE (gateway);


--
-- Name: unique_mac_subnet; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY node
    ADD CONSTRAINT unique_mac_subnet UNIQUE (mac_address, subnet_id);


--
-- Name: unique_name; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY nodetype
    ADD CONSTRAINT unique_name UNIQUE (name);


--
-- Name: unique_node_time; Type: CONSTRAINT; Schema: public; Owner: woladmin; Tablespace: 
--

ALTER TABLE ONLY record
    ADD CONSTRAINT unique_node_time UNIQUE (node_id, recordtime_id);


--
-- Name: record_time_idx; Type: INDEX; Schema: public; Owner: woladmin; Tablespace: 
--

CREATE INDEX record_time_idx ON record USING btree (recordtime_id);


--
-- Name: node_record; Type: FK CONSTRAINT; Schema: public; Owner: woladmin
--

ALTER TABLE ONLY record
    ADD CONSTRAINT node_record FOREIGN KEY (node_id) REFERENCES node(node_id);


--
-- Name: nodetype_node; Type: FK CONSTRAINT; Schema: public; Owner: woladmin
--

ALTER TABLE ONLY node
    ADD CONSTRAINT nodetype_node FOREIGN KEY (type_id) REFERENCES nodetype(type_id);


--
-- Name: recordtime_record; Type: FK CONSTRAINT; Schema: public; Owner: woladmin
--

ALTER TABLE ONLY record
    ADD CONSTRAINT recordtime_record FOREIGN KEY (recordtime_id) REFERENCES recordtime(recordtime_id);


--
-- Name: subnet_node; Type: FK CONSTRAINT; Schema: public; Owner: woladmin
--

ALTER TABLE ONLY node
    ADD CONSTRAINT subnet_node FOREIGN KEY (subnet_id) REFERENCES subnet(subnet_id);


--
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

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


--
--

