-- requires: schema-1
-- requires: table-Name
-- requires: table-Pronunciation

BEGIN;


--
-- Name: Tag; Type: TABLE; Schema: 1; Owner: knowsme_master; Tablespace: 
--

CREATE TABLE "Tag" (
    "Key" "text" NOT NULL,
    "NameId" integer,
    "PronunciationId" integer,
    "TagId" integer NOT NULL,
    CONSTRAINT "ReferToOneObjectOnly" CHECK (((("NameId" IS NOT NULL) AND (COALESCE("PronunciationId") IS NULL)) OR (("PronunciationId" IS NOT NULL) AND (COALESCE("NameId") IS NULL))))
);


ALTER TABLE "Tag" OWNER TO "knowsme_master";


--
-- Name: Tag_TagId_seq; Type: SEQUENCE; Schema: 1; Owner: knowsme_master
--

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


ALTER TABLE "Tag_TagId_seq" OWNER TO "knowsme_master";


--
-- Name: Tag_TagId_seq; Type: SEQUENCE; Schema: 1; Owner: knowsme_master
--

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


ALTER TABLE "Tag_TagId_seq" OWNER TO "knowsme_master";

--
-- Name: Tag_TagId_seq; Type: SEQUENCE OWNED BY; Schema: 1; Owner: knowsme_master
--

ALTER SEQUENCE "Tag_TagId_seq" OWNED BY "Tag"."TagId";





--
-- Name: TagId; Type: DEFAULT; Schema: 1; Owner: knowsme_master
--

ALTER TABLE ONLY "Tag" ALTER COLUMN "TagId" SET DEFAULT "nextval"('"Tag_TagId_seq"'::"regclass");


--
-- Name: Tag_Key_NameId_key; Type: CONSTRAINT; Schema: 1; Owner: knowsme_master; Tablespace: 
--

ALTER TABLE ONLY "Tag"
    ADD CONSTRAINT "Tag_Key_NameId_key" UNIQUE ("Key", "NameId");


--
-- Name: Tag_Key_PronunciationId_key; Type: CONSTRAINT; Schema: 1; Owner: knowsme_master; Tablespace: 
--

ALTER TABLE ONLY "Tag"
    ADD CONSTRAINT "Tag_Key_PronunciationId_key" UNIQUE ("Key", "PronunciationId");


--
-- Name: Tag_pkey; Type: CONSTRAINT; Schema: 1; Owner: knowsme_master; Tablespace: 
--

ALTER TABLE ONLY "Tag"
    ADD CONSTRAINT "Tag_pkey" PRIMARY KEY ("TagId");


--
-- Name: Tag_NameId_fkey; Type: FK CONSTRAINT; Schema: 1; Owner: knowsme_master
--

ALTER TABLE ONLY "Tag"
    ADD CONSTRAINT "Tag_NameId_fkey" FOREIGN KEY ("NameId") REFERENCES "Name"("NameId") ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: Tag_PronunciationId_fkey; Type: FK CONSTRAINT; Schema: 1; Owner: knowsme_master
--

ALTER TABLE ONLY "Tag"
    ADD CONSTRAINT "Tag_PronunciationId_fkey" FOREIGN KEY ("PronunciationId") REFERENCES "Pronunciation"("PronunciationId") ON UPDATE CASCADE ON DELETE CASCADE;


COMMIT;
