migration.sql 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. -- CreateEnum
  2. CREATE TYPE "ReqType" AS ENUM ('REST', 'GQL');
  3. -- CreateEnum
  4. CREATE TYPE "TeamMemberRole" AS ENUM ('OWNER', 'VIEWER', 'EDITOR');
  5. -- CreateTable
  6. CREATE TABLE "Team" (
  7. "id" TEXT NOT NULL,
  8. "name" TEXT NOT NULL,
  9. CONSTRAINT "Team_pkey" PRIMARY KEY ("id")
  10. );
  11. -- CreateTable
  12. CREATE TABLE "TeamMember" (
  13. "id" TEXT NOT NULL,
  14. "role" "TeamMemberRole" NOT NULL,
  15. "userUid" TEXT NOT NULL,
  16. "teamID" TEXT NOT NULL,
  17. CONSTRAINT "TeamMember_pkey" PRIMARY KEY ("id")
  18. );
  19. -- CreateTable
  20. CREATE TABLE "TeamInvitation" (
  21. "id" TEXT NOT NULL,
  22. "teamID" TEXT NOT NULL,
  23. "creatorUid" TEXT NOT NULL,
  24. "inviteeEmail" TEXT NOT NULL,
  25. "inviteeRole" "TeamMemberRole" NOT NULL,
  26. CONSTRAINT "TeamInvitation_pkey" PRIMARY KEY ("id")
  27. );
  28. -- CreateTable
  29. CREATE TABLE "TeamCollection" (
  30. "id" TEXT NOT NULL,
  31. "parentID" TEXT,
  32. "teamID" TEXT NOT NULL,
  33. "title" TEXT NOT NULL,
  34. "orderIndex" INTEGER NOT NULL,
  35. "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  36. "updatedOn" TIMESTAMP(3) NOT NULL,
  37. CONSTRAINT "TeamCollection_pkey" PRIMARY KEY ("id")
  38. );
  39. -- CreateTable
  40. CREATE TABLE "TeamRequest" (
  41. "id" TEXT NOT NULL,
  42. "collectionID" TEXT NOT NULL,
  43. "teamID" TEXT NOT NULL,
  44. "title" TEXT NOT NULL,
  45. "request" JSONB NOT NULL,
  46. "orderIndex" INTEGER NOT NULL,
  47. "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  48. "updatedOn" TIMESTAMP(3) NOT NULL,
  49. CONSTRAINT "TeamRequest_pkey" PRIMARY KEY ("id")
  50. );
  51. -- CreateTable
  52. CREATE TABLE "Shortcode" (
  53. "id" TEXT NOT NULL,
  54. "request" JSONB NOT NULL,
  55. "creatorUid" TEXT,
  56. "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  57. CONSTRAINT "Shortcode_pkey" PRIMARY KEY ("id")
  58. );
  59. -- CreateTable
  60. CREATE TABLE "TeamEnvironment" (
  61. "id" TEXT NOT NULL,
  62. "teamID" TEXT NOT NULL,
  63. "name" TEXT NOT NULL,
  64. "variables" JSONB NOT NULL,
  65. CONSTRAINT "TeamEnvironment_pkey" PRIMARY KEY ("id")
  66. );
  67. -- CreateTable
  68. CREATE TABLE "User" (
  69. "uid" TEXT NOT NULL,
  70. "displayName" TEXT,
  71. "email" TEXT,
  72. "photoURL" TEXT,
  73. "isAdmin" BOOLEAN NOT NULL DEFAULT false,
  74. "refreshToken" TEXT,
  75. "currentRESTSession" JSONB,
  76. "currentGQLSession" JSONB,
  77. "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  78. CONSTRAINT "User_pkey" PRIMARY KEY ("uid")
  79. );
  80. -- CreateTable
  81. CREATE TABLE "Account" (
  82. "id" TEXT NOT NULL,
  83. "userId" TEXT NOT NULL,
  84. "provider" TEXT NOT NULL,
  85. "providerAccountId" TEXT NOT NULL,
  86. "providerRefreshToken" TEXT,
  87. "providerAccessToken" TEXT,
  88. "providerScope" TEXT,
  89. "loggedIn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  90. CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
  91. );
  92. -- CreateTable
  93. CREATE TABLE "VerificationToken" (
  94. "deviceIdentifier" TEXT NOT NULL,
  95. "token" TEXT NOT NULL,
  96. "userUid" TEXT NOT NULL,
  97. "expiresOn" TIMESTAMP(3) NOT NULL
  98. );
  99. -- CreateTable
  100. CREATE TABLE "UserSettings" (
  101. "id" TEXT NOT NULL,
  102. "userUid" TEXT NOT NULL,
  103. "properties" JSONB NOT NULL,
  104. "updatedOn" TIMESTAMP(3) NOT NULL,
  105. CONSTRAINT "UserSettings_pkey" PRIMARY KEY ("id")
  106. );
  107. -- CreateTable
  108. CREATE TABLE "UserHistory" (
  109. "id" TEXT NOT NULL,
  110. "userUid" TEXT NOT NULL,
  111. "reqType" "ReqType" NOT NULL,
  112. "request" JSONB NOT NULL,
  113. "responseMetadata" JSONB NOT NULL,
  114. "isStarred" BOOLEAN NOT NULL,
  115. "executedOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  116. CONSTRAINT "UserHistory_pkey" PRIMARY KEY ("id")
  117. );
  118. -- CreateTable
  119. CREATE TABLE "UserEnvironment" (
  120. "id" TEXT NOT NULL,
  121. "userUid" TEXT NOT NULL,
  122. "name" TEXT,
  123. "variables" JSONB NOT NULL,
  124. "isGlobal" BOOLEAN NOT NULL,
  125. CONSTRAINT "UserEnvironment_pkey" PRIMARY KEY ("id")
  126. );
  127. -- CreateTable
  128. CREATE TABLE "InvitedUsers" (
  129. "adminUid" TEXT NOT NULL,
  130. "adminEmail" TEXT NOT NULL,
  131. "inviteeEmail" TEXT NOT NULL,
  132. "invitedOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
  133. );
  134. -- CreateTable
  135. CREATE TABLE "UserRequest" (
  136. "id" TEXT NOT NULL,
  137. "collectionID" TEXT NOT NULL,
  138. "userUid" TEXT NOT NULL,
  139. "title" TEXT NOT NULL,
  140. "request" JSONB NOT NULL,
  141. "type" "ReqType" NOT NULL,
  142. "orderIndex" INTEGER NOT NULL,
  143. "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  144. "updatedOn" TIMESTAMP(3) NOT NULL,
  145. CONSTRAINT "UserRequest_pkey" PRIMARY KEY ("id")
  146. );
  147. -- CreateTable
  148. CREATE TABLE "UserCollection" (
  149. "id" TEXT NOT NULL,
  150. "parentID" TEXT,
  151. "userUid" TEXT NOT NULL,
  152. "title" TEXT NOT NULL,
  153. "orderIndex" INTEGER NOT NULL,
  154. "type" "ReqType" NOT NULL,
  155. "createdOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  156. "updatedOn" TIMESTAMP(3) NOT NULL,
  157. CONSTRAINT "UserCollection_pkey" PRIMARY KEY ("id")
  158. );
  159. -- CreateIndex
  160. CREATE UNIQUE INDEX "TeamMember_teamID_userUid_key" ON "TeamMember"("teamID", "userUid");
  161. -- CreateIndex
  162. CREATE INDEX "TeamInvitation_teamID_idx" ON "TeamInvitation"("teamID");
  163. -- CreateIndex
  164. CREATE UNIQUE INDEX "TeamInvitation_teamID_inviteeEmail_key" ON "TeamInvitation"("teamID", "inviteeEmail");
  165. -- CreateIndex
  166. CREATE UNIQUE INDEX "Shortcode_id_creatorUid_key" ON "Shortcode"("id", "creatorUid");
  167. -- CreateIndex
  168. CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
  169. -- CreateIndex
  170. CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId");
  171. -- CreateIndex
  172. CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token");
  173. -- CreateIndex
  174. CREATE UNIQUE INDEX "VerificationToken_deviceIdentifier_token_key" ON "VerificationToken"("deviceIdentifier", "token");
  175. -- CreateIndex
  176. CREATE UNIQUE INDEX "UserSettings_userUid_key" ON "UserSettings"("userUid");
  177. -- CreateIndex
  178. CREATE UNIQUE INDEX "InvitedUsers_inviteeEmail_key" ON "InvitedUsers"("inviteeEmail");
  179. -- AddForeignKey
  180. ALTER TABLE "TeamMember" ADD CONSTRAINT "TeamMember_teamID_fkey" FOREIGN KEY ("teamID") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  181. -- AddForeignKey
  182. ALTER TABLE "TeamInvitation" ADD CONSTRAINT "TeamInvitation_teamID_fkey" FOREIGN KEY ("teamID") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  183. -- AddForeignKey
  184. ALTER TABLE "TeamCollection" ADD CONSTRAINT "TeamCollection_parentID_fkey" FOREIGN KEY ("parentID") REFERENCES "TeamCollection"("id") ON DELETE SET NULL ON UPDATE CASCADE;
  185. -- AddForeignKey
  186. ALTER TABLE "TeamCollection" ADD CONSTRAINT "TeamCollection_teamID_fkey" FOREIGN KEY ("teamID") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  187. -- AddForeignKey
  188. ALTER TABLE "TeamRequest" ADD CONSTRAINT "TeamRequest_collectionID_fkey" FOREIGN KEY ("collectionID") REFERENCES "TeamCollection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  189. -- AddForeignKey
  190. ALTER TABLE "TeamRequest" ADD CONSTRAINT "TeamRequest_teamID_fkey" FOREIGN KEY ("teamID") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  191. -- AddForeignKey
  192. ALTER TABLE "TeamEnvironment" ADD CONSTRAINT "TeamEnvironment_teamID_fkey" FOREIGN KEY ("teamID") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  193. -- AddForeignKey
  194. ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  195. -- AddForeignKey
  196. ALTER TABLE "VerificationToken" ADD CONSTRAINT "VerificationToken_userUid_fkey" FOREIGN KEY ("userUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  197. -- AddForeignKey
  198. ALTER TABLE "UserSettings" ADD CONSTRAINT "UserSettings_userUid_fkey" FOREIGN KEY ("userUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  199. -- AddForeignKey
  200. ALTER TABLE "UserHistory" ADD CONSTRAINT "UserHistory_userUid_fkey" FOREIGN KEY ("userUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  201. -- AddForeignKey
  202. ALTER TABLE "UserEnvironment" ADD CONSTRAINT "UserEnvironment_userUid_fkey" FOREIGN KEY ("userUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  203. -- AddForeignKey
  204. ALTER TABLE "InvitedUsers" ADD CONSTRAINT "InvitedUsers_adminUid_fkey" FOREIGN KEY ("adminUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  205. -- AddForeignKey
  206. ALTER TABLE "UserRequest" ADD CONSTRAINT "UserRequest_collectionID_fkey" FOREIGN KEY ("collectionID") REFERENCES "UserCollection"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
  207. -- AddForeignKey
  208. ALTER TABLE "UserRequest" ADD CONSTRAINT "UserRequest_userUid_fkey" FOREIGN KEY ("userUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;
  209. -- AddForeignKey
  210. ALTER TABLE "UserCollection" ADD CONSTRAINT "UserCollection_parentID_fkey" FOREIGN KEY ("parentID") REFERENCES "UserCollection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
  211. -- AddForeignKey
  212. ALTER TABLE "UserCollection" ADD CONSTRAINT "UserCollection_userUid_fkey" FOREIGN KEY ("userUid") REFERENCES "User"("uid") ON DELETE CASCADE ON UPDATE CASCADE;