-- CreateTable CREATE TABLE "Dataset" ( "id" SERIAL NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3) NOT NULL, "rootCid" TEXT NOT NULL, "size" INTEGER NOT NULL, "userId" INTEGER NOT NULL, CONSTRAINT "Dataset_pkey" PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "DataReference" ( "id" SERIAL NOT NULL, "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMP(3) NOT NULL, "cid" TEXT NOT NULL, "size" INTEGER NOT NULL, "userId" INTEGER NOT NULL, "datasetId" INTEGER, CONSTRAINT "DataReference_pkey" PRIMARY KEY ("id") ); -- AddForeignKey ALTER TABLE "Dataset" ADD CONSTRAINT "Dataset_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "DataReference" ADD CONSTRAINT "DataReference_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "DataReference" ADD CONSTRAINT "DataReference_datasetId_fkey" FOREIGN KEY ("datasetId") REFERENCES "Dataset"("id") ON DELETE SET NULL ON UPDATE CASCADE;