diff --git a/BE/prisma/migrations/20260101084425_refactor_naming_convention/migration.sql b/BE/prisma/migrations/20260101084425_refactor_naming_convention/migration.sql new file mode 100644 index 0000000..0ac6592 --- /dev/null +++ b/BE/prisma/migrations/20260101084425_refactor_naming_convention/migration.sql @@ -0,0 +1,59 @@ +/* + Warnings: + + - The primary key for the `answers` table will be changed. If it partially fails, the table could be left without primary key constraint. + - The primary key for the `questions` table will be changed. If it partially fails, the table could be left without primary key constraint. + - The primary key for the `users` table will be changed. If it partially fails, the table could be left without primary key constraint. + +*/ +-- DropForeignKey +ALTER TABLE `answers` DROP FOREIGN KEY `answers_question_id_fkey`; + +-- DropForeignKey +ALTER TABLE `answers` DROP FOREIGN KEY `answers_user_id_fkey`; + +-- DropForeignKey +ALTER TABLE `questions` DROP FOREIGN KEY `questions_accepted_answer_id_fkey`; + +-- DropForeignKey +ALTER TABLE `questions` DROP FOREIGN KEY `questions_user_id_fkey`; + +-- DropIndex +DROP INDEX `answers_question_id_fkey` ON `answers`; + +-- DropIndex +DROP INDEX `answers_user_id_fkey` ON `answers`; + +-- DropIndex +DROP INDEX `questions_user_id_fkey` ON `questions`; + +-- AlterTable +ALTER TABLE `answers` DROP PRIMARY KEY, + MODIFY `id` BIGINT NOT NULL AUTO_INCREMENT, + MODIFY `question_id` BIGINT NOT NULL, + MODIFY `user_id` BIGINT NOT NULL, + ADD PRIMARY KEY (`id`); + +-- AlterTable +ALTER TABLE `questions` DROP PRIMARY KEY, + MODIFY `id` BIGINT NOT NULL AUTO_INCREMENT, + MODIFY `user_id` BIGINT NOT NULL, + MODIFY `accepted_answer_id` BIGINT NULL, + ADD PRIMARY KEY (`id`); + +-- AlterTable +ALTER TABLE `users` DROP PRIMARY KEY, + MODIFY `id` BIGINT NOT NULL AUTO_INCREMENT, + ADD PRIMARY KEY (`id`); + +-- AddForeignKey +ALTER TABLE `questions` ADD CONSTRAINT `questions_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `questions` ADD CONSTRAINT `questions_accepted_answer_id_fkey` FOREIGN KEY (`accepted_answer_id`) REFERENCES `answers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `answers` ADD CONSTRAINT `answers_question_id_fkey` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `answers` ADD CONSTRAINT `answers_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/BE/prisma/migrations/20260101084807_refactor_naming_convention/migration.sql b/BE/prisma/migrations/20260101084807_refactor_naming_convention/migration.sql new file mode 100644 index 0000000..bb9ef01 --- /dev/null +++ b/BE/prisma/migrations/20260101084807_refactor_naming_convention/migration.sql @@ -0,0 +1,66 @@ +/* + Warnings: + + - The primary key for the `answers` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to alter the column `id` on the `answers` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `question_id` on the `answers` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `user_id` on the `answers` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - The primary key for the `questions` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to alter the column `id` on the `questions` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `user_id` on the `questions` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - You are about to alter the column `accepted_answer_id` on the `questions` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + - The primary key for the `users` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to alter the column `id` on the `users` table. The data in that column could be lost. The data in that column will be cast from `BigInt` to `Int`. + +*/ +-- DropForeignKey +ALTER TABLE `answers` DROP FOREIGN KEY `answers_question_id_fkey`; + +-- DropForeignKey +ALTER TABLE `answers` DROP FOREIGN KEY `answers_user_id_fkey`; + +-- DropForeignKey +ALTER TABLE `questions` DROP FOREIGN KEY `questions_accepted_answer_id_fkey`; + +-- DropForeignKey +ALTER TABLE `questions` DROP FOREIGN KEY `questions_user_id_fkey`; + +-- DropIndex +DROP INDEX `answers_question_id_fkey` ON `answers`; + +-- DropIndex +DROP INDEX `answers_user_id_fkey` ON `answers`; + +-- DropIndex +DROP INDEX `questions_user_id_fkey` ON `questions`; + +-- AlterTable +ALTER TABLE `answers` DROP PRIMARY KEY, + MODIFY `id` INTEGER NOT NULL AUTO_INCREMENT, + MODIFY `question_id` INTEGER NOT NULL, + MODIFY `user_id` INTEGER NOT NULL, + ADD PRIMARY KEY (`id`); + +-- AlterTable +ALTER TABLE `questions` DROP PRIMARY KEY, + MODIFY `id` INTEGER NOT NULL AUTO_INCREMENT, + MODIFY `user_id` INTEGER NOT NULL, + MODIFY `accepted_answer_id` INTEGER NULL, + ADD PRIMARY KEY (`id`); + +-- AlterTable +ALTER TABLE `users` DROP PRIMARY KEY, + MODIFY `id` INTEGER NOT NULL AUTO_INCREMENT, + ADD PRIMARY KEY (`id`); + +-- AddForeignKey +ALTER TABLE `questions` ADD CONSTRAINT `questions_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `questions` ADD CONSTRAINT `questions_accepted_answer_id_fkey` FOREIGN KEY (`accepted_answer_id`) REFERENCES `answers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `answers` ADD CONSTRAINT `answers_question_id_fkey` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `answers` ADD CONSTRAINT `answers_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/BE/prisma/migrations/20260112024610_refactor_naming_convention/migration.sql b/BE/prisma/migrations/20260112024610_refactor_naming_convention/migration.sql new file mode 100644 index 0000000..0b939fc --- /dev/null +++ b/BE/prisma/migrations/20260112024610_refactor_naming_convention/migration.sql @@ -0,0 +1,77 @@ +/* + Warnings: + + - The primary key for the `answers` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `user_id` on the `answers` table. All the data in the column will be lost. + - The primary key for the `questions` table will be changed. If it partially fails, the table could be left without primary key constraint. + - You are about to drop the column `accepted_answer_id` on the `questions` table. All the data in the column will be lost. + - You are about to drop the column `user_id` on the `questions` table. All the data in the column will be lost. + - You are about to drop the `users` table. If the table is not empty, all the data it contains will be lost. + - Added the required column `member_id` to the `answers` table without a default value. This is not possible if the table is not empty. + - Added the required column `member_id` to the `questions` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropForeignKey +ALTER TABLE `answers` DROP FOREIGN KEY `answers_question_id_fkey`; + +-- DropForeignKey +ALTER TABLE `answers` DROP FOREIGN KEY `answers_user_id_fkey`; + +-- DropForeignKey +ALTER TABLE `questions` DROP FOREIGN KEY `questions_accepted_answer_id_fkey`; + +-- DropForeignKey +ALTER TABLE `questions` DROP FOREIGN KEY `questions_user_id_fkey`; + +-- DropIndex +DROP INDEX `answers_question_id_fkey` ON `answers`; + +-- DropIndex +DROP INDEX `answers_user_id_fkey` ON `answers`; + +-- DropIndex +DROP INDEX `questions_accepted_answer_id_key` ON `questions`; + +-- DropIndex +DROP INDEX `questions_user_id_fkey` ON `questions`; + +-- AlterTable +ALTER TABLE `answers` DROP PRIMARY KEY, + DROP COLUMN `user_id`, + ADD COLUMN `member_id` BIGINT NOT NULL, + MODIFY `id` BIGINT NOT NULL AUTO_INCREMENT, + MODIFY `question_id` BIGINT NOT NULL, + ADD PRIMARY KEY (`id`); + +-- AlterTable +ALTER TABLE `questions` DROP PRIMARY KEY, + DROP COLUMN `accepted_answer_id`, + DROP COLUMN `user_id`, + ADD COLUMN `is_resolved` BOOLEAN NOT NULL DEFAULT false, + ADD COLUMN `member_id` BIGINT NOT NULL, + MODIFY `id` BIGINT NOT NULL AUTO_INCREMENT, + ADD PRIMARY KEY (`id`); + +-- DropTable +DROP TABLE `users`; + +-- CreateTable +CREATE TABLE `members` ( + `id` BIGINT NOT NULL AUTO_INCREMENT, + `nickname` VARCHAR(191) NOT NULL, + `avatar_url` VARCHAR(191) NULL, + `cohort` TINYINT NULL, + `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AddForeignKey +ALTER TABLE `questions` ADD CONSTRAINT `questions_member_id_fkey` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `answers` ADD CONSTRAINT `answers_question_id_fkey` FOREIGN KEY (`question_id`) REFERENCES `questions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE `answers` ADD CONSTRAINT `answers_member_id_fkey` FOREIGN KEY (`member_id`) REFERENCES `members`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/BE/prisma/schema.prisma b/BE/prisma/schema.prisma index a16b5e5..59079a5 100644 --- a/BE/prisma/schema.prisma +++ b/BE/prisma/schema.prisma @@ -14,56 +14,52 @@ datasource db { provider = "mysql" } -model User { - id Int @id @default(autoincrement()) - user_id String @unique - password String +model Member { + id BigInt @id @default(autoincrement()) nickname String - avatar_url String? + avatarUrl String? @map("avatar_url") cohort Int? @db.TinyInt - created_at DateTime @default(now()) - updated_at DateTime @default(now()) @updatedAt + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @default(now()) @updatedAt @map("updated_at") questions Question[] answers Answer[] - @@map("users") + @@map("members") } model Question { - id Int @id @default(autoincrement()) - user_id Int - accepted_answer_id Int? @unique + id BigInt @id @default(autoincrement()) + memberId BigInt @map("member_id") title String contents String hashtags String? - like_count Int @default(0) - view_count Int @default(0) - answer_count Int @default(0) - created_at DateTime @default(now()) - updated_at DateTime @default(now()) @updatedAt + likeCount Int @default(0) @map("like_count") + viewCount Int @default(0) @map("view_count") + answerCount Int @default(0) @map("answer_count") + isResolved Boolean @default(false) @map("is_resolved") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @default(now()) @updatedAt @map("updated_at") - user User @relation(fields: [user_id], references: [id]) + member Member @relation(fields: [memberId], references: [id]) answers Answer[] @relation("QuestionAnswers") - accepted_answer Answer? @relation("AcceptedAnswer", fields: [accepted_answer_id], references: [id]) @@map("questions") } model Answer { - id Int @id @default(autoincrement()) - question_id Int - user_id Int + id BigInt @id @default(autoincrement()) + questionId BigInt @map("question_id") + memberId BigInt @map("member_id") contents String - like_count Int @default(0) - is_accepted Boolean @default(false) - view_count Int @default(0) - created_at DateTime @default(now()) - updated_at DateTime @default(now()) @updatedAt + likeCount Int @default(0) @map("like_count") + isAccepted Boolean @default(false) @map("is_accepted") + viewCount Int @default(0) @map("view_count") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @default(now()) @updatedAt @map("updated_at") - question Question @relation("QuestionAnswers", fields: [question_id], references: [id]) - user User @relation(fields: [user_id], references: [id]) - accepted_in Question? @relation("AcceptedAnswer") + question Question @relation("QuestionAnswers", fields: [questionId], references: [id]) + member Member @relation(fields: [memberId], references: [id]) @@map("answers") } \ No newline at end of file diff --git a/BE/src/main.ts b/BE/src/main.ts index f76bc8d..3511475 100644 --- a/BE/src/main.ts +++ b/BE/src/main.ts @@ -1,6 +1,11 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; +// BigInt 전역 설정 (JSON.stringify 시 문자열로 변환) +(BigInt.prototype as any).toJSON = function () { + return this.toString(); +}; + async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(process.env.PORT ?? 3000);