mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
chore(db): remove unused table and unused route (#2342)
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
import { db } from '@sim/db'
|
||||
import { marketplace, workflow } from '@sim/db/schema'
|
||||
import { eq } from 'drizzle-orm'
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { generateRequestId } from '@/lib/core/utils/request'
|
||||
import { createLogger } from '@/lib/logs/console/logger'
|
||||
import { createErrorResponse, createSuccessResponse } from '@/app/api/workflows/utils'
|
||||
|
||||
const logger = createLogger('PublicWorkflowAPI')
|
||||
|
||||
// Cache response for performance
|
||||
export const revalidate = 3600
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const requestId = generateRequestId()
|
||||
|
||||
try {
|
||||
const { id } = await params
|
||||
|
||||
// First, check if the workflow exists and is published to the marketplace
|
||||
const marketplaceEntry = await db
|
||||
.select({
|
||||
id: marketplace.id,
|
||||
workflowId: marketplace.workflowId,
|
||||
state: marketplace.state,
|
||||
name: marketplace.name,
|
||||
description: marketplace.description,
|
||||
authorId: marketplace.authorId,
|
||||
authorName: marketplace.authorName,
|
||||
})
|
||||
.from(marketplace)
|
||||
.where(eq(marketplace.workflowId, id))
|
||||
.limit(1)
|
||||
.then((rows) => rows[0])
|
||||
|
||||
if (!marketplaceEntry) {
|
||||
// Check if workflow exists but is not in marketplace
|
||||
const workflowExists = await db
|
||||
.select({ id: workflow.id })
|
||||
.from(workflow)
|
||||
.where(eq(workflow.id, id))
|
||||
.limit(1)
|
||||
.then((rows) => rows.length > 0)
|
||||
|
||||
if (!workflowExists) {
|
||||
logger.warn(`[${requestId}] Workflow not found: ${id}`)
|
||||
return createErrorResponse('Workflow not found', 404)
|
||||
}
|
||||
|
||||
logger.warn(`[${requestId}] Workflow exists but is not published: ${id}`)
|
||||
return createErrorResponse('Workflow is not published', 403)
|
||||
}
|
||||
|
||||
logger.info(`[${requestId}] Retrieved public workflow: ${id}`)
|
||||
|
||||
return createSuccessResponse({
|
||||
id: marketplaceEntry.workflowId,
|
||||
name: marketplaceEntry.name,
|
||||
description: marketplaceEntry.description,
|
||||
authorId: marketplaceEntry.authorId,
|
||||
authorName: marketplaceEntry.authorName,
|
||||
state: marketplaceEntry.state,
|
||||
isPublic: true,
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error(`[${requestId}] Error getting public workflow: ${(await params).id}`, error)
|
||||
return createErrorResponse('Failed to get public workflow', 500)
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ export async function DELETE(
|
||||
logger.info(`Deleted templates for workflows in workspace ${workspaceId}`)
|
||||
} else {
|
||||
// Set workflowId to null for templates to create "orphaned" templates
|
||||
// This allows templates to remain in marketplace but without source workflows
|
||||
// This allows templates to remain without source workflows
|
||||
await tx
|
||||
.update(templates)
|
||||
.set({ workflowId: null })
|
||||
@@ -260,7 +260,7 @@ export async function DELETE(
|
||||
// Delete all workflows in the workspace - database cascade will handle all workflow-related data
|
||||
// The database cascade will handle deleting related workflow_blocks, workflow_edges, workflow_subflows,
|
||||
// workflow_logs, workflow_execution_snapshots, workflow_execution_logs, workflow_execution_trace_spans,
|
||||
// workflow_schedule, webhook, marketplace, chat, and memory records
|
||||
// workflow_schedule, webhook, chat, and memory records
|
||||
await tx.delete(workflow).where(eq(workflow.workspaceId, workspaceId))
|
||||
|
||||
// Clear workspace ID from knowledge bases instead of deleting them
|
||||
|
||||
@@ -508,7 +508,6 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
|
||||
color: getNextWorkflowColor(),
|
||||
workspaceId, // Include the workspaceId in the new workflow
|
||||
folderId: sourceWorkflow.folderId, // Include the folderId from source workflow
|
||||
// Do not copy marketplace data
|
||||
}
|
||||
|
||||
// Get the current workflow state to copy from
|
||||
|
||||
1
packages/db/migrations/0122_pale_absorbing_man.sql
Normal file
1
packages/db/migrations/0122_pale_absorbing_man.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE "marketplace" CASCADE;
|
||||
7715
packages/db/migrations/meta/0122_snapshot.json
Normal file
7715
packages/db/migrations/meta/0122_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -848,6 +848,13 @@
|
||||
"when": 1765434895472,
|
||||
"tag": "0121_new_mantis",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 122,
|
||||
"version": "7",
|
||||
"when": 1765587157593,
|
||||
"tag": "0122_pale_absorbing_man",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -621,24 +621,6 @@ export const apiKey = pgTable(
|
||||
})
|
||||
)
|
||||
|
||||
export const marketplace = pgTable('marketplace', {
|
||||
id: text('id').primaryKey(),
|
||||
workflowId: text('workflow_id')
|
||||
.notNull()
|
||||
.references(() => workflow.id, { onDelete: 'cascade' }),
|
||||
state: json('state').notNull(),
|
||||
name: text('name').notNull(),
|
||||
description: text('description'),
|
||||
authorId: text('author_id')
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
authorName: text('author_name').notNull(),
|
||||
views: integer('views').notNull().default(0),
|
||||
category: text('category'),
|
||||
createdAt: timestamp('created_at').notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at').notNull().defaultNow(),
|
||||
})
|
||||
|
||||
export const billingBlockedReasonEnum = pgEnum('billing_blocked_reason', [
|
||||
'payment_failed',
|
||||
'dispute',
|
||||
|
||||
Reference in New Issue
Block a user