updateUserDataTool¶
A workflow that safely updates user profile information in the youth entrepreneurs database by validating the user exists before making changes.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow provides a controlled way to update user profile data in the youthEntrepreneursReal table. It ensures data integrity by first verifying that exactly one user record exists for the given phone number before proceeding with the update. The workflow is designed to be called by other workflows that need to modify user information such as names and business details.
How It Works¶
- Receive Input: The workflow accepts user data including phone number, first name, second name, and business information
- Validate User Exists: Queries the database to count how many records exist for the provided phone number
- Check Count: Verifies that exactly one user record exists (not zero, not multiple)
- Update or Error: If validation passes, retrieves the user ID and updates their profile; if validation fails, returns an error message
- Confirm Success: Returns a success message with the updated phone number
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[Execute a SQL query]
B --> C[If]
C -->|User Found| D[Execute a SQL query1]
C -->|User Not Found| E[Edit Fields - Error]
D --> F[Insert or update rows in a table]
F --> G[Edit Fields1 - Success]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It expects the following input parameters:
- phoneNumber - The user's phone number (used as identifier)
- firstName - Updated first name
- secondName - Updated second name
- businessOwned - Updated business information
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input parameters from calling workflow |
| PostgreSQL | Execute a SQL query | Counts existing records for the phone number |
| If | If | Validates that exactly one user record exists |
| PostgreSQL | Execute a SQL query1 | Retrieves the user ID for the update |
| PostgreSQL | Insert or update rows in a table | Updates the user's profile information |
| Set | Edit Fields | Returns error message when validation fails |
| Set | Edit Fields1 | Returns success message when update completes |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to Supabase PostgreSQL instance
- Credential:
PostgresOnSupabase(ID: Hw9XWerQ5RNHaVTk) - Access needed to
youthEntrepreneursRealtable for read and write operations
- Credential:
Environment Variables¶
No environment variables are directly used in this workflow. Database connection details are managed through n8n credentials.
Data Flow¶
Input:
1 2 3 4 5 6 | |
Success Output:
1 2 3 | |
Error Output:
1 2 3 | |
Error Handling¶
The workflow includes validation to prevent data corruption:
- User Not Found: If no user exists with the provided phone number, returns error message
- Multiple Users: If multiple users exist with the same phone number, returns error message
- Database Errors: Any SQL execution failures will cause the workflow to stop with an error
The conditional logic ensures updates only occur when exactly one matching user record is found.
Known Limitations¶
- Phone number must exactly match the stored format in the database
- Only updates specific fields (firstName, secondName, businessOwned, channel)
- No validation of input data format or content
- Error messages are generic and don't specify the exact validation failure
Related Workflows¶
This workflow is designed to be called by other workflows that need to update user data. Look for workflows that use the "Execute Workflow" node pointing to this workflow.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named "PostgresOnSupabase"
- Configure connection to your Supabase PostgreSQL instance
- Ensure access to the
youthEntrepreneursRealtable
-
Verify Database Schema: Ensure your database has the
youthEntrepreneursRealtable with these columns:id(primary key)phoneNumber(string)firstName(string)secondName(string)businessOwned(string)channel(string)
-
Test the Workflow:
- Use the pinned test data or create your own
- Verify both success and error scenarios
- Check that database updates are applied correctly
-
Integration: Call this workflow from other workflows using the "Execute Workflow" node with the required input parameters