MCPcopy Index your code
hub / github.com/simstudioai/sim / renameTable

Function renameTable

apps/sim/lib/table/service.ts:498–528  ·  view source on GitHub ↗
(
  tableId: string,
  newName: string,
  requestId: string
)

Source from the content-addressed store, hash-verified

496 * @throws Error if name is invalid
497 */
498export async function renameTable(
499 tableId: string,
500 newName: string,
501 requestId: string
502): Promise<{ id: string; name: string }> {
503 const nameValidation = validateTableName(newName)
504 if (!nameValidation.valid) {
505 throw new Error(nameValidation.errors.join(', '))
506 }
507
508 const now = new Date()
509 try {
510 const result = await db
511 .update(userTableDefinitions)
512 .set({ name: newName, updatedAt: now })
513 .where(eq(userTableDefinitions.id, tableId))
514 .returning({ id: userTableDefinitions.id })
515
516 if (result.length === 0) {
517 throw new Error(`Table ${tableId} not found`)
518 }
519
520 logger.info(`[${requestId}] Renamed table ${tableId} to "${newName}"`)
521 return { id: tableId, name: newName }
522 } catch (error: unknown) {
523 if (getPostgresErrorCode(error) === '23505') {
524 throw new TableConflictError(newName)
525 }
526 throw error
527 }
528}
529
530/**
531 * Updates a table's metadata (UI state like column widths/order, plus behavioral

Callers 2

executeFunction · 0.90
route.tsFile · 0.90

Calls 6

validateTableNameFunction · 0.90
getPostgresErrorCodeFunction · 0.90
joinMethod · 0.80
infoMethod · 0.80
setMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected