feat: add Prisma schema with User, Project, Module, Endpoint models
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,9 +8,9 @@
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "tsc --watch",
|
||||
"db:generate": "prisma generate",
|
||||
"db:migrate": "prisma migrate dev",
|
||||
"db:push": "prisma db push"
|
||||
"db:generate": "prisma generate --schema ../../prisma/schema.prisma",
|
||||
"db:migrate": "prisma migrate dev --schema ../../prisma/schema.prisma",
|
||||
"db:push": "prisma db push --schema ../../prisma/schema.prisma"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^6.0.0"
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
// Shared types — will be populated as we build features
|
||||
import type { User, Project, Module, Endpoint, ModuleSource } from '@prisma/client';
|
||||
|
||||
export type { User, Project, Module, Endpoint, ModuleSource };
|
||||
|
||||
export type ApiResponse<T = unknown> = {
|
||||
success: boolean;
|
||||
data?: T;
|
||||
@@ -7,3 +10,23 @@ export type ApiResponse<T = unknown> = {
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type ProjectWithStats = Project & {
|
||||
_count: { endpoints: number; modules: number };
|
||||
};
|
||||
|
||||
export type ModuleWithCount = Module & {
|
||||
_count: { endpoints: number };
|
||||
};
|
||||
|
||||
export type EndpointSummary = {
|
||||
id: string;
|
||||
method: string;
|
||||
path: string;
|
||||
summary: string | null;
|
||||
deprecated: boolean;
|
||||
};
|
||||
|
||||
export type EndpointDetail = Endpoint & {
|
||||
moduleName: string;
|
||||
};
|
||||
|
||||
92
prisma/schema.prisma
Normal file
92
prisma/schema.prisma
Normal file
@@ -0,0 +1,92 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
passwordHash String?
|
||||
name String
|
||||
avatarUrl String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
oauthAccounts OAuthAccount[]
|
||||
projects Project[]
|
||||
}
|
||||
|
||||
model OAuthAccount {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
provider String
|
||||
providerAccountId String
|
||||
createdAt DateTime @default(now())
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([provider, providerAccountId])
|
||||
}
|
||||
|
||||
model Project {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
name String
|
||||
description String?
|
||||
baseUrl String?
|
||||
openApiSpec Json
|
||||
openApiVersion String
|
||||
apiKeyHash String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
modules Module[]
|
||||
endpoints Endpoint[]
|
||||
}
|
||||
|
||||
enum ModuleSource {
|
||||
tag
|
||||
path_prefix
|
||||
manual
|
||||
}
|
||||
|
||||
model Module {
|
||||
id String @id @default(uuid())
|
||||
projectId String
|
||||
name String
|
||||
description String?
|
||||
sortOrder Int @default(0)
|
||||
source ModuleSource
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
endpoints Endpoint[]
|
||||
|
||||
@@index([projectId])
|
||||
}
|
||||
|
||||
model Endpoint {
|
||||
id String @id @default(uuid())
|
||||
projectId String
|
||||
moduleId String
|
||||
method String
|
||||
path String
|
||||
summary String?
|
||||
description String?
|
||||
operationId String?
|
||||
parameters Json @default("[]")
|
||||
requestBody Json?
|
||||
responses Json @default("{}")
|
||||
tags String[] @default([])
|
||||
deprecated Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
module Module @relation(fields: [moduleId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([projectId])
|
||||
@@index([moduleId])
|
||||
@@index([projectId, moduleId])
|
||||
}
|
||||
Reference in New Issue
Block a user