mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-28 00:06:27 +02:00
♻️ Switch to turborepo (#532)
This commit is contained in:
parent
41ef81aa75
commit
0a836aeec7
419 changed files with 2300 additions and 2504 deletions
|
@ -0,0 +1,94 @@
|
|||
-- CreateEnum
|
||||
CREATE TYPE "PollType" AS ENUM ('date');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Poll" (
|
||||
"urlId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
"deadline" TIMESTAMP(3),
|
||||
"title" TEXT NOT NULL,
|
||||
"type" "PollType" NOT NULL,
|
||||
"description" TEXT,
|
||||
"location" TEXT,
|
||||
"userId" TEXT NOT NULL,
|
||||
"verificationCode" TEXT NOT NULL,
|
||||
"timeZone" TEXT,
|
||||
"verified" BOOLEAN NOT NULL DEFAULT false,
|
||||
"authorName" TEXT NOT NULL DEFAULT E'',
|
||||
"demo" BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
CONSTRAINT "Poll_pkey" PRIMARY KEY ("urlId")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Participant" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"userId" TEXT,
|
||||
"pollId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Participant_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Option" (
|
||||
"id" TEXT NOT NULL,
|
||||
"value" TEXT NOT NULL,
|
||||
"pollId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "Option_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Vote" (
|
||||
"id" TEXT NOT NULL,
|
||||
"participantId" TEXT NOT NULL,
|
||||
"optionId" TEXT NOT NULL,
|
||||
"pollId" TEXT NOT NULL,
|
||||
|
||||
CONSTRAINT "Vote_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Poll_urlId_key" ON "Poll"("urlId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Poll_urlId_verificationCode_key" ON "Poll"("urlId", "verificationCode");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Participant_id_pollId_key" ON "Participant"("id", "pollId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Poll" ADD CONSTRAINT "Poll_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Participant" ADD CONSTRAINT "Participant_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Participant" ADD CONSTRAINT "Participant_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Option" ADD CONSTRAINT "Option_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_participantId_fkey" FOREIGN KEY ("participantId") REFERENCES "Participant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_optionId_fkey" FOREIGN KEY ("optionId") REFERENCES "Option"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,20 @@
|
|||
-- CreateTable
|
||||
CREATE TABLE "Comment" (
|
||||
"id" TEXT NOT NULL,
|
||||
"content" TEXT NOT NULL,
|
||||
"pollId" TEXT NOT NULL,
|
||||
"authorName" TEXT NOT NULL,
|
||||
"userId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Comment_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Comment_id_pollId_key" ON "Comment"("id", "pollId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,47 @@
|
|||
-- Create nanoid function
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
|
||||
CREATE OR REPLACE FUNCTION nanoid(size int DEFAULT 21)
|
||||
RETURNS text AS $$
|
||||
DECLARE
|
||||
id text := '';
|
||||
i int := 0;
|
||||
urlAlphabet char(64) := 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW';
|
||||
bytes bytea := gen_random_bytes(size);
|
||||
byte int;
|
||||
pos int;
|
||||
BEGIN
|
||||
WHILE i < size LOOP
|
||||
byte := get_byte(bytes, i);
|
||||
pos := (byte & 63) + 1; -- + 1 because substr starts at 1 for some reason
|
||||
id := id || substr(urlAlphabet, pos, 1);
|
||||
i = i + 1;
|
||||
END LOOP;
|
||||
RETURN id;
|
||||
END
|
||||
$$ LANGUAGE PLPGSQL STABLE;
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "Role" AS ENUM ('admin', 'participant');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Link" (
|
||||
"urlId" TEXT NOT NULL,
|
||||
"role" "Role" NOT NULL,
|
||||
"pollId" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "Link_pkey" PRIMARY KEY ("urlId")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Link_urlId_key" ON "Link"("urlId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Link_pollId_role_key" ON "Link"("pollId", "role");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Link" ADD CONSTRAINT "Link_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
INSERT INTO "Link" ("urlId", "pollId", "role") SELECT "urlId", "urlId", 'admin' as "role" FROM "Poll";
|
||||
INSERT INTO "Link" ("urlId", "pollId", "role") SELECT nanoid(), "urlId", 'participant' as "role" FROM "Poll";
|
|
@ -0,0 +1,2 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "Poll" ADD COLUMN "notifications" BOOLEAN NOT NULL DEFAULT false;
|
|
@ -0,0 +1,3 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "Poll" ADD COLUMN "closed" BOOLEAN NOT NULL DEFAULT false,
|
||||
ADD COLUMN "legacy" BOOLEAN NOT NULL DEFAULT false;
|
|
@ -0,0 +1,17 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_pollId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Link" DROP CONSTRAINT "Link_pollId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Option" DROP CONSTRAINT "Option_pollId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Link" ADD CONSTRAINT "Link_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Option" ADD CONSTRAINT "Option_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,5 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "Participant" DROP CONSTRAINT "Participant_pollId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Participant" ADD CONSTRAINT "Participant_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,5 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "Vote" DROP CONSTRAINT "Vote_pollId_fkey";
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_pollId_fkey" FOREIGN KEY ("pollId") REFERENCES "Poll"("urlId") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,43 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "Comment" ADD COLUMN "updatedAt" TIMESTAMP(3);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Option" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "updatedAt" TIMESTAMP(3);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Participant" ADD COLUMN "updatedAt" TIMESTAMP(3);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "updatedAt" TIMESTAMP(3);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Vote" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
ADD COLUMN "updatedAt" TIMESTAMP(3);
|
||||
|
||||
-- We need to get rid of duplicate email addresses in the users table
|
||||
-- because the index was previously case sensitive
|
||||
|
||||
-- First we update all polls created by users with a duplicate email address
|
||||
-- to a single user
|
||||
UPDATE "Poll" p SET "userId" = u.id
|
||||
FROM (
|
||||
SELECT min(id) id, array_agg(id) as "userIds"
|
||||
FROM "User" u
|
||||
GROUP BY lower(email)
|
||||
HAVING count(*) > 1
|
||||
) u
|
||||
WHERE p."userId" = any(u."userIds")
|
||||
AND p."userId" <> u.id;
|
||||
|
||||
-- Remove all users that do not have polls
|
||||
DELETE FROM "User" u
|
||||
WHERE NOT EXISTS (SELECT * FROM "Poll" p WHERE u.id = p."userId");
|
||||
|
||||
-- Add citext extension
|
||||
CREATE EXTENSION IF NOT EXISTS citext;
|
||||
|
||||
-- Change email to citext
|
||||
ALTER TABLE "User"
|
||||
ALTER COLUMN email TYPE citext;
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `verificationCode` on the `Poll` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "Poll_urlId_verificationCode_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Comment" ADD COLUMN "guestId" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Participant" ADD COLUMN "guestId" TEXT;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Poll" DROP COLUMN "verificationCode";
|
|
@ -0,0 +1,5 @@
|
|||
-- CreateEnum
|
||||
CREATE TYPE "VoteType" AS ENUM ('yes', 'no', 'ifNeedBe');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Vote" ADD COLUMN "type" "VoteType" NOT NULL DEFAULT E'yes';
|
|
@ -0,0 +1,173 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_pollId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Link" DROP CONSTRAINT "Link_pollId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Option" DROP CONSTRAINT "Option_pollId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Participant" DROP CONSTRAINT "Participant_pollId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Participant" DROP CONSTRAINT "Participant_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Poll" DROP CONSTRAINT "Poll_userId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Vote" DROP CONSTRAINT "Vote_optionId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Vote" DROP CONSTRAINT "Vote_participantId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Vote" DROP CONSTRAINT "Vote_pollId_fkey";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "Comment" RENAME TO "comments";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "Link" RENAME TO "links";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "Option" RENAME TO "options";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "Participant" RENAME TO "participants";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "Poll" RENAME TO "polls";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "User" RENAME TO "users";
|
||||
|
||||
-- Rename table
|
||||
ALTER TABLE "Vote" RENAME TO "votes";
|
||||
|
||||
-- Rename enum
|
||||
ALTER TYPE "PollType" RENAME TO "poll_type";
|
||||
|
||||
-- Rename enum
|
||||
ALTER TYPE "Role" RENAME TO "role";
|
||||
|
||||
-- Rename enum
|
||||
ALTER TYPE "VoteType" RENAME TO "vote_type";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "comments" RENAME COLUMN "authorName" TO "author_name";
|
||||
ALTER TABLE "comments" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "comments" RENAME COLUMN "guestId" TO "guest_id";
|
||||
ALTER TABLE "comments" RENAME COLUMN "pollId" TO "poll_id";
|
||||
ALTER TABLE "comments" RENAME COLUMN "updatedAt" TO "updated_at";
|
||||
ALTER TABLE "comments" RENAME COLUMN "userId" TO "user_id";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "links" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "links" RENAME COLUMN "pollId" TO "poll_id";
|
||||
ALTER TABLE "links" RENAME COLUMN "urlId" TO "url_id";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "options" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "options" RENAME COLUMN "pollId" TO "poll_id";
|
||||
ALTER TABLE "options" RENAME COLUMN "updatedAt" TO "updated_at";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "participants" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "participants" RENAME COLUMN "guestId" TO "guest_id";
|
||||
ALTER TABLE "participants" RENAME COLUMN "pollId" TO "poll_id";
|
||||
ALTER TABLE "participants" RENAME COLUMN "updatedAt" TO "updated_at";
|
||||
ALTER TABLE "participants" RENAME COLUMN "userId" TO "user_id";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "polls" RENAME COLUMN "authorName" TO "author_name";
|
||||
ALTER TABLE "polls" RENAME COLUMN "userId" TO "user_id";
|
||||
ALTER TABLE "polls" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "polls" RENAME COLUMN "timeZone" TO "time_zone";
|
||||
ALTER TABLE "polls" RENAME COLUMN "updatedAt" TO "updated_at";
|
||||
ALTER TABLE "polls" RENAME COLUMN "urlId" TO "url_id";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "users" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "users" RENAME COLUMN "updatedAt" TO "updated_at";
|
||||
|
||||
-- Rename fields
|
||||
ALTER TABLE "votes" RENAME COLUMN "createdAt" TO "created_at";
|
||||
ALTER TABLE "votes" RENAME COLUMN "optionId" TO "option_id";
|
||||
ALTER TABLE "votes" RENAME COLUMN "participantId" TO "participant_id";
|
||||
ALTER TABLE "votes" RENAME COLUMN "pollId" TO "poll_id";
|
||||
ALTER TABLE "votes" RENAME COLUMN "updatedAt" TO "updated_at";
|
||||
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "polls_url_id_key" ON "polls"("url_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "links_url_id_key" ON "links"("url_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "links_poll_id_role_key" ON "links"("poll_id", "role");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "participants_id_poll_id_key" ON "participants"("id", "poll_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "comments_id_poll_id_key" ON "comments"("id", "poll_id");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "polls" ADD CONSTRAINT "polls_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "links" ADD CONSTRAINT "links_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "options" ADD CONSTRAINT "options_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_participant_id_fkey" FOREIGN KEY ("participant_id") REFERENCES "participants"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_option_id_fkey" FOREIGN KEY ("option_id") REFERENCES "options"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "comments" RENAME CONSTRAINT "Comment_pkey" TO "comments_pkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "links" RENAME CONSTRAINT "Link_pkey" TO "links_pkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "options" RENAME CONSTRAINT "Option_pkey" TO "options_pkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "participants" RENAME CONSTRAINT "Participant_pkey" TO "participants_pkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "polls" RENAME CONSTRAINT "Poll_pkey" TO "polls_pkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" RENAME CONSTRAINT "User_pkey" TO "users_pkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "votes" RENAME CONSTRAINT "Vote_pkey" TO "votes_pkey";
|
|
@ -0,0 +1,13 @@
|
|||
-- Previously we only stored "yes" and "ifNeedBe" votes and assumed missing votes are "no"
|
||||
-- Since we want to differentiate between "no" and did not vote yet we want to include "no" votes
|
||||
-- in this table
|
||||
INSERT INTO votes (id, poll_id, participant_id, option_id, type)
|
||||
SELECT nanoid(), poll_id, participant_id, option_id, 'no'
|
||||
FROM (
|
||||
SELECT o.poll_id, p.id participant_id, o.id option_id
|
||||
FROM options o
|
||||
JOIN participants p ON o.poll_id = p.poll_id
|
||||
EXCEPT
|
||||
SELECT poll_id, participant_id, option_id
|
||||
FROM votes
|
||||
) AS missing;
|
|
@ -0,0 +1,44 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "links" DROP CONSTRAINT "links_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "options" DROP CONSTRAINT "options_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "participants" DROP CONSTRAINT "participants_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_option_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_participant_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_poll_id_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "polls" ADD COLUMN "deleted" BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "links" ADD CONSTRAINT "links_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "participants" ADD CONSTRAINT "participants_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "options" ADD CONSTRAINT "options_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_participant_id_fkey" FOREIGN KEY ("participant_id") REFERENCES "participants"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "votes" ADD CONSTRAINT "votes_option_id_fkey" FOREIGN KEY ("option_id") REFERENCES "options"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "comments" ADD CONSTRAINT "comments_poll_id_fkey" FOREIGN KEY ("poll_id") REFERENCES "polls"("url_id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,2 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "polls" ADD COLUMN "touched_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
|
@ -0,0 +1,29 @@
|
|||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "comments" DROP CONSTRAINT "comments_user_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "links" DROP CONSTRAINT "links_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "options" DROP CONSTRAINT "options_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "participants" DROP CONSTRAINT "participants_poll_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "participants" DROP CONSTRAINT "participants_user_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "polls" DROP CONSTRAINT "polls_user_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_option_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_participant_id_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "votes" DROP CONSTRAINT "votes_poll_id_fkey";
|
|
@ -0,0 +1,4 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "polls" ADD COLUMN "deleted_at" TIMESTAMP(3);
|
||||
|
||||
UPDATE "polls" SET "deleted_at" = now() WHERE "deleted" = true;
|
|
@ -0,0 +1,26 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "polls"
|
||||
ADD COLUMN "admin_url_id" TEXT,
|
||||
ADD COLUMN "participant_url_id" TEXT;
|
||||
|
||||
UPDATE polls
|
||||
SET participant_url_id=(SELECT url_id FROM links WHERE polls.url_id=links.poll_id AND links."role"='participant');
|
||||
|
||||
UPDATE polls
|
||||
SET admin_url_id=(SELECT url_id FROM links WHERE polls.url_id=links.poll_id AND links."role"='admin');
|
||||
|
||||
ALTER TABLE "polls"
|
||||
ALTER COLUMN "admin_url_id" SET NOT NULL,
|
||||
ALTER COLUMN "participant_url_id" SET NOT NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "links";
|
||||
|
||||
-- DropEnum
|
||||
DROP TYPE "role";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "polls_participant_url_id_key" ON "polls"("participant_url_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "polls_admin_url_id_key" ON "polls"("admin_url_id");
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- The primary key for the `polls` table will be changed. If it partially fails, the table could be left without primary key constraint.
|
||||
- You are about to drop the column `url_id` on the `polls` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[id]` on the table `polls` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `id` to the `polls` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX "Poll_urlId_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "polls_url_id_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "polls"
|
||||
RENAME COLUMN "url_id" TO "id";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "polls_id_key" ON "polls"("id");
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `guest_id` on the `comments` table. All the data in the column will be lost.
|
||||
- You are about to drop the column `guest_id` on the `participants` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- Set user_id to guest_id
|
||||
UPDATE "comments"
|
||||
SET "user_id" = "guest_id"
|
||||
WHERE "user_id" IS NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "comments" DROP COLUMN "guest_id";
|
||||
|
||||
-- Set user_id to guest_id
|
||||
UPDATE "participants"
|
||||
SET "user_id" = "guest_id"
|
||||
WHERE "user_id" IS NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "participants" DROP COLUMN "guest_id";
|
|
@ -0,0 +1,5 @@
|
|||
-- CreateIndex
|
||||
CREATE INDEX "participants_poll_id_idx" ON "participants" USING HASH ("poll_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "votes_participant_id_idx" ON "votes" USING HASH ("participant_id");
|
|
@ -0,0 +1,17 @@
|
|||
-- DropIndex
|
||||
DROP INDEX "Participant_id_pollId_key";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "participants_id_poll_id_key";
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "comments_poll_id_idx" ON "comments" USING HASH ("poll_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "options_poll_id_idx" ON "options" USING HASH ("poll_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "polls_user_id_idx" ON "polls" USING HASH ("user_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "votes_poll_id_idx" ON "votes" USING HASH ("poll_id");
|
|
@ -0,0 +1,2 @@
|
|||
-- CreateIndex
|
||||
CREATE INDEX "comments_user_id_idx" ON "comments" USING HASH ("user_id");
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[id,poll_id]` on the table `participants` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "participants_id_poll_id_key" ON "participants"("id", "poll_id");
|
3
packages/database/prisma/migrations/migration_lock.toml
Normal file
3
packages/database/prisma/migrations/migration_lock.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "postgresql"
|
Loading…
Add table
Add a link
Reference in a new issue