Overview
Connection server actions handle database connection management, including deletion, schema retrieval, validation, and introspection.deleteConnection
Deletes a specific database connection from a project.Parameters
ID of the connection to delete
ID of the user requesting deletion (must own the parent project)
Validation
The connection ID is validated using theConnectionDeleteSchema:
Response
Indicates if deletion was successful
Success message with connection and project details
Error message (only when success is false)Possible errors:
"Invalid connection ID""Connection not found or you don't have permission to delete it""Failed to delete connection"
Behavior
- Ownership verification: Only the project owner can delete connections
- Cascade impact: Deleting a connection may affect widgets using that schema
- Revalidation: Automatically revalidates
/projectsand/projects/:idpaths
Example
getProjectSchema
Retrieves the stored database schema for a project from the first available connection with an introspected schema.Parameters
ID of the project to retrieve schema for
Response
Indicates if schema retrieval was successful
The database schema object (only when success is true)
Array of table definitions
Table name
Timestamp of the last schema introspection
Error message (only when success is false)Possible errors:
"Valid project ID is required""Project not found""No schema found for this project""Invalid schema format""Failed to fetch project schema"
Behavior
- Returns schema from the first connection with a non-null
dbSchemafield - Handles both JSON string and object formats for stored schemas
- Includes timestamp of last introspection
Example
Schemas are automatically introspected when connections are created or validated. Use
regenerateProjectSchemas to refresh.validateProjectConnections
Validates all database connections in a project by testing connectivity.Parameters
ID of the project to validate connections for
ID of the user requesting validation (must own the project)
Response
Indicates if validation process completed successfully
Number of valid connections
Total number of connections tested
Error message (only when success is false)
Behavior
- Parallel validation: Tests all connections concurrently using
Promise.allSettled - Connection test: Makes HTTP request to
/api/testdbconnectionfor each connection - No persistence: Results are returned but NOT saved to the database
- Read-only: Does not modify connection status in the database
Example
validateConnectionsQuietly
Validates connections and updates their status in the database without triggering UI updates.Parameters
ID of the project to validate connections for
ID of the user requesting validation (must own the project)
Response
Indicates if validation completed successfully
Number of valid connections
Total number of connections tested
Detailed status for each connection
Error message (only when success is false)
Behavior
- Database persistence: Updates each connection’s
isValid,validationError, andlastIntrospectionAtfields - Parallel validation: Tests all connections concurrently
- Background operation: Designed for silent validation after create/update operations
- No revalidation: Does not trigger Next.js path revalidation
- Empty project handling: Returns success with 0 connections if project has no connections
Example
This action is automatically called after
createProjectWithConnections and updateProject. You rarely need to call it directly.CreateDbSchema
Introspects a database connection to extract and store its schema (tables, columns, types).Parameters
ID of the database connection to introspect
Response
Returns the introspected schema data or throws an error.Array of table definitions extracted from the database
Behavior
- API call: Makes HTTP POST request to
/api/createschema - Database update: Stores schema in the connection’s
dbSchemafield - Timestamp update: Updates
lastIntrospectionAttimestamp - Error handling: Throws detailed error messages on failure
Errors
ThrowsError with descriptive messages:
"Invalid connection ID provided""API call failed with status {statusCode}""Failed to create database schema: {errorMessage}"
Example
Schema introspection is automatically triggered when connections are created or updated. Manual calls are only needed for schema refresh.
Type Definitions
Validation Schemas
Connection-related Zod schemas from@/lib/projects/schemas:
