/*
  Warnings:

  - You are about to drop the column `userID` on the `kml_record` table. All the data in the column will be lost.
  - Added the required column `FarmID` to the `kml_record` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "kml_record" DROP CONSTRAINT "kml_record_userID_fkey";

-- AlterTable
ALTER TABLE "kml_record" DROP COLUMN "userID",
ADD COLUMN     "FarmID" INTEGER NOT NULL;

-- CreateTable
CREATE TABLE "farm_data" (
    "id" SERIAL NOT NULL,
    "landAreaAcres" DOUBLE PRECISION NOT NULL,
    "landStatus" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "farm_crops" (
    "id" SERIAL NOT NULL,
    "farmId" INTEGER NOT NULL,
    "crop" TEXT NOT NULL,
    "sowingDate" TIMESTAMP(3) NOT NULL,
    "harvestDate" TIMESTAMP(3) NOT NULL,
    "areaSownAcres" DOUBLE PRECISION NOT NULL,
    "yieldPerAcre" DOUBLE PRECISION NOT NULL,
    "fertilizerBags" INTEGER NOT NULL,
    "pesticideApps" INTEGER NOT NULL,
    "hasSoilReport" BOOLEAN NOT NULL,

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

-- CreateTable
CREATE TABLE "farm_irrigation" (
    "id" SERIAL NOT NULL,
    "farmId" INTEGER NOT NULL,
    "irrigationType" TEXT NOT NULL,

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

-- AddForeignKey
ALTER TABLE "kml_record" ADD CONSTRAINT "kml_record_FarmID_fkey" FOREIGN KEY ("FarmID") REFERENCES "farm_data"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "farm_crops" ADD CONSTRAINT "farm_crops_farmId_fkey" FOREIGN KEY ("farmId") REFERENCES "farm_data"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "farm_irrigation" ADD CONSTRAINT "farm_irrigation_farmId_fkey" FOREIGN KEY ("farmId") REFERENCES "farm_data"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
