From e430048b43b1c6af457650672ea7c225acef072f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E7=90=AA=E6=96=8C?= Date: Mon, 5 Jul 2021 13:32:39 +0800 Subject: [PATCH] chore(psql): use psql --- .gitignore | 2 + .../migration.sql | 40 +++++++++++++------ prisma/migrations/migration_lock.toml | 2 +- prisma/schema.prisma | 4 +- 4 files changed, 33 insertions(+), 15 deletions(-) rename prisma/migrations/{20210705020459_y_dev => 20210705033221_init}/migration.sql (55%) diff --git a/.gitignore b/.gitignore index 4e794b0..20b86a8 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ yarn-error.log* # vercel .vercel .env + +*.sql diff --git a/prisma/migrations/20210705020459_y_dev/migration.sql b/prisma/migrations/20210705033221_init/migration.sql similarity index 55% rename from prisma/migrations/20210705020459_y_dev/migration.sql rename to prisma/migrations/20210705033221_init/migration.sql index f8e4b2d..d260127 100644 --- a/prisma/migrations/20210705020459_y_dev/migration.sql +++ b/prisma/migrations/20210705033221_init/migration.sql @@ -1,51 +1,55 @@ -- CreateTable CREATE TABLE "User" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "id" SERIAL NOT NULL, "name" TEXT, "password" TEXT NOT NULL, - "email" TEXT NOT NULL + "email" TEXT NOT NULL, + + PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Post" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "id" SERIAL NOT NULL, "title" TEXT NOT NULL, "content" TEXT NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "likes" INTEGER DEFAULT 0, "hits" INTEGER NOT NULL DEFAULT 0, "summary" TEXT, "slug" TEXT, "userId" INTEGER NOT NULL, "published" INTEGER NOT NULL DEFAULT 0, - FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE + + PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Category" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "id" SERIAL NOT NULL, "name" TEXT NOT NULL, - "createdAt" DATETIME DEFAULT CURRENT_TIMESTAMP + "createdAt" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP, + + PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "Project" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "id" SERIAL NOT NULL, "title" TEXT NOT NULL, "description" TEXT NOT NULL, "repoUrl" TEXT, "appUrl" TEXT, "order" INTEGER DEFAULT -1, "userId" INTEGER NOT NULL, - FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE + + PRIMARY KEY ("id") ); -- CreateTable CREATE TABLE "_CategoryToPost" ( "A" INTEGER NOT NULL, - "B" INTEGER NOT NULL, - FOREIGN KEY ("A") REFERENCES "Category" ("id") ON DELETE CASCADE ON UPDATE CASCADE, - FOREIGN KEY ("B") REFERENCES "Post" ("id") ON DELETE CASCADE ON UPDATE CASCADE + "B" INTEGER NOT NULL ); -- CreateIndex @@ -62,3 +66,15 @@ CREATE UNIQUE INDEX "_CategoryToPost_AB_unique" ON "_CategoryToPost"("A", "B"); -- CreateIndex CREATE INDEX "_CategoryToPost_B_index" ON "_CategoryToPost"("B"); + +-- AddForeignKey +ALTER TABLE "Post" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Project" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_CategoryToPost" ADD FOREIGN KEY ("A") REFERENCES "Category"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_CategoryToPost" ADD FOREIGN KEY ("B") REFERENCES "Post"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index e5e5c47..fbffa92 100644 --- a/prisma/migrations/migration_lock.toml +++ b/prisma/migrations/migration_lock.toml @@ -1,3 +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 +provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 72314cc..dc28e82 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,8 +3,8 @@ generator client { } datasource db { - provider = "sqlite" - url = "file:./dev.db" + provider = "postgresql" + url = env("DATABASE_URL") } model User{