-- Schema: bird__image_and_language
CREATE SCHEMA IF NOT EXISTS "bird__image_and_language";

-- Table: ATT_CLASSES
CREATE TABLE "bird__image_and_language"."ATT_CLASSES" (
    "ATT_CLASS_ID" BIGINT NOT NULL DEFAULT 0,
    "ATT_CLASS" TEXT NOT NULL,
    CONSTRAINT "ATT_CLASSES_pkey" PRIMARY KEY ("ATT_CLASS_ID")
);

-- Table: IMG_OBJ
CREATE TABLE "bird__image_and_language"."IMG_OBJ" (
    "IMG_ID" BIGINT NOT NULL DEFAULT 0,
    "OBJ_SAMPLE_ID" BIGINT NOT NULL DEFAULT 0,
    "OBJ_CLASS_ID" BIGINT,
    "X" BIGINT,
    "Y" BIGINT,
    "W" BIGINT,
    "H" BIGINT,
    CONSTRAINT "IMG_OBJ_pkey" PRIMARY KEY ("IMG_ID", "OBJ_SAMPLE_ID")
);

-- Table: IMG_OBJ_ATT
CREATE TABLE "bird__image_and_language"."IMG_OBJ_ATT" (
    "IMG_ID" BIGINT NOT NULL DEFAULT 0,
    "ATT_CLASS_ID" BIGINT NOT NULL DEFAULT 0,
    "OBJ_SAMPLE_ID" BIGINT NOT NULL DEFAULT 0,
    CONSTRAINT "IMG_OBJ_ATT_pkey" PRIMARY KEY ("IMG_ID", "ATT_CLASS_ID", "OBJ_SAMPLE_ID")
);

-- Table: IMG_REL
CREATE TABLE "bird__image_and_language"."IMG_REL" (
    "IMG_ID" BIGINT NOT NULL DEFAULT 0,
    "PRED_CLASS_ID" BIGINT NOT NULL DEFAULT 0,
    "OBJ1_SAMPLE_ID" BIGINT NOT NULL DEFAULT 0,
    "OBJ2_SAMPLE_ID" BIGINT NOT NULL DEFAULT 0,
    CONSTRAINT "IMG_REL_pkey" PRIMARY KEY ("IMG_ID", "PRED_CLASS_ID", "OBJ1_SAMPLE_ID", "OBJ2_SAMPLE_ID")
);

-- Table: OBJ_CLASSES
CREATE TABLE "bird__image_and_language"."OBJ_CLASSES" (
    "OBJ_CLASS_ID" BIGINT NOT NULL DEFAULT 0,
    "OBJ_CLASS" TEXT NOT NULL,
    CONSTRAINT "OBJ_CLASSES_pkey" PRIMARY KEY ("OBJ_CLASS_ID")
);

-- Table: PRED_CLASSES
CREATE TABLE "bird__image_and_language"."PRED_CLASSES" (
    "PRED_CLASS_ID" BIGINT NOT NULL DEFAULT 0,
    "PRED_CLASS" TEXT NOT NULL,
    CONSTRAINT "PRED_CLASSES_pkey" PRIMARY KEY ("PRED_CLASS_ID")
);

-- Foreign Keys
ALTER TABLE "bird__image_and_language"."IMG_OBJ" ADD CONSTRAINT "fk_IMG_OBJ_0" FOREIGN KEY ("OBJ_CLASS_ID") REFERENCES "bird__image_and_language"."OBJ_CLASSES" ("OBJ_CLASS_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__image_and_language"."IMG_OBJ_ATT" ADD CONSTRAINT "fk_IMG_OBJ_ATT_0" FOREIGN KEY ("IMG_ID", "IMG_ID", "OBJ_SAMPLE_ID", "OBJ_SAMPLE_ID") REFERENCES "bird__image_and_language"."IMG_OBJ" ("IMG_ID", "IMG_ID", "OBJ_SAMPLE_ID", "OBJ_SAMPLE_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__image_and_language"."IMG_OBJ_ATT" ADD CONSTRAINT "fk_IMG_OBJ_ATT_1" FOREIGN KEY ("ATT_CLASS_ID") REFERENCES "bird__image_and_language"."ATT_CLASSES" ("ATT_CLASS_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__image_and_language"."IMG_REL" ADD CONSTRAINT "fk_IMG_REL_0" FOREIGN KEY ("IMG_ID", "IMG_ID", "OBJ2_SAMPLE_ID", "OBJ2_SAMPLE_ID") REFERENCES "bird__image_and_language"."IMG_OBJ" ("IMG_ID", "IMG_ID", "OBJ_SAMPLE_ID", "OBJ_SAMPLE_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__image_and_language"."IMG_REL" ADD CONSTRAINT "fk_IMG_REL_1" FOREIGN KEY ("IMG_ID", "IMG_ID", "OBJ1_SAMPLE_ID", "OBJ1_SAMPLE_ID") REFERENCES "bird__image_and_language"."IMG_OBJ" ("IMG_ID", "IMG_ID", "OBJ_SAMPLE_ID", "OBJ_SAMPLE_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "bird__image_and_language"."IMG_REL" ADD CONSTRAINT "fk_IMG_REL_2" FOREIGN KEY ("PRED_CLASS_ID") REFERENCES "bird__image_and_language"."PRED_CLASSES" ("PRED_CLASS_ID") ON DELETE NO ACTION ON UPDATE NO ACTION;
