diff --git a/prisma/dev.db b/prisma/dev.db new file mode 100644 index 0000000..561bcac Binary files /dev/null and b/prisma/dev.db differ diff --git a/prisma/migrations/20240611084041_init/migration.sql b/prisma/migrations/20240611084041_init/migration.sql new file mode 100644 index 0000000..a0542fa --- /dev/null +++ b/prisma/migrations/20240611084041_init/migration.sql @@ -0,0 +1,28 @@ +-- CreateTable +CREATE TABLE "Story" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "word_count" INTEGER NOT NULL, + "title" TEXT NOT NULL, + "deleted" INTEGER NOT NULL +); + +-- CreateTable +CREATE TABLE "Pub" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "title" TEXT NOT NULL, + "link" TEXT NOT NULL, + "query_after_days" INTEGER NOT NULL, + "deleted" INTEGER NOT NULL +); + +-- CreateTable +CREATE TABLE "Genre" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "Response" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "response" TEXT NOT NULL +); diff --git a/prisma/migrations/20240611085835_init/migration.sql b/prisma/migrations/20240611085835_init/migration.sql new file mode 100644 index 0000000..4a33710 --- /dev/null +++ b/prisma/migrations/20240611085835_init/migration.sql @@ -0,0 +1,30 @@ +-- CreateTable +CREATE TABLE "Sub" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "storyId" INTEGER NOT NULL, + "pubId" INTEGER NOT NULL, + "submitted" TEXT NOT NULL, + "responded" TEXT NOT NULL, + "responseId" INTEGER NOT NULL, + CONSTRAINT "Sub_storyId_fkey" FOREIGN KEY ("storyId") REFERENCES "Story" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Sub_pubId_fkey" FOREIGN KEY ("pubId") REFERENCES "Pub" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "Sub_responseId_fkey" FOREIGN KEY ("responseId") REFERENCES "Response" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "PubsGenres" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "pubId" INTEGER NOT NULL, + "genreId" INTEGER NOT NULL, + CONSTRAINT "PubsGenres_pubId_fkey" FOREIGN KEY ("pubId") REFERENCES "Pub" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "PubsGenres_genreId_fkey" FOREIGN KEY ("genreId") REFERENCES "Genre" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "StoriesGenres" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "storyId" INTEGER NOT NULL, + "genreId" INTEGER NOT NULL, + CONSTRAINT "StoriesGenres_storyId_fkey" FOREIGN KEY ("storyId") REFERENCES "Story" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, + CONSTRAINT "StoriesGenres_genreId_fkey" FOREIGN KEY ("genreId") REFERENCES "Genre" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); diff --git a/prisma/migrations/20240611095254_init/migration.sql b/prisma/migrations/20240611095254_init/migration.sql new file mode 100644 index 0000000..b43ac6f --- /dev/null +++ b/prisma/migrations/20240611095254_init/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the `PubsGenres` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `StoriesGenres` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +PRAGMA foreign_keys=off; +DROP TABLE "PubsGenres"; +PRAGMA foreign_keys=on; + +-- DropTable +PRAGMA foreign_keys=off; +DROP TABLE "StoriesGenres"; +PRAGMA foreign_keys=on; diff --git a/prisma/migrations/20240611095640_init/migration.sql b/prisma/migrations/20240611095640_init/migration.sql new file mode 100644 index 0000000..8da8e4d --- /dev/null +++ b/prisma/migrations/20240611095640_init/migration.sql @@ -0,0 +1,16 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Genre" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT NOT NULL, + "storyId" INTEGER, + "pubId" INTEGER, + CONSTRAINT "Genre_storyId_fkey" FOREIGN KEY ("storyId") REFERENCES "Story" ("id") ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT "Genre_pubId_fkey" FOREIGN KEY ("pubId") REFERENCES "Pub" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); +INSERT INTO "new_Genre" ("id", "name") SELECT "id", "name" FROM "Genre"; +DROP TABLE "Genre"; +ALTER TABLE "new_Genre" RENAME TO "Genre"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/20240611100117_init/migration.sql b/prisma/migrations/20240611100117_init/migration.sql new file mode 100644 index 0000000..3359c40 --- /dev/null +++ b/prisma/migrations/20240611100117_init/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - A unique constraint covering the columns `[name]` on the table `Genre` will be added. If there are existing duplicate values, this will fail. + +*/ +-- CreateIndex +CREATE UNIQUE INDEX "Genre_name_key" ON "Genre"("name"); diff --git a/prisma/migrations/20240611101409_init/migration.sql b/prisma/migrations/20240611101409_init/migration.sql new file mode 100644 index 0000000..1be32db --- /dev/null +++ b/prisma/migrations/20240611101409_init/migration.sql @@ -0,0 +1,48 @@ +/* + Warnings: + + - You are about to drop the column `pubId` on the `Genre` table. All the data in the column will be lost. + - You are about to drop the column `storyId` on the `Genre` table. All the data in the column will be lost. + +*/ +-- CreateTable +CREATE TABLE "_GenreToStory" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL, + CONSTRAINT "_GenreToStory_A_fkey" FOREIGN KEY ("A") REFERENCES "Genre" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "_GenreToStory_B_fkey" FOREIGN KEY ("B") REFERENCES "Story" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "_GenreToPub" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL, + CONSTRAINT "_GenreToPub_A_fkey" FOREIGN KEY ("A") REFERENCES "Genre" ("id") ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT "_GenreToPub_B_fkey" FOREIGN KEY ("B") REFERENCES "Pub" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Genre" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT NOT NULL +); +INSERT INTO "new_Genre" ("id", "name") SELECT "id", "name" FROM "Genre"; +DROP TABLE "Genre"; +ALTER TABLE "new_Genre" RENAME TO "Genre"; +CREATE UNIQUE INDEX "Genre_name_key" ON "Genre"("name"); +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; + +-- CreateIndex +CREATE UNIQUE INDEX "_GenreToStory_AB_unique" ON "_GenreToStory"("A", "B"); + +-- CreateIndex +CREATE INDEX "_GenreToStory_B_index" ON "_GenreToStory"("B"); + +-- CreateIndex +CREATE UNIQUE INDEX "_GenreToPub_AB_unique" ON "_GenreToPub"("A", "B"); + +-- CreateIndex +CREATE INDEX "_GenreToPub_B_index" ON "_GenreToPub"("B"); diff --git a/prisma/migrations/20240611102342_init/migration.sql b/prisma/migrations/20240611102342_init/migration.sql new file mode 100644 index 0000000..f9ac785 --- /dev/null +++ b/prisma/migrations/20240611102342_init/migration.sql @@ -0,0 +1,24 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Pub" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "title" TEXT NOT NULL, + "link" TEXT NOT NULL, + "query_after_days" INTEGER NOT NULL, + "deleted" INTEGER NOT NULL DEFAULT 0 +); +INSERT INTO "new_Pub" ("deleted", "id", "link", "query_after_days", "title") SELECT "deleted", "id", "link", "query_after_days", "title" FROM "Pub"; +DROP TABLE "Pub"; +ALTER TABLE "new_Pub" RENAME TO "Pub"; +CREATE TABLE "new_Story" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "word_count" INTEGER NOT NULL, + "title" TEXT NOT NULL, + "deleted" INTEGER NOT NULL DEFAULT 0 +); +INSERT INTO "new_Story" ("deleted", "id", "title", "word_count") SELECT "deleted", "id", "title", "word_count" FROM "Story"; +DROP TABLE "Story"; +ALTER TABLE "new_Story" RENAME TO "Story"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/20240611102754_init/migration.sql b/prisma/migrations/20240611102754_init/migration.sql new file mode 100644 index 0000000..ce59ab6 --- /dev/null +++ b/prisma/migrations/20240611102754_init/migration.sql @@ -0,0 +1,15 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Pub" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "title" TEXT NOT NULL, + "link" TEXT NOT NULL DEFAULT '', + "query_after_days" INTEGER NOT NULL, + "deleted" INTEGER NOT NULL DEFAULT 0 +); +INSERT INTO "new_Pub" ("deleted", "id", "link", "query_after_days", "title") SELECT "deleted", "id", "link", "query_after_days", "title" FROM "Pub"; +DROP TABLE "Pub"; +ALTER TABLE "new_Pub" RENAME TO "Pub"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5e5c47 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..8a99d2a --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,55 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "sqlite" + url = "file:./dev.db" +} + +model Story { + id Int @id @default(autoincrement()) + word_count Int + title String + deleted Int @default(0) + subs Sub[] + genres Genre[] +} + +model Pub { + id Int @id @default(autoincrement()) + title String + link String @default("") + query_after_days Int + deleted Int @default(0) + subs Sub[] + genres Genre[] +} + +model Genre { + id Int @id @default(autoincrement()) + name String @unique + stories Story[] + pubs Pub[] +} + +model Response { + id Int @id @default(autoincrement()) + response String + subs Sub[] +} + +model Sub { + id Int @id @default(autoincrement()) + story Story @relation(fields: [storyId], references: [id]) + storyId Int + pub Pub @relation(fields: [pubId], references: [id]) + pubId Int + submitted String + responded String + response Response @relation(fields: [responseId], references: [id]) + responseId Int +} diff --git a/prisma/script.js b/prisma/script.js new file mode 100644 index 0000000..65dac19 --- /dev/null +++ b/prisma/script.js @@ -0,0 +1,27 @@ +import { PrismaClient } from '@prisma/client' + +const prisma = new PrismaClient() + +async function main() { + // ... you will write your Prisma Client queries here + const story = await prisma.story.update({ + where: { id: 1 }, + data: { + title: "Ghost Aliens of Mars", + genres: { set: [{ id: 1 }, { id: 2 }], create: { name: "alien-punk" } } + } + + }) + console.log(story) + +} + +main() + .then(async () => { + await prisma.$disconnect() + }) + .catch(async (e) => { + console.error(e) + await prisma.$disconnect() + process.exit(1) + })