-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration.sql
More file actions
90 lines (69 loc) · 3.11 KB
/
Copy pathmigration.sql
File metadata and controls
90 lines (69 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
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 `[name,age]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- Added the required column `age` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `email` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `isadmin` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- CreateEnum
CREATE TYPE "role" AS ENUM ('BASIC', 'ADMIN');
-- AlterTable
ALTER TABLE "User" DROP CONSTRAINT "User_pkey",
ADD COLUMN "age" INTEGER NOT NULL,
ADD COLUMN "email" TEXT NOT NULL,
ADD COLUMN "isadmin" BOOLEAN NOT NULL,
ALTER COLUMN "id" DROP DEFAULT,
ALTER COLUMN "id" SET DATA TYPE TEXT,
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id");
DROP SEQUENCE "User_id_seq";
-- CreateTable
CREATE TABLE "Userpreference" (
"id" TEXT NOT NULL,
"emailupdates" BOOLEAN NOT NULL,
"userId" TEXT NOT NULL,
CONSTRAINT "Userpreference_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Post" (
"id" TEXT NOT NULL,
"avgrating" DOUBLE PRECISION NOT NULL,
"createdat" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedat" TIMESTAMP(3) NOT NULL,
"sno" INTEGER NOT NULL,
"authorId" TEXT NOT NULL,
"favoritedbyId" TEXT,
CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "category" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "category_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "_PostTocategory" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,
CONSTRAINT "_PostTocategory_AB_pkey" PRIMARY KEY ("A","B")
);
-- CreateIndex
CREATE UNIQUE INDEX "Userpreference_userId_key" ON "Userpreference"("userId");
-- CreateIndex
CREATE UNIQUE INDEX "category_name_key" ON "category"("name");
-- CreateIndex
CREATE INDEX "_PostTocategory_B_index" ON "_PostTocategory"("B");
-- CreateIndex
CREATE INDEX "User_email_idx" ON "User"("email");
-- CreateIndex
CREATE UNIQUE INDEX "User_name_age_key" ON "User"("name", "age");
-- AddForeignKey
ALTER TABLE "Userpreference" ADD CONSTRAINT "Userpreference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Post" ADD CONSTRAINT "Post_favoritedbyId_fkey" FOREIGN KEY ("favoritedbyId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_PostTocategory" ADD CONSTRAINT "_PostTocategory_A_fkey" FOREIGN KEY ("A") REFERENCES "Post"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "_PostTocategory" ADD CONSTRAINT "_PostTocategory_B_fkey" FOREIGN KEY ("B") REFERENCES "category"("id") ON DELETE CASCADE ON UPDATE CASCADE;