import mongoose, { Schema, Document, Types } from "mongoose"; import { DeploymentProjectDocument } from "./deploymentProject.js"; export interface DeploymentRunDocument extends Document { project: Types.ObjectId | DeploymentProjectDocument; status: "running" | "success" | "failed"; message?: string; logs: string[]; startedAt: Date; finishedAt?: Date; durationMs?: number; createdAt: Date; updatedAt: Date; } const DeploymentRunSchema = new Schema( { project: { type: Schema.Types.ObjectId, ref: "DeploymentProject", required: true }, status: { type: String, enum: ["running", "success", "failed"], required: true }, message: { type: String }, logs: { type: [String], default: [] }, startedAt: { type: Date, required: true }, finishedAt: { type: Date }, durationMs: { type: Number } }, { timestamps: true } ); DeploymentRunSchema.index({ project: 1, startedAt: -1 }); export const DeploymentRun = mongoose.model( "DeploymentRun", DeploymentRunSchema );