-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Artur-Poffo/feat-implement-prisma-reposit…
…ories Feat(Prisma repositories): Implement prisma repositories
- Loading branch information
Showing
53 changed files
with
2,690 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
prisma/migrations/20240214203319_file_image_and_video_models/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Warnings: | ||
- Changed the type of `item_type` on the `EnrollmentCompletedItem` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. | ||
*/ | ||
-- CreateEnum | ||
CREATE TYPE "EnrollmentCompletedItemTypes" AS ENUM ('CLASS', 'MODULE'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "VideoTypes" AS ENUM ('MP4', 'AVI'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "ImageTypes" AS ENUM ('JPEG', 'PNG'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "EnrollmentCompletedItem" DROP COLUMN "item_type", | ||
ADD COLUMN "item_type" "EnrollmentCompletedItemTypes" NOT NULL; | ||
|
||
-- DropEnum | ||
DROP TYPE "EnrollmentCompletedItemType"; | ||
|
||
-- CreateTable | ||
CREATE TABLE "files" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"key" TEXT NOT NULL, | ||
"size" DECIMAL(65,30) NOT NULL, | ||
"stored_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "files_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "videos" ( | ||
"id" TEXT NOT NULL, | ||
"type" "VideoTypes" NOT NULL, | ||
"duration" DECIMAL(65,30) NOT NULL, | ||
"file_id" TEXT NOT NULL, | ||
|
||
CONSTRAINT "videos_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "images" ( | ||
"id" TEXT NOT NULL, | ||
"type" "ImageTypes" NOT NULL, | ||
"file_id" TEXT NOT NULL, | ||
|
||
CONSTRAINT "images_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "files_key_key" ON "files"("key"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "videos" ADD CONSTRAINT "videos_file_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "images" ADD CONSTRAINT "images_file_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
31 changes: 31 additions & 0 deletions
31
prisma/migrations/20240214204313_global_file_model/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the `images` table. If the table is not empty, all the data it contains will be lost. | ||
- You are about to drop the `videos` table. If the table is not empty, all the data it contains will be lost. | ||
- Added the required column `type` to the `files` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- CreateEnum | ||
CREATE TYPE "FileTypes" AS ENUM ('MP4', 'AVI', 'JPEG', 'PNG'); | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "images" DROP CONSTRAINT "images_file_id_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "videos" DROP CONSTRAINT "videos_file_id_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "files" ADD COLUMN "type" "FileTypes" NOT NULL; | ||
|
||
-- DropTable | ||
DROP TABLE "images"; | ||
|
||
-- DropTable | ||
DROP TABLE "videos"; | ||
|
||
-- DropEnum | ||
DROP TYPE "ImageTypes"; | ||
|
||
-- DropEnum | ||
DROP TYPE "VideoTypes"; |
12 changes: 12 additions & 0 deletions
12
prisma/migrations/20240214204910_file_type_to_string/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Warnings: | ||
- Changed the type of `type` on the `files` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "files" DROP COLUMN "type", | ||
ADD COLUMN "type" TEXT NOT NULL; | ||
|
||
-- DropEnum | ||
DROP TYPE "FileTypes"; |
25 changes: 25 additions & 0 deletions
25
prisma/migrations/20240214205840_video_model/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `video_key` on the `classes` table. All the data in the column will be lost. | ||
- Added the required column `video_id` to the `classes` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "classes" DROP COLUMN "video_key", | ||
ADD COLUMN "video_id" TEXT NOT NULL; | ||
|
||
-- CreateTable | ||
CREATE TABLE "videos" ( | ||
"id" TEXT NOT NULL, | ||
"duration" DECIMAL(65,30) NOT NULL, | ||
"file_id" TEXT NOT NULL, | ||
|
||
CONSTRAINT "videos_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "classes" ADD CONSTRAINT "classes_video_id_fkey" FOREIGN KEY ("video_id") REFERENCES "videos"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "videos" ADD CONSTRAINT "videos_file_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[file_id]` on the table `videos` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "videos" DROP CONSTRAINT "videos_file_id_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "videos" ALTER COLUMN "file_id" DROP NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "videos_file_id_key" ON "videos"("file_id"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "videos" ADD CONSTRAINT "videos_file_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
14 changes: 14 additions & 0 deletions
14
prisma/migrations/20240214222933_turn_file_id_required/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
Warnings: | ||
- Made the column `file_id` on table `videos` required. This step will fail if there are existing NULL values in that column. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "videos" DROP CONSTRAINT "videos_file_id_fkey"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "videos" ALTER COLUMN "file_id" SET NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "videos" ADD CONSTRAINT "videos_file_id_fkey" FOREIGN KEY ("file_id") REFERENCES "files"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
11 changes: 11 additions & 0 deletions
11
prisma/migrations/20240214224307_course_and_instructor_relation/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `instructor_id` to the `courses` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "courses" ADD COLUMN "instructor_id" TEXT NOT NULL; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "courses" ADD CONSTRAINT "courses_instructor_id_fkey" FOREIGN KEY ("instructor_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240215201244_attached_at_field_on_course_tag/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "course_tags" ADD COLUMN "attachedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { env } from '@/infra/env' | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
export const prisma = new PrismaClient({ | ||
log: env.NODE_ENV === 'development' ? ['query'] : [] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { UniqueEntityID } from '@/core/entities/unique-entity-id' | ||
import { Certificate } from '@/domain/course-management/enterprise/entities/certificate' | ||
import { type Prisma, type Certificate as PrismaCertificate } from '@prisma/client' | ||
|
||
export class CertificateMapper { | ||
static toDomain(raw: PrismaCertificate): Certificate { | ||
return Certificate.create( | ||
{ | ||
courseId: new UniqueEntityID(raw.courseId), | ||
imageId: new UniqueEntityID('') | ||
}, | ||
new UniqueEntityID(raw.id) | ||
) | ||
} | ||
|
||
static toPrisma(certificate: Certificate): Prisma.CertificateUncheckedCreateInput { | ||
return { | ||
id: certificate.id.toString(), | ||
courseId: certificate.courseId.toString(), | ||
imageKey: '' | ||
} | ||
} | ||
} |
Oops, something went wrong.