-- CreateTable
CREATE TABLE "User" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "password" TEXT NOT NULL,
    "department" TEXT NOT NULL,
    "type" INTEGER NOT NULL,
    "status" BOOLEAN NOT NULL DEFAULT true,

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Plants" (
    "id" TEXT NOT NULL,
    "popular_name" TEXT NOT NULL,
    "variables_names" TEXT NOT NULL,
    "scientific_name" TEXT NOT NULL,
    "family" TEXT NOT NULL,
    "phenology" TEXT NOT NULL,
    "division" BOOLEAN NOT NULL,
    "geographic_dist" TEXT NOT NULL,
    "others" TEXT,
    "reference" TEXT NOT NULL,

    CONSTRAINT "Plants_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Animals" (
    "id" TEXT NOT NULL,
    "popular_name" TEXT NOT NULL,
    "variables_names" TEXT NOT NULL,
    "scientific_name" TEXT NOT NULL,
    "order" TEXT NOT NULL,
    "family" TEXT NOT NULL,
    "habitat" TEXT NOT NULL,
    "food" TEXT NOT NULL,
    "habits" TEXT NOT NULL,
    "others" TEXT,
    "geographic_dist" TEXT NOT NULL,
    "group" INTEGER NOT NULL,
    "reference" TEXT NOT NULL,

    CONSTRAINT "Animals_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Apparitions" (
    "id" TEXT NOT NULL,
    "localization" TEXT,
    "map_image_url" TEXT NOT NULL,
    "latitude" DECIMAL(65,30) NOT NULL,
    "longitude" DECIMAL(65,30) NOT NULL,
    "date" TEXT,
    "animalId" TEXT,
    "plantId" TEXT,

    CONSTRAINT "Apparitions_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PhotoUrl" (
    "id" TEXT NOT NULL,
    "photo_url" TEXT,
    "author" TEXT,
    "plantId" TEXT,
    "animalId" TEXT,

    CONSTRAINT "PhotoUrl_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- AddForeignKey
ALTER TABLE "Apparitions" ADD CONSTRAINT "Apparitions_animalId_fkey" FOREIGN KEY ("animalId") REFERENCES "Animals"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Apparitions" ADD CONSTRAINT "Apparitions_plantId_fkey" FOREIGN KEY ("plantId") REFERENCES "Plants"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PhotoUrl" ADD CONSTRAINT "PhotoUrl_plantId_fkey" FOREIGN KEY ("plantId") REFERENCES "Plants"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PhotoUrl" ADD CONSTRAINT "PhotoUrl_animalId_fkey" FOREIGN KEY ("animalId") REFERENCES "Animals"("id") ON DELETE CASCADE ON UPDATE CASCADE;
