Skip to content

Commit 1c0fab2

Browse files
Merge PR: Tags model, pagination, and fixes
2 parents fee2859 + 5e53f7e commit 1c0fab2

44 files changed

Lines changed: 2477 additions & 1688 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ jspm_packages/
5252
build
5353
dist
5454

55-
# Prisma generated client (should not be needed starting from v7; refer to the docs)
56-
prisma/generated/client
55+
# Prisma generated client (needed to be placed & ignored explicitly starting from v7)
56+
prisma/client

package-lock.json

Lines changed: 843 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
"main": "./dist/server.js",
3333
"scripts": {
3434
"lint": "eslint .",
35+
"type-check": "tsc --noEmit",
3536
"prepare": "simple-git-hooks",
3637
"postinstall": "prisma generate",
3738
"start": "node ./dist/server.js",
38-
"type-check": "tsc --noEmit --pretty",
3939
"test": "dotenv -e .env.test -o -- vitest",
4040
"dev": "tsx watch --env-file=.env ./src/server.ts",
41-
"build": "tsc --pretty --project tsconfig.prod.json",
41+
"build": "tsc --pretty -p tsconfig.prod.json && tsc-alias -p tsconfig.prod.json",
4242
"test:db:push": "dotenv -e .env.test -o -- prisma db push --skip-generate --force-reset",
4343
"pg:down": "docker compose -f docker-compose.postgres.yml down --remove-orphans",
4444
"pg:stop": "docker compose -f docker-compose.postgres.yml stop",
4545
"pg:up": "docker compose -f docker-compose.postgres.yml up"
4646
},
4747
"dependencies": {
48-
"@prisma/client": "^6.11.1",
48+
"@prisma/client": "^6.13.0",
4949
"@supabase/supabase-js": "^2.50.0",
5050
"bcryptjs": "^3.0.2",
5151
"cors": "^2.8.5",
@@ -78,9 +78,10 @@
7878
"dotenv-cli": "^8.0.0",
7979
"eslint": "^9.24.0",
8080
"eslint-plugin-security": "^3.0.1",
81-
"prisma": "^6.11.1",
81+
"prisma": "^6.13.0",
8282
"simple-git-hooks": "^2.12.1",
8383
"supertest": "^7.1.0",
84+
"tsc-alias": "^1.8.16",
8485
"tsx": "^4.19.3",
8586
"typescript": "^5.8.3",
8687
"typescript-eslint": "^8.29.1",
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[order]` on the table `categories` will be added. If there are existing duplicate values, this will fail.
5+
- A unique constraint covering the columns `[order]` on the table `comments` will be added. If there are existing duplicate values, this will fail.
6+
- A unique constraint covering the columns `[order]` on the table `images` will be added. If there are existing duplicate values, this will fail.
7+
- A unique constraint covering the columns `[order]` on the table `posts` will be added. If there are existing duplicate values, this will fail.
8+
- A unique constraint covering the columns `[order]` on the table `users` will be added. If there are existing duplicate values, this will fail.
9+
- A unique constraint covering the columns `[order]` on the table `votes_on_posts` will be added. If there are existing duplicate values, this will fail.
10+
11+
*/
12+
-- AlterTable
13+
ALTER TABLE "categories" ADD COLUMN "order" SERIAL NOT NULL;
14+
15+
-- AlterTable
16+
ALTER TABLE "comments" ADD COLUMN "order" SERIAL NOT NULL;
17+
18+
-- AlterTable
19+
ALTER TABLE "images" ADD COLUMN "order" SERIAL NOT NULL;
20+
21+
-- AlterTable
22+
ALTER TABLE "posts" ADD COLUMN "order" SERIAL NOT NULL;
23+
24+
-- AlterTable
25+
ALTER TABLE "users" ADD COLUMN "order" SERIAL NOT NULL;
26+
27+
-- AlterTable
28+
ALTER TABLE "votes_on_posts" ADD COLUMN "order" SERIAL NOT NULL;
29+
30+
-- CreateIndex
31+
CREATE UNIQUE INDEX "categories_order_key" ON "categories"("order");
32+
33+
-- CreateIndex
34+
CREATE UNIQUE INDEX "comments_order_key" ON "comments"("order");
35+
36+
-- CreateIndex
37+
CREATE UNIQUE INDEX "images_order_key" ON "images"("order");
38+
39+
-- CreateIndex
40+
CREATE UNIQUE INDEX "posts_order_key" ON "posts"("order");
41+
42+
-- CreateIndex
43+
CREATE UNIQUE INDEX "users_order_key" ON "users"("order");
44+
45+
-- CreateIndex
46+
CREATE UNIQUE INDEX "votes_on_posts_order_key" ON "votes_on_posts"("order");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `category_name` on the `categories_on_posts` table. All the data in the column will be lost.
5+
- A unique constraint covering the columns `[post_id,name]` on the table `categories_on_posts` will be added. If there are existing duplicate values, this will fail.
6+
- Added the required column `name` to the `categories_on_posts` table without a default value. This is not possible if the table is not empty.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE "categories_on_posts" DROP CONSTRAINT "categories_on_posts_category_name_fkey";
11+
12+
-- DropIndex
13+
DROP INDEX "categories_on_posts_post_id_category_name_key";
14+
15+
-- AlterTable
16+
ALTER TABLE "categories_on_posts" DROP COLUMN "category_name",
17+
ADD COLUMN "name" TEXT NOT NULL;
18+
19+
-- CreateIndex
20+
CREATE UNIQUE INDEX "categories_on_posts_post_id_name_key" ON "categories_on_posts"("post_id", "name");
21+
22+
-- AddForeignKey
23+
ALTER TABLE "categories_on_posts" ADD CONSTRAINT "categories_on_posts_name_fkey" FOREIGN KEY ("name") REFERENCES "categories"("name") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `categories` table. If the table is not empty, all the data it contains will be lost.
5+
- You are about to drop the `categories_on_posts` table. If the table is not empty, all the data it contains will be lost.
6+
- You are about to drop the `votes_on_posts` table. If the table is not empty, all the data it contains will be lost.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE "public"."categories_on_posts" DROP CONSTRAINT "categories_on_posts_name_fkey";
11+
12+
-- DropForeignKey
13+
ALTER TABLE "public"."categories_on_posts" DROP CONSTRAINT "categories_on_posts_post_id_fkey";
14+
15+
-- DropForeignKey
16+
ALTER TABLE "public"."votes_on_posts" DROP CONSTRAINT "votes_on_posts_post_id_fkey";
17+
18+
-- DropForeignKey
19+
ALTER TABLE "public"."votes_on_posts" DROP CONSTRAINT "votes_on_posts_user_id_fkey";
20+
21+
-- DropTable
22+
DROP TABLE "public"."categories";
23+
24+
-- DropTable
25+
DROP TABLE "public"."categories_on_posts";
26+
27+
-- DropTable
28+
DROP TABLE "public"."votes_on_posts";
29+
30+
-- CreateTable
31+
CREATE TABLE "public"."tags" (
32+
"order" SERIAL NOT NULL,
33+
"name" TEXT NOT NULL
34+
);
35+
36+
-- CreateTable
37+
CREATE TABLE "public"."posts_tags" (
38+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
39+
"post_id" UUID NOT NULL,
40+
"name" TEXT NOT NULL,
41+
42+
CONSTRAINT "posts_tags_pkey" PRIMARY KEY ("id")
43+
);
44+
45+
-- CreateTable
46+
CREATE TABLE "public"."posts_votes" (
47+
"id" UUID NOT NULL DEFAULT gen_random_uuid(),
48+
"order" SERIAL NOT NULL,
49+
"user_id" UUID NOT NULL,
50+
"post_id" UUID NOT NULL,
51+
"is_upvote" BOOLEAN NOT NULL DEFAULT true,
52+
53+
CONSTRAINT "posts_votes_pkey" PRIMARY KEY ("id")
54+
);
55+
56+
-- CreateIndex
57+
CREATE UNIQUE INDEX "tags_order_key" ON "public"."tags"("order");
58+
59+
-- CreateIndex
60+
CREATE UNIQUE INDEX "tags_name_key" ON "public"."tags"("name");
61+
62+
-- CreateIndex
63+
CREATE UNIQUE INDEX "posts_tags_post_id_name_key" ON "public"."posts_tags"("post_id", "name");
64+
65+
-- CreateIndex
66+
CREATE UNIQUE INDEX "posts_votes_order_key" ON "public"."posts_votes"("order");
67+
68+
-- CreateIndex
69+
CREATE UNIQUE INDEX "posts_votes_user_id_post_id_key" ON "public"."posts_votes"("user_id", "post_id");
70+
71+
-- AddForeignKey
72+
ALTER TABLE "public"."posts_tags" ADD CONSTRAINT "posts_tags_post_id_fkey" FOREIGN KEY ("post_id") REFERENCES "public"."posts"("id") ON DELETE CASCADE ON UPDATE CASCADE;
73+
74+
-- AddForeignKey
75+
ALTER TABLE "public"."posts_tags" ADD CONSTRAINT "posts_tags_name_fkey" FOREIGN KEY ("name") REFERENCES "public"."tags"("name") ON DELETE CASCADE ON UPDATE CASCADE;
76+
77+
-- AddForeignKey
78+
ALTER TABLE "public"."posts_votes" ADD CONSTRAINT "posts_votes_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
79+
80+
-- AddForeignKey
81+
ALTER TABLE "public"."posts_votes" ADD CONSTRAINT "posts_votes_post_id_fkey" FOREIGN KEY ("post_id") REFERENCES "public"."posts"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
generator client {
22
provider = "prisma-client-js"
3-
output = "./generated/client"
3+
output = "./client"
44
}
55

66
datasource db {
@@ -10,6 +10,7 @@ datasource db {
1010

1111
model User {
1212
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
13+
order Int @unique @default(autoincrement())
1314
password String @db.Char(60)
1415
fullname String @db.VarChar(100)
1516
username String @unique @db.VarChar(50)
@@ -27,6 +28,7 @@ model User {
2728

2829
model Comment {
2930
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
31+
order Int @unique @default(autoincrement())
3032
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
3133
authorId String @map("author_id") @db.Uuid
3234
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
@@ -39,55 +41,59 @@ model Comment {
3941
}
4042

4143
model Post {
42-
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
43-
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
44-
authorId String @map("author_id") @db.Uuid
45-
published Boolean @default(false)
46-
createdAt DateTime @default(now()) @map("created_at")
47-
updatedAt DateTime @updatedAt @map("updated_at")
48-
categories CategoriesOnPosts[]
49-
votes VoteOnPost[]
50-
comments Comment[]
51-
content String
52-
title String
53-
image Image? @relation(fields: [imageId], references: [id])
54-
imageId String? @map("image_id") @db.Uuid
44+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
45+
order Int @unique @default(autoincrement())
46+
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
47+
authorId String @map("author_id") @db.Uuid
48+
published Boolean @default(false)
49+
createdAt DateTime @default(now()) @map("created_at")
50+
updatedAt DateTime @updatedAt @map("updated_at")
51+
tags TagsOnPosts[]
52+
votes VoteOnPost[]
53+
comments Comment[]
54+
content String
55+
title String
56+
image Image? @relation(fields: [imageId], references: [id])
57+
imageId String? @map("image_id") @db.Uuid
5558
5659
@@map("posts")
5760
}
5861

59-
model Category {
60-
name String @unique
61-
posts CategoriesOnPosts[]
62+
model Tag {
63+
order Int @unique @default(autoincrement())
64+
name String @unique
65+
posts TagsOnPosts[]
6266
63-
@@map("categories")
67+
@@map("tags")
6468
}
6569

66-
model CategoriesOnPosts {
67-
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
68-
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
69-
postId String @map("post_id") @db.Uuid
70-
category Category @relation(fields: [categoryName], references: [name], onDelete: Cascade)
71-
categoryName String @map("category_name")
70+
model TagsOnPosts {
71+
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
72+
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
73+
postId String @map("post_id") @db.Uuid
74+
tag Tag @relation(fields: [name], references: [name], onDelete: Cascade)
75+
name String
7276
73-
@@unique([postId, categoryName])
74-
@@map("categories_on_posts")
77+
@@unique([postId, name])
78+
@@map("posts_tags")
7579
}
7680

7781
model VoteOnPost {
7882
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
83+
order Int @unique @default(autoincrement())
7984
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
8085
userId String @map("user_id") @db.Uuid
8186
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
8287
postId String @map("post_id") @db.Uuid
8388
isUpvote Boolean @default(true) @map("is_upvote")
8489
8590
@@unique([userId, postId])
86-
@@map("votes_on_posts")
91+
@@map("posts_votes")
8792
}
8893

8994
model Image {
9095
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
96+
order Int @unique @default(autoincrement())
9197
ownerId String @map("author_id") @db.Uuid
9298
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
9399
createdAt DateTime @default(now()) @map("created_at")

0 commit comments

Comments
 (0)