feat: add deployment endpoint
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"use server";
|
||||
|
||||
import { db } from "@/db/db";
|
||||
import { deploymentsTable } from "@/db/schema";
|
||||
import { auth } from "@clerk/nextjs";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import "server-only";
|
||||
|
||||
export async function createDeployments(
|
||||
workflow_id: string,
|
||||
version_id: string,
|
||||
machine_id: string,
|
||||
environment: "production" | "staging"
|
||||
) {
|
||||
const { userId } = auth();
|
||||
if (!userId) throw new Error("No user id");
|
||||
|
||||
// Same environment and same workflow
|
||||
const existingDeployment = await db.query.deploymentsTable.findFirst({
|
||||
where: and(
|
||||
eq(deploymentsTable.workflow_id, workflow_id),
|
||||
eq(deploymentsTable.environment, environment)
|
||||
),
|
||||
});
|
||||
|
||||
if (existingDeployment) {
|
||||
await db
|
||||
.update(deploymentsTable)
|
||||
.set({
|
||||
workflow_id,
|
||||
workflow_version_id: version_id,
|
||||
machine_id,
|
||||
})
|
||||
.where(eq(deploymentsTable.id, existingDeployment.id));
|
||||
} else {
|
||||
await db.insert(deploymentsTable).values({
|
||||
user_id: userId,
|
||||
workflow_id,
|
||||
workflow_version_id: version_id,
|
||||
machine_id,
|
||||
environment,
|
||||
});
|
||||
}
|
||||
revalidatePath(`/${workflow_id}`);
|
||||
}
|
||||
@@ -43,14 +43,7 @@ export async function addMachine(name: string, endpoint: string) {
|
||||
export async function deleteMachine(
|
||||
machine_id: string
|
||||
): Promise<{ message: string; error?: boolean }> {
|
||||
try {
|
||||
await db.delete(machinesTable).where(eq(machinesTable.id, machine_id));
|
||||
revalidatePath("/machines");
|
||||
return { message: "Machine Deleted" };
|
||||
} catch (error: unknown) {
|
||||
return {
|
||||
message: `Error: ${error.detail}`,
|
||||
error: true,
|
||||
};
|
||||
}
|
||||
await db.delete(machinesTable).where(eq(machinesTable.id, machine_id));
|
||||
revalidatePath("/machines");
|
||||
return { message: "Machine Deleted" };
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { db } from "@/db/db";
|
||||
import { workflowRunsTable } from "@/db/schema";
|
||||
import { deploymentsTable, workflowRunsTable } from "@/db/schema";
|
||||
import { desc, eq } from "drizzle-orm";
|
||||
|
||||
export async function findAllRuns(workflow_id: string) {
|
||||
@@ -21,3 +21,22 @@ export async function findAllRuns(workflow_id: string) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function findAllDeployments(workflow_id: string) {
|
||||
return await db.query.deploymentsTable.findMany({
|
||||
where: eq(deploymentsTable.workflow_id, workflow_id),
|
||||
orderBy: desc(deploymentsTable.environment),
|
||||
with: {
|
||||
machine: {
|
||||
columns: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
version: {
|
||||
columns: {
|
||||
version: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
"use server";
|
||||
|
||||
import { db } from "@/db/db";
|
||||
import { workflowRunOutputs } from "@/db/schema";
|
||||
import { workflowRunOutputs, workflowRunsTable } from "@/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
export async function getRunsOutput(run_id: string) {
|
||||
// throw new Error("Not implemented");
|
||||
return await db
|
||||
.select()
|
||||
.from(workflowRunOutputs)
|
||||
.where(eq(workflowRunOutputs.run_id, run_id));
|
||||
}
|
||||
|
||||
export async function getRunsData(run_id: string) {
|
||||
// throw new Error("Not implemented");
|
||||
return await db.query.workflowRunsTable.findFirst({
|
||||
where: eq(workflowRunsTable.id, run_id),
|
||||
with: {
|
||||
outputs: {
|
||||
columns: {
|
||||
data: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const s3Client = new S3({
|
||||
forcePathStyle: true,
|
||||
});
|
||||
|
||||
function replaceCDNUrl(url: string) {
|
||||
export function replaceCDNUrl(url: string) {
|
||||
url = url.replace(
|
||||
process.env.SPACES_ENDPOINT!,
|
||||
process.env.SPACES_ENDPOINT_CDN!
|
||||
|
||||
Reference in New Issue
Block a user