File size: 2,734 Bytes
4e83772 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | import mongoose, { Document, Schema, Types } from "mongoose";
export interface IEnvVar {
name: string;
value: string;
}
export enum ProjectStatus {
NOT_STARTED = "NOT_STARTED",
QUEUED = "QUEUED",
BUILDING = "BUILDING",
READY = "READY",
FAILED = "FAILED",
CANCELED = "CANCELLED",
}
export enum ProjectProvider {
MANUAL = "MANUAL",
GITHUB = "GITHUB",
GITHUB_DISCONNECTED = "GITHUB_DISCONNECTED",
}
export interface IProject extends Document {
_id: string;
user: Types.ObjectId;
name: string;
ghRepoId?: number;
isPrivateGhRepo: boolean;
provider: ProjectProvider;
repoURL: string;
subdomain: string;
buildCommand: string;
installCommand: string;
techStack?: string;
branch: string;
rootDir: string;
outputDirectory: string;
currentDeployment: string | null;
tempDeployment: string | null;
lastDeployment: string | null;
env: IEnvVar[];
lastDeployedAt?: Date;
status: ProjectStatus;
deployments?: Types.ObjectId[];
isDeleted: boolean;
isDisabled: boolean;
rewriteNonFilePaths: boolean;
autoDeployEnabled: boolean;
createdAt: Date;
updatedAt: Date;
}
const projectSchema = new Schema<IProject>(
{
user: { type: Schema.Types.ObjectId, ref: "User", required: true },
name: { type: String, required: true },
repoURL: { type: String, required: true },
subdomain: { type: String, required: true, unique: true },
buildCommand: { type: String, required: true, default: "build" },
branch: { type: String, required: true, default: "main" },
rootDir: { type: String, required: true, default: "/" },
installCommand: { type: String, required: true, default: "install" },
techStack: { type: String },
outputDirectory: { type: String, required: true, default: "dist" },
currentDeployment: { type: String, default: null },
tempDeployment: { type: String, default: null },
lastDeployment: { type: String, default: null },
env: [{ name: String, value: String, _id: false }],
lastDeployedAt: { type: Date, default: Date.now() },
isPrivateGhRepo: { type: Boolean, default: false },
provider: { type: String, enum: Object.values(ProjectProvider), required: true, default: ProjectProvider.MANUAL },
ghRepoId: { type: Number, sparse: true },
isDeleted: { type: Boolean, default: false },
isDisabled: { type: Boolean, default: false },
rewriteNonFilePaths: {
type: Boolean,
default: false,
},
autoDeployEnabled: {
type: Boolean,
default: false,
},
status: {
type: String,
required: true,
enum: Object.values(ProjectStatus),
default: ProjectStatus.NOT_STARTED,
},
deployments: [{ type: Schema.Types.ObjectId, ref: "Deployment" }],
},
{
timestamps: true,
},
);
export const Project = mongoose.model<IProject>("Project", projectSchema);
|