Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Update DB and state store

Tomas Valentabfc4936190f7
diff --git a/db/supabase.ts b/db/supabase.ts
index ffd59fe55..439e545ff 100644
--- a/db/supabase.ts
+++ b/db/supabase.ts
@@ -11,25 +11,25 @@ export interface Database {
Tables: {
deployments: {
Row: {
- code: string | null
created_at: string
id: string
logs: Json[] | null
project_id: string
+ route_id: string | null
}
Insert: {
- code?: string | null
created_at?: string
id?: string
logs?: Json[] | null
project_id: string
+ route_id?: string | null
}
Update: {
- code?: string | null
created_at?: string
id?: string
logs?: Json[] | null
project_id?: string
+ route_id?: string | null
}
}
projects: {
diff --git a/db/tables.ts b/db/tables.ts
index 67cc0d5ef..8dde09dd0 100644
--- a/db/tables.ts
+++ b/db/tables.ts
@@ -1,2 +1,3 @@
export const projectsTable = 'projects'
export const deploymentsTable = 'deployments'
+export const routesTable = 'routes'
diff --git a/hooks/useLatestDeployment.tsx b/hooks/useLatestDeployment.tsx
index 49fd123d3..8da0fd51b 100644
--- a/hooks/useLatestDeployment.tsx
+++ b/hooks/useLatestDeployment.tsx
@@ -4,31 +4,35 @@ import { useState, useEffect } from 'react'
import { deploymentsTable } from 'db/tables'
import { Database } from 'db/supabase'
+import { Route } from 'state/store'
-export function useLatestDeployment(project: projects) {
+export function useLatestDeployment(project: projects, route?: Route) {
const [initDeployment, setInitDeployment] = useState<deployments>()
const [deployment, setDeployment] = useState<deployments>()
const client = useSupabaseClient<Database>()
useEffect(function init() {
+ if (!route?.id) return
+
(async function () {
const deployment = await client
.from(deploymentsTable)
.select('*')
.eq('project_id', project.id)
+ .eq('route_id', route.id)
.order('created_at')
.limit(1)
.single()
if (deployment.error) return
-
- console.log(deployment.data)
setInitDeployment(deployment.data as unknown as deployments)
}())
- }, [client, project.id])
+ }, [client, project.id, route?.id])
useEffect(function subscribe() {
+ if (!route?.id) return
+
const insertSub = client.channel('any')
.on('postgres_changes',
{
@@ -37,8 +41,9 @@ export function useLatestDeployment(project: projects) {
table: deploymentsTable,
filter: `project_id=eq.${project.id}`,
}, payload => {
- console.log('Change received!', payload)
- setDeployment(payload.new as deployments)
+ if (payload.new.route_id === route.id) {
+ setDeployment(payload.new as deployments)
+ }
})
.subscribe()
const updateSub = client.channel('any')
@@ -49,8 +54,9 @@ export function useLatestDeployment(project: projects) {
table: deploymentsTable,
filter: `project_id=eq.${project.id}`,
}, payload => {
- console.log('Change received!', payload)
- setDeployment(payload.new as deployments)
+ if (payload.new.route_id === route.id) {
+ setDeployment(payload.new as deployments)
+ }
})
.subscribe()
@@ -58,7 +64,11 @@ export function useLatestDeployment(project: projects) {
insertSub.unsubscribe()
updateSub.unsubscribe()
}
- }, [client, project.id])
+ }, [
+ client,
+ project.id,
+ route?.id,
+ ])
return deployment || initDeployment
}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index d68c0108d..60dddc68d 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -255,8 +255,8 @@ model deployments {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
created_at DateTime @default(now()) @db.Timestamptz(6)
logs Json[]
- code String?
project_id String
+ route_id String?
projects projects @relation(fields: [project_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
@@schema("public")
diff --git a/state/store.ts b/state/store.ts
index 7ea0cab9e..185e1236a 100644
--- a/state/store.ts
+++ b/state/store.ts
@@ -139,13 +139,13 @@ export function createStore(initialState?: projects, client?: SupabaseClient<Dat
return null
},
removeItem: async () => {
- const res = await client.from(projectsTable).update({ data: {} }).eq('project_id', initialState.id).single()
+ const res = await client.from(projectsTable).update({ data: {} }).eq('id', initialState.id).single()
if (res.error) {
throw res.error
}
},
setItem: async (name, value) => {
- const res = await client.from(projectsTable).update({ data: value as any }).eq('project_id', initialState.id)
+ const res = await client.from(projectsTable).update({ data: value as any }).eq('id', initialState.id)
if (res.error) {
throw res.error
}