/*
  Warnings:

  - The primary key for the `nursery_plant_inventory` table will be changed. If it partially fails, the table could be left without primary key constraint.
  - You are about to drop the column `nursery_stock_id` on the `nursery_plant_inventory` table. All the data in the column will be lost.
  - You are about to drop the column `species_id` on the `nursery_plant_inventory` table. All the data in the column will be lost.
  - You are about to drop the column `species_id` on the `request` table. All the data in the column will be lost.
  - Added the required column `specie_id` to the `nursery_plant_inventory` table without a default value. This is not possible if the table is not empty.
  - Added the required column `specie_id` to the `request` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "nursery_plant_inventory" DROP CONSTRAINT "nursery_plant_inventory_nursery_id_fkey";

-- DropForeignKey
ALTER TABLE "nursery_plant_inventory" DROP CONSTRAINT "nursery_plant_inventory_species_id_fkey";

-- DropForeignKey
ALTER TABLE "request" DROP CONSTRAINT "request_species_id_fkey";

-- AlterTable
ALTER TABLE "nursery_plant_inventory" DROP CONSTRAINT "nursery_plant_inventory_pkey",
DROP COLUMN "nursery_stock_id",
DROP COLUMN "species_id",
ADD COLUMN     "id" SERIAL NOT NULL,
ADD COLUMN     "specie_id" INTEGER NOT NULL,
ADD CONSTRAINT "nursery_plant_inventory_pkey" PRIMARY KEY ("id");

-- AlterTable
ALTER TABLE "request" DROP COLUMN "species_id",
ADD COLUMN     "specie_id" INTEGER NOT NULL;

-- CreateTable
CREATE TABLE "nursery" (
    "id" TEXT NOT NULL,
    "company_id" TEXT NOT NULL,

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

-- AddForeignKey
ALTER TABLE "nursery" ADD CONSTRAINT "nursery_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "company"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "nursery_plant_inventory" ADD CONSTRAINT "nursery_plant_inventory_nursery_id_fkey" FOREIGN KEY ("nursery_id") REFERENCES "nursery"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "nursery_plant_inventory" ADD CONSTRAINT "nursery_plant_inventory_specie_id_fkey" FOREIGN KEY ("specie_id") REFERENCES "species"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "request" ADD CONSTRAINT "request_specie_id_fkey" FOREIGN KEY ("specie_id") REFERENCES "species"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
