--
--

\connect - jwscott


--
-- TOC entry 2 (OID 4879293)
-- Name: my_staff; Type: TABLE; Schema: public; Owner: jwscott
--

CREATE TABLE my_staff (
    staff_id integer NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 3 (OID 4879297)
-- Name: my_staff_group; Type: TABLE; Schema: public; Owner: jwscott
--

CREATE TABLE my_staff_group (
    staff_group_id integer NOT NULL,
    staff_group_name text
) WITHOUT OIDS;


--
-- TOC entry 4 (OID 4879304)
-- Name: my_staff_to_group; Type: TABLE; Schema: public; Owner: jwscott
--

CREATE TABLE my_staff_to_group (
    staff_id integer NOT NULL,
    staff_group_id integer NOT NULL
) WITHOUT OIDS;


--
-- TOC entry 5 (OID 4879318)
-- Name: staff_login; Type: VIEW; Schema: public; Owner: jwscott
--

CREATE VIEW staff_login AS
    SELECT staff_id, staff_group_name AS role FROM ((my_staff NATURAL CROSS JOIN my_staff_group) NATURAL JOIN my_staff_to_group);


--
-- TOC entry 6 (OID 4879295)
-- Name: my_staff_pkey; Type: CONSTRAINT; Schema: public; Owner: jwscott
--

ALTER TABLE ONLY my_staff
    ADD CONSTRAINT my_staff_pkey PRIMARY KEY (staff_id);


--
-- TOC entry 7 (OID 4879302)
-- Name: my_staff_group_pkey; Type: CONSTRAINT; Schema: public; Owner: jwscott
--

ALTER TABLE ONLY my_staff_group
    ADD CONSTRAINT my_staff_group_pkey PRIMARY KEY (staff_group_id);


--
-- TOC entry 8 (OID 4879306)
-- Name: my_staff_to_group_pkey; Type: CONSTRAINT; Schema: public; Owner: jwscott
--

ALTER TABLE ONLY my_staff_to_group
    ADD CONSTRAINT my_staff_to_group_pkey PRIMARY KEY (staff_id, staff_group_id);


--
-- TOC entry 9 (OID 4879308)
-- Name: $1; Type: CONSTRAINT; Schema: public; Owner: jwscott
--

ALTER TABLE ONLY my_staff_to_group
    ADD CONSTRAINT "$1" FOREIGN KEY (staff_id) REFERENCES my_staff(staff_id) ON UPDATE NO ACTION ON DELETE NO ACTION;


--
-- TOC entry 10 (OID 4879312)
-- Name: $2; Type: CONSTRAINT; Schema: public; Owner: jwscott
--

ALTER TABLE ONLY my_staff_to_group
    ADD CONSTRAINT "$2" FOREIGN KEY (staff_group_id) REFERENCES my_staff_group(staff_group_id) ON UPDATE NO ACTION ON DELETE NO ACTION;


