Implemented TypeORM, Prisma and Enums on a schema

This commit is contained in:
2025-12-19 21:40:46 +02:00
parent 8ca2b50f9c
commit 289715ba44
9 changed files with 3001 additions and 13 deletions

View File

@@ -0,0 +1,46 @@
datasource db {
provider = "postgresql"
}
generator client {
provider = "prisma-client"
output = "./generated"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
role Role @default(USER)
posts Post[]
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
bio String
user User @relation(fields: [userId], references: [id])
userId Int @unique
}
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
categories Category[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
}
enum Role {
USER
ADMIN
}

View File

@@ -0,0 +1,115 @@
//@ts-nocheck
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany, ManyToMany, JoinTable, CreateDateColumn, UpdateDateColumn } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ unique: true })
email: string;
@Column()
name: string;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@OneToMany(() => Project, project => project.owner)
ownedProjects: Project[];
@ManyToMany(() => Project, project => project.members)
@JoinTable()
projects: Project[];
}
@Entity()
export class Project {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
title: string;
@Column({ nullable: true })
description: string;
@Column({ default: 'active' })
status: string;
@ManyToOne(() => User, user => user.ownedProjects)
owner: User;
@ManyToMany(() => User, user => user.projects)
members: User[];
@OneToMany(() => Task, task => task.project)
tasks: Task[];
@CreateDateColumn()
createdAt: Date;
}
@Entity()
export class Task {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
title: string;
@Column({ type: 'text', nullable: true })
description: string;
@Column({ default: 'todo' })
status: string;
@Column({ nullable: true })
dueDate: Date;
@ManyToOne(() => Project, project => project.tasks)
project: Project;
@ManyToOne(() => User, { nullable: true })
assignee: User;
@OneToMany(() => Comment, comment => comment.task)
comments: Comment[];
}
@Entity()
export class Comment {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('text')
content: string;
@ManyToOne(() => Task, task => task.comments)
task: Task;
@ManyToOne(() => User)
author: User;
@CreateDateColumn()
createdAt: Date;
}
@Entity()
export class Tag {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ unique: true })
name: string;
@Column()
color: string;
@ManyToMany(() => Task)
@JoinTable()
tasks: Task[];
}