From f8c318aac7467bcb6492784dcf5abcdd4b442555 Mon Sep 17 00:00:00 2001 From: LeeJongBeom <52884648+devleejb@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:32:55 +0900 Subject: [PATCH] Support MongoDB (#49) * Change schema for mongodb * Delete migration files * Update `DATABASE_URL` to MongoDB connection URL * Update schema * Update dependency for `prisma` --- backend/.env | 2 +- backend/package-lock.json | 64 +++++++++---------- backend/package.json | 4 +- .../20240115062824_init/migration.sql | 43 ------------- backend/prisma/migrations/migration_lock.toml | 3 - backend/prisma/schema.prisma | 54 +++++++++------- 6 files changed, 66 insertions(+), 104 deletions(-) delete mode 100644 backend/prisma/migrations/20240115062824_init/migration.sql delete mode 100644 backend/prisma/migrations/migration_lock.toml diff --git a/backend/.env b/backend/.env index 641cfea2..3abaa827 100644 --- a/backend/.env +++ b/backend/.env @@ -1 +1 @@ -DATABASE_URL="file:./dev.db" \ No newline at end of file +DATABASE_URL="mongodb://localhost:27017/codepair" \ No newline at end of file diff --git a/backend/package-lock.json b/backend/package-lock.json index b22f3e98..42fbf276 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -13,7 +13,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", "@nestjs/swagger": "^7.1.17", - "@prisma/client": "^5.8.0", + "@prisma/client": "^5.8.1", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" }, @@ -32,7 +32,7 @@ "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", "prettier": "^3.0.0", - "prisma": "^5.8.0", + "prisma": "^5.8.1", "source-map-support": "^0.5.21", "supertest": "^6.3.3", "ts-jest": "^29.1.0", @@ -1975,9 +1975,9 @@ } }, "node_modules/@prisma/client": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.8.0.tgz", - "integrity": "sha512-QxO6C4MaA/ysTIbC+EcAH1aX/YkpymhXtO6zPdk+FvA7+59tNibIYpd+7koPdViLg2iKES4ojsxWNUGNJaEcbA==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.8.1.tgz", + "integrity": "sha512-xQtMPfbIwLlbm0VVIVQY2yqQVOxPwRQhvIp7Z3m2900g1bu/zRHKhYZJQWELqmjl6d8YwBy0K2NvMqh47v1ubw==", "hasInstallScript": true, "engines": { "node": ">=16.13" @@ -1992,48 +1992,48 @@ } }, "node_modules/@prisma/debug": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.8.0.tgz", - "integrity": "sha512-ZqPpkvbovu/kQJ1bvy57NO4dw97fpQGcbQSCtsqlwSE1UNKJP75R3BKxdznk8ZPMY+GJdMRetWNv4oAvSbWn8Q==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.8.1.tgz", + "integrity": "sha512-tjuw7eA0Us3T42jx9AmAgL58rzwzpFGYc3R7Y4Ip75EBYrKMBA1YihuWMcBC92ILmjlQ/u3p8VxcIE0hr+fZfg==", "devOptional": true }, "node_modules/@prisma/engines": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.8.0.tgz", - "integrity": "sha512-Qhqm9WWLujNEC13AuZlUO14SQ15tNLe5puaz+tOk7UqINqJ3PtqMmuSuzomiw2diGVqZ+HYiSQzlR3+pPucVHA==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.8.1.tgz", + "integrity": "sha512-TJgYLRrZr56uhqcXO4GmP5be+zjCIHtLDK20Cnfg+o9d905hsN065QOL+3Z0zQAy6YD31Ol4u2kzSfRmbJv/uA==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/debug": "5.8.0", - "@prisma/engines-version": "5.8.0-37.0a83d8541752d7582de2ebc1ece46519ce72a848", - "@prisma/fetch-engine": "5.8.0", - "@prisma/get-platform": "5.8.0" + "@prisma/debug": "5.8.1", + "@prisma/engines-version": "5.8.1-1.78caf6feeaed953168c64e15a249c3e9a033ebe2", + "@prisma/fetch-engine": "5.8.1", + "@prisma/get-platform": "5.8.1" } }, "node_modules/@prisma/engines-version": { - "version": "5.8.0-37.0a83d8541752d7582de2ebc1ece46519ce72a848", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.8.0-37.0a83d8541752d7582de2ebc1ece46519ce72a848.tgz", - "integrity": "sha512-cXcoVweYbnv8xRfkWq9oj8BECOdzHUazrSpYCa0ehp5TNz4l5Spa8jbq/VROCTzj3ZncH5D9Q2TmySYTOUeKlw==", + "version": "5.8.1-1.78caf6feeaed953168c64e15a249c3e9a033ebe2", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.8.1-1.78caf6feeaed953168c64e15a249c3e9a033ebe2.tgz", + "integrity": "sha512-f5C3JM3l9yhGr3cr4FMqWloFaSCpNpMi58Om22rjD2DOz3owci2mFdFXMgnAGazFPKrCbbEhcxdsRfspEYRoFQ==", "devOptional": true }, "node_modules/@prisma/fetch-engine": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.8.0.tgz", - "integrity": "sha512-1CAuE+JoYsPNggMEn6qk0zos06Uc9bYZBJ0VBPHD6R7REL05614koAbOCmn52IaYz3nobb7f25hqW6AY7rLkIw==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.8.1.tgz", + "integrity": "sha512-+bgjjoSFa6uYEbAPlklfoVSStOEfcpheOjoBoNsNNSQdSzcwE2nM4Q0prun0+P8/0sCHo18JZ9xqa8gObvgOUw==", "devOptional": true, "dependencies": { - "@prisma/debug": "5.8.0", - "@prisma/engines-version": "5.8.0-37.0a83d8541752d7582de2ebc1ece46519ce72a848", - "@prisma/get-platform": "5.8.0" + "@prisma/debug": "5.8.1", + "@prisma/engines-version": "5.8.1-1.78caf6feeaed953168c64e15a249c3e9a033ebe2", + "@prisma/get-platform": "5.8.1" } }, "node_modules/@prisma/get-platform": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.8.0.tgz", - "integrity": "sha512-Nk3rhTFZ1LYkFZJnpSvQcLPCaBWgJQfteHII6UEENOOkYlmP0k3FuswND54tzzEr4qs39wOdV9pbXKX9U2lv7A==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.8.1.tgz", + "integrity": "sha512-wnA+6HTFcY+tkykMokix9GiAkaauPC5W/gg0O5JB0J8tCTNWrqpnQ7AsaGRfkYUbeOIioh6woDjQrGTTRf1Zag==", "devOptional": true, "dependencies": { - "@prisma/debug": "5.8.0" + "@prisma/debug": "5.8.1" } }, "node_modules/@sinclair/typebox": { @@ -7015,13 +7015,13 @@ } }, "node_modules/prisma": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.8.0.tgz", - "integrity": "sha512-hDKoEqPt2qEUTH5yGO3l27CBnPtwvte0CGMKrpCr9+/A919JghfqJ3qgCGgMbOwdkXUOzdho0RH9tyUF3UhpMw==", + "version": "5.8.1", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.8.1.tgz", + "integrity": "sha512-N6CpjzECnUHZ5beeYpDzkt2rYpEdAeqXX2dweu6BoQaeYkNZrC/WJHM+5MO/uidFHTak8QhkPKBWck1o/4MD4A==", "devOptional": true, "hasInstallScript": true, "dependencies": { - "@prisma/engines": "5.8.0" + "@prisma/engines": "5.8.1" }, "bin": { "prisma": "build/index.js" diff --git a/backend/package.json b/backend/package.json index 983e10d1..50bbdfd5 100644 --- a/backend/package.json +++ b/backend/package.json @@ -25,7 +25,7 @@ "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", "@nestjs/swagger": "^7.1.17", - "@prisma/client": "^5.8.0", + "@prisma/client": "^5.8.1", "reflect-metadata": "^0.1.13", "rxjs": "^7.8.1" }, @@ -44,7 +44,7 @@ "eslint-plugin-prettier": "^5.0.0", "jest": "^29.5.0", "prettier": "^3.0.0", - "prisma": "^5.8.0", + "prisma": "^5.8.1", "source-map-support": "^0.5.21", "supertest": "^6.3.3", "ts-jest": "^29.1.0", diff --git a/backend/prisma/migrations/20240115062824_init/migration.sql b/backend/prisma/migrations/20240115062824_init/migration.sql deleted file mode 100644 index 28b73072..00000000 --- a/backend/prisma/migrations/20240115062824_init/migration.sql +++ /dev/null @@ -1,43 +0,0 @@ --- CreateTable -CREATE TABLE "User" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "socialUid" TEXT NOT NULL, - "nickname" TEXT NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL -); - --- CreateTable -CREATE TABLE "UserWorkspace" ( - "userId" INTEGER NOT NULL, - "workspaceId" INTEGER NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL, - - PRIMARY KEY ("userId", "workspaceId"), - CONSTRAINT "UserWorkspace_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT "UserWorkspace_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "Workspace" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Workspace" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "title" TEXT NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL -); - --- CreateTable -CREATE TABLE "Document" ( - "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - "yorkieDocumentId" TEXT NOT NULL, - "title" TEXT NOT NULL, - "content" TEXT, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL, - "workspaceId" INTEGER NOT NULL, - CONSTRAINT "Document_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "Workspace" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateIndex -CREATE UNIQUE INDEX "User_socialUid_key" ON "User"("socialUid"); diff --git a/backend/prisma/migrations/migration_lock.toml b/backend/prisma/migrations/migration_lock.toml deleted file mode 100644 index e5e5c470..00000000 --- a/backend/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# 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/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 4d5b3841..e5e018fd 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -6,46 +6,54 @@ generator client { } datasource db { - provider = "sqlite" + provider = "mongodb" url = env("DATABASE_URL") } model User { - id Int @id @default(autoincrement()) - socialUid String @unique - nickname String - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - UserWorkspace UserWorkspace[] + id String @id @default(auto()) @map("_id") @db.ObjectId + socialProvider String @map("social_provider") + socialUid String @unique @map("social_uid") + nickname String + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + UserWorkspace UserWorkspace[] + + @@map("users") } model UserWorkspace { + id String @id @default(auto()) @map("_id") @db.ObjectId user User @relation(fields: [userId], references: [id]) - userId Int + userId String @map("user_id") @db.ObjectId workspace Workspace @relation(fields: [workspaceId], references: [id]) - workspaceId Int - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + workspaceId String @map("workspace_id") @db.ObjectId + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") - @@id([userId, workspaceId]) + @@map("user_workspaces") } model Workspace { - id Int @id @default(autoincrement()) - title String - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - documentList Document[] - UserWorkspace UserWorkspace[] + id String @id @default(auto()) @map("_id") @db.ObjectId + title String + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + documentList Document[] + userWorkspaceList UserWorkspace[] + + @@map("workspaces") } model Document { - id Int @id @default(autoincrement()) - yorkieDocumentId String + id String @id @default(auto()) @map("_id") @db.ObjectId + yorkieDocumentId String @map("yorkie_document_id") title String content String? - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") workspace Workspace @relation(fields: [workspaceId], references: [id]) - workspaceId Int + workspaceId String @map("workspace_id") @db.ObjectId + + @@map("documents") }