From bb53acd8c32944afc6166561e7fad3773c74a048 Mon Sep 17 00:00:00 2001 From: QishengHu Date: Wed, 6 Sep 2023 10:10:22 +0800 Subject: [PATCH] Update prisma migrate configuration --- package.json | 2 +- prisma/migrations/0_init/migration.sql | 118 ++++++++++++++++++ .../20221014084317_init/migration.sql | 0 .../20221020094651_upate_cli/migration.sql | 0 .../migration.sql | 0 .../20221126150023_add_account/migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../migration.sql | 0 .../20230306121228_update/migration.sql | 0 .../migration.sql | 0 .../migration_lock.toml | 0 12 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 prisma/migrations/0_init/migration.sql rename prisma/{migrations => migrations_0}/20221014084317_init/migration.sql (100%) rename prisma/{migrations => migrations_0}/20221020094651_upate_cli/migration.sql (100%) rename prisma/{migrations => migrations_0}/20221103144245_drop_account_session/migration.sql (100%) rename prisma/{migrations => migrations_0}/20221126150023_add_account/migration.sql (100%) rename prisma/{migrations => migrations_0}/20221126151212_email_password_optional/migration.sql (100%) rename prisma/{migrations => migrations_0}/20221126151510_refresh_token_expires/migration.sql (100%) rename prisma/{migrations => migrations_0}/20221127033222_email_required/migration.sql (100%) rename prisma/{migrations => migrations_0}/20230306121228_update/migration.sql (100%) rename prisma/{migrations => migrations_0}/20230905035233_drop_aux_fields/migration.sql (100%) rename prisma/{migrations => migrations_0}/migration_lock.toml (100%) diff --git a/package.json b/package.json index 3baaaa4..0de5327 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint": "next lint", "db:push": "prisma db push", "db:migrate": "prisma migrate dev", - "db:deploy": "prisma migrate deploy", + "db:deploy": "prisma migrate resolve --applied 0_init", "db:reset": "prisma migrate reset", "db:browse": "prisma studio", "generate": "zenstack generate", diff --git a/prisma/migrations/0_init/migration.sql b/prisma/migrations/0_init/migration.sql new file mode 100644 index 0000000..bb681a1 --- /dev/null +++ b/prisma/migrations/0_init/migration.sql @@ -0,0 +1,118 @@ +-- CreateEnum +CREATE TYPE "SpaceUserRole" AS ENUM ('USER', 'ADMIN'); + +-- CreateTable +CREATE TABLE "Space" ( + "id" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "name" TEXT NOT NULL, + "slug" TEXT NOT NULL, + + CONSTRAINT "Space_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "SpaceUser" ( + "id" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "spaceId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "role" "SpaceUserRole" NOT NULL, + + CONSTRAINT "SpaceUser_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "email" TEXT NOT NULL, + "emailVerified" TIMESTAMP(3), + "password" TEXT, + "name" TEXT, + "image" TEXT, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "List" ( + "id" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "spaceId" TEXT NOT NULL, + "ownerId" TEXT NOT NULL, + "title" TEXT NOT NULL, + "private" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "List_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Todo" ( + "id" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "ownerId" TEXT NOT NULL, + "listId" TEXT NOT NULL, + "title" TEXT NOT NULL, + "completedAt" TIMESTAMP(3), + + CONSTRAINT "Todo_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "refresh_token_expires_in" INTEGER, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT, + + CONSTRAINT "Account_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Space_slug_key" ON "Space"("slug"); + +-- CreateIndex +CREATE UNIQUE INDEX "SpaceUser_userId_spaceId_key" ON "SpaceUser"("userId", "spaceId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- AddForeignKey +ALTER TABLE "SpaceUser" ADD CONSTRAINT "SpaceUser_spaceId_fkey" FOREIGN KEY ("spaceId") REFERENCES "Space"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "SpaceUser" ADD CONSTRAINT "SpaceUser_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "List" ADD CONSTRAINT "List_spaceId_fkey" FOREIGN KEY ("spaceId") REFERENCES "Space"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "List" ADD CONSTRAINT "List_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Todo" ADD CONSTRAINT "Todo_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Todo" ADD CONSTRAINT "Todo_listId_fkey" FOREIGN KEY ("listId") REFERENCES "List"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + diff --git a/prisma/migrations/20221014084317_init/migration.sql b/prisma/migrations_0/20221014084317_init/migration.sql similarity index 100% rename from prisma/migrations/20221014084317_init/migration.sql rename to prisma/migrations_0/20221014084317_init/migration.sql diff --git a/prisma/migrations/20221020094651_upate_cli/migration.sql b/prisma/migrations_0/20221020094651_upate_cli/migration.sql similarity index 100% rename from prisma/migrations/20221020094651_upate_cli/migration.sql rename to prisma/migrations_0/20221020094651_upate_cli/migration.sql diff --git a/prisma/migrations/20221103144245_drop_account_session/migration.sql b/prisma/migrations_0/20221103144245_drop_account_session/migration.sql similarity index 100% rename from prisma/migrations/20221103144245_drop_account_session/migration.sql rename to prisma/migrations_0/20221103144245_drop_account_session/migration.sql diff --git a/prisma/migrations/20221126150023_add_account/migration.sql b/prisma/migrations_0/20221126150023_add_account/migration.sql similarity index 100% rename from prisma/migrations/20221126150023_add_account/migration.sql rename to prisma/migrations_0/20221126150023_add_account/migration.sql diff --git a/prisma/migrations/20221126151212_email_password_optional/migration.sql b/prisma/migrations_0/20221126151212_email_password_optional/migration.sql similarity index 100% rename from prisma/migrations/20221126151212_email_password_optional/migration.sql rename to prisma/migrations_0/20221126151212_email_password_optional/migration.sql diff --git a/prisma/migrations/20221126151510_refresh_token_expires/migration.sql b/prisma/migrations_0/20221126151510_refresh_token_expires/migration.sql similarity index 100% rename from prisma/migrations/20221126151510_refresh_token_expires/migration.sql rename to prisma/migrations_0/20221126151510_refresh_token_expires/migration.sql diff --git a/prisma/migrations/20221127033222_email_required/migration.sql b/prisma/migrations_0/20221127033222_email_required/migration.sql similarity index 100% rename from prisma/migrations/20221127033222_email_required/migration.sql rename to prisma/migrations_0/20221127033222_email_required/migration.sql diff --git a/prisma/migrations/20230306121228_update/migration.sql b/prisma/migrations_0/20230306121228_update/migration.sql similarity index 100% rename from prisma/migrations/20230306121228_update/migration.sql rename to prisma/migrations_0/20230306121228_update/migration.sql diff --git a/prisma/migrations/20230905035233_drop_aux_fields/migration.sql b/prisma/migrations_0/20230905035233_drop_aux_fields/migration.sql similarity index 100% rename from prisma/migrations/20230905035233_drop_aux_fields/migration.sql rename to prisma/migrations_0/20230905035233_drop_aux_fields/migration.sql diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations_0/migration_lock.toml similarity index 100% rename from prisma/migrations/migration_lock.toml rename to prisma/migrations_0/migration_lock.toml