--- template/app/migrations/20240702143707_update_user_entity/migration.sql +++ opensaas-sh/app/migrations/20240702143707_update_user_entity/migration.sql @@ -0,0 +1,65 @@ +/* + Warnings: + + - The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. + - A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail. + - A unique constraint covering the columns `[username]` on the table `User` will be added. If there are existing duplicate values, this will fail. + +*/ +-- DropForeignKey +ALTER TABLE "Auth" DROP CONSTRAINT "Auth_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "ContactFormMessage" DROP CONSTRAINT "ContactFormMessage_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "File" DROP CONSTRAINT "File_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "GptResponse" DROP CONSTRAINT "GptResponse_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "Task" DROP CONSTRAINT "Task_userId_fkey"; + +-- AlterTable +ALTER TABLE "Auth" ALTER COLUMN "userId" SET DATA TYPE TEXT; + +-- AlterTable +ALTER TABLE "ContactFormMessage" ALTER COLUMN "userId" SET DATA TYPE TEXT; + +-- AlterTable +ALTER TABLE "File" ALTER COLUMN "userId" SET DATA TYPE TEXT; + +-- AlterTable +ALTER TABLE "GptResponse" ALTER COLUMN "userId" SET DATA TYPE TEXT; + +-- AlterTable +ALTER TABLE "Task" ALTER COLUMN "userId" SET DATA TYPE TEXT; + +-- AlterTable +ALTER TABLE "User" DROP CONSTRAINT "User_pkey", +ALTER COLUMN "id" DROP DEFAULT, +ALTER COLUMN "id" SET DATA TYPE TEXT, +ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id"); +DROP SEQUENCE "User_id_seq"; + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); + +-- AddForeignKey +ALTER TABLE "GptResponse" ADD CONSTRAINT "GptResponse_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Task" ADD CONSTRAINT "Task_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "File" ADD CONSTRAINT "File_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "ContactFormMessage" ADD CONSTRAINT "ContactFormMessage_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Auth" ADD CONSTRAINT "Auth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;