feat: 增加 pipeline和 deployment

This commit is contained in:
2025-09-21 21:38:42 +08:00
parent ef4fce6d42
commit fd0cf782c4
10 changed files with 154 additions and 17 deletions

7
apps/server/README.md Normal file
View File

@@ -0,0 +1,7 @@
## 表
- user
- project
- pipeline
- deployment
- runner

View File

@@ -0,0 +1,45 @@
import { Controller, Get, Post } from '../../decorators/route.ts';
import type { Prisma } from '../../generated/prisma/index.js';
import prisma from '../../libs/db.ts';
import type { Context } from 'koa';
@Controller('/deployments')
export class DeploymentController {
@Get('')
async list(ctx: Context) {
const { page = 1, pageSize = 10 } = ctx.query;
const result = await prisma.deployment.findMany({
where: {
valid: 1,
},
take: Number(pageSize),
skip: (Number(page) - 1) * Number(pageSize),
orderBy: {
createdAt: 'desc',
},
});
const total = await prisma.deployment.count();
return {
data: result,
page: Number(page),
pageSize: Number(pageSize),
total: total,
};
}
@Post('')
async create(ctx: Context) {
const body = ctx.request.body as Prisma.DeploymentCreateInput;
prisma.deployment.create({
data: {
branch: body.branch,
commitHash: body.commitHash,
commitMessage: body.commitMessage,
valid: 1,
},
});
}
}

View File

@@ -2,3 +2,5 @@
export { ProjectController } from './project/index.ts';
export { UserController } from './user/index.ts';
export { AuthController } from './auth/index.ts';
export { DeploymentController } from './deployment/index.ts';
export { PipelineController } from './pipeline/index.ts'

View File

@@ -0,0 +1,22 @@
import type { Context } from 'koa';
import { Controller, Get, Post } from '../../decorators/route.ts';
import prisma from '../../libs/db.ts';
@Controller('/pipelines')
export class PipelineController {
@Get('/:id')
async get(ctx: Context) {
const id = ctx.params.id;
const pipeline = await prisma.pipeline.findUnique({
where: {
id: id,
},
});
return pipeline;
}
@Post('')
async create(ctx: Context) {
}
}

View File

@@ -6,6 +6,8 @@ import {
ProjectController,
UserController,
AuthController,
DeploymentController,
PipelineController
} from '../controllers/index.ts';
import { log } from '../libs/logger.ts';
@@ -38,6 +40,8 @@ export class Router implements Middleware {
ProjectController,
UserController,
AuthController,
DeploymentController,
PipelineController
]);
// 输出注册的路由信息

View File

@@ -18,7 +18,8 @@
"koa-session": "^7.0.2",
"pino": "^9.9.1",
"pino-pretty": "^13.1.1",
"zod": "^4.1.5"
"zod": "^4.1.5",
"zx": "^8.8.2"
},
"devDependencies": {
"@tsconfig/node-ts": "^23.6.1",

Binary file not shown.

View File

@@ -12,26 +12,19 @@ datasource db {
}
model Project {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
name String
description String?
repository String
valid Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String
updatedBy String
}
// Relations
deployments Deployment[]
pipelines Pipeline[]
model Environment {
id Int @id @default(autoincrement())
name String
description String?
valid Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String
updatedBy String
valid Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String
updatedBy String
}
model User {
@@ -47,3 +40,56 @@ model User {
createdBy String @default("system")
updatedBy String @default("system")
}
model Pipeline {
id Int @id @default(autoincrement())
name String
description String?
valid Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String
updatedBy String
// Relations
projectId Int?
Project Project? @relation(fields: [projectId], references: [id])
steps Step[]
}
model Step {
id Int @id @default(autoincrement())
name String
description String?
order Int
status String?
valid Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String
updatedBy String
pipelineId Int
pipeline Pipeline @relation(fields: [pipelineId], references: [id])
}
model Deployment {
id Int @id @default(autoincrement())
branch String
env String?
status String // pending, running, success, failed, cancelled
commitHash String?
commitMessage String?
buildLog String?
startedAt DateTime @default(now())
finishedAt DateTime?
valid Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy String
updatedBy String
projectId Int
Project Project? @relation(fields: [projectId], references: [id])
pipelineId Int
}