-- DropForeignKey
ALTER TABLE "users" DROP CONSTRAINT "users_contact_uid_fkey";

-- DropForeignKey
ALTER TABLE "users" DROP CONSTRAINT "users_office_role_uid_fkey";

-- DropForeignKey
ALTER TABLE "users" DROP CONSTRAINT "users_office_uid_fkey";

-- DropForeignKey
ALTER TABLE "users" DROP CONSTRAINT "users_roles_uid_fkey";

-- CreateTable
CREATE TABLE "email" (
    "uid" TEXT NOT NULL,
    "templateName" VARCHAR(255) NOT NULL,
    "from" VARCHAR(255),
    "to" VARCHAR(255) NOT NULL,
    "subject" VARCHAR(255) NOT NULL,
    "templateVariables" JSON NOT NULL DEFAULT '{}',
    "cc" VARCHAR(255)[],
    "cci" VARCHAR(255)[],
    "sentAt" TIMESTAMP(3),
    "nbTrySend" INTEGER DEFAULT 0,
    "lastTrySendDate" TIMESTAMP(3),

    CONSTRAINT "email_pkey" PRIMARY KEY ("uid")
);

-- CreateIndex
CREATE UNIQUE INDEX "email_uid_key" ON "email"("uid");

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_contact_uid_fkey" FOREIGN KEY ("contact_uid") REFERENCES "contacts"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_roles_uid_fkey" FOREIGN KEY ("roles_uid") REFERENCES "roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_office_role_uid_fkey" FOREIGN KEY ("office_role_uid") REFERENCES "office_roles"("uid") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_office_uid_fkey" FOREIGN KEY ("office_uid") REFERENCES "offices"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
