-- CreateEnum
CREATE TYPE "StakeholderType" AS ENUM ('MINISTRY', 'PRIVATE_SECTOR');

-- AlterTable
ALTER TABLE "users" ADD COLUMN     "avatar" TEXT,
ADD COLUMN     "position" TEXT;

-- CreateTable
CREATE TABLE "stakeholders" (
    "id" SERIAL NOT NULL,
    "logo" TEXT,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "type" "StakeholderType" NOT NULL,
    "active" BOOLEAN NOT NULL DEFAULT true,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,
    "deleted_at" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "stakeholder_users" (
    "id" SERIAL NOT NULL,
    "user_id" INTEGER NOT NULL,
    "stakeholder_id" INTEGER NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "stakeholder_users_user_id_idx" ON "stakeholder_users"("user_id");

-- CreateIndex
CREATE INDEX "stakeholder_users_stakeholder_id_idx" ON "stakeholder_users"("stakeholder_id");

-- CreateIndex
CREATE UNIQUE INDEX "stakeholder_users_user_id_stakeholder_id_key" ON "stakeholder_users"("user_id", "stakeholder_id");

-- AddForeignKey
ALTER TABLE "stakeholder_users" ADD CONSTRAINT "stakeholder_users_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "stakeholder_users" ADD CONSTRAINT "stakeholder_users_stakeholder_id_fkey" FOREIGN KEY ("stakeholder_id") REFERENCES "stakeholders"("id") ON DELETE CASCADE ON UPDATE CASCADE;
