Spaces:
Sleeping

File size: 2,708 Bytes
4e83772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc50dd8
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
97
98
99
100
101
102
103
104
105
106
import mongoose, { Document, Schema, Types } from "mongoose";

export enum DeploymentStatus {
	NOT_STARTED = "NOT_STARTED",
	QUEUED = "QUEUED",
	BUILDING = "BUILDING",
	READY = "READY",
	FAILED = "FAILED",
	CANCELED = "CANCELLED",
}
export interface FileStructureType {
	totalSize: number;
	files: {
		name: string;
		size: number;
	}[];
}
enum EnvsAvailable {
	development = "development",
	staging = "staging",
	production = "production",
}
export enum DeploymentTriggers {
	GIT_PUSH = "GIT_PUSH",
	GITHUB_CHECKS_RERUN = "GITHUB_CHECKS_RERUN",
	MANUAL = "MANUAL",
	REDEPLOY = "REDEPLOY",
}

export interface IDeployment extends Document {
	_id: string;
	project: Types.ObjectId;
	commit_hash: string;
	publicId: string;
	user: Types.ObjectId;
	status: DeploymentStatus;
	environment: EnvsAvailable;

	timings: {
		install_ms: number;
		build_ms: number;
		duration_ms: number;
		upload_ms: number;
	};
	overWrite: boolean;
	complete_at: Date;
	identifierSlug: string;
	error_message?: string;
	branch: string;
	triggerEvent: DeploymentTriggers;
	triggeredBy?: string;
	file_structure: FileStructureType | null;
	createdAt: Date;
	updatedAt: Date;
}

const deploymentSchema = new Schema<IDeployment>(
	{
		project: { type: Schema.Types.ObjectId, ref: "Project", required: true },
		publicId: { type: String, required: true, unique: true },
		status: { type: String, enum: Object.values(DeploymentStatus), default: DeploymentStatus.NOT_STARTED },
		identifierSlug: { type: String, required: true },
		user: { type: Schema.Types.ObjectId, ref: "User", required: true },
		commit_hash: { type: String, required: true },
		environment: {
			type: String,
			enum: Object.values(EnvsAvailable),
			default: EnvsAvailable.production,
			required: true,
		},
		timings: {
			type: {
				upload_ms: { type: Number, default: 0 },
				install_ms: { type: Number, default: 0 },
				build_ms: { type: Number, default: 0 },
				duration_ms: { type: Number, default: 0 },
			},
			default: () => ({}),
			_id: false,
		},
		overWrite: { type: Boolean, required: true },
		error_message: { type: String },
		triggerEvent: { type: String, enum: Object.values(DeploymentTriggers), default: DeploymentTriggers.MANUAL },
		triggeredBy: { type: String, required: false },
		branch: { type: String, required: false },
		file_structure: {
			type: {
				totalSize: { type: Number, default: 0 },
				files: [
					{
						name: { type: String, required: true },
						size: { type: Number, default: 0 },
						_id: false,
					},
				],
			},
			default: null,
			_id: false,
		},
		complete_at: { type: Date },
	},
	{ timestamps: true },
);

export const Deployment = mongoose.model<IDeployment>("Deployment", deploymentSchema);