Update User Status Tool (Testing)¶
This workflow provides a reliable way to update user onboarding status in the youth entrepreneurs database. It validates user existence, logs status changes for audit purposes, and handles errors gracefully when users cannot be found or updated.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves as a utility tool for updating user onboarding status in what appears to be a youth entrepreneurship program database. It ensures data integrity by validating user existence before making changes and maintains an audit trail of all status updates.
How It Works¶
- Receive Input: The workflow accepts a phone number and new onboarding status from another workflow
- Validate User: Checks if exactly one user exists with the provided phone number
- Branch Logic: If user exists, proceed with update; if not, return an error message
- Get User ID: Retrieves the user's database ID using their phone number
- Log Change: Records the status change in an audit log before making the update
- Update Status: Updates the user's onboarding status in the main database
- 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[Log Status Change]
F --> G[Insert or update rows in a table]
G --> H[Edit Fields1 - Success]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It expects two input parameters:
- phoneNumber: The user's phone number to identify them
- onboardingStatus: The new status to set for the user
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input parameters from calling workflow |
| Postgres | Execute a SQL query | Counts users with the given phone number for validation |
| If | If | Routes workflow based on whether exactly one user was found |
| Postgres | Execute a SQL query1 | Retrieves the user's ID for the update operation |
| Postgres | Log Status Change | Records the status change in the audit log |
| Postgres | Insert or update rows in a table | Updates the user's onboarding status |
| Set | Edit Fields | Formats error message when user is not found |
| Set | Edit Fields1 | Formats success message after successful update |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to a Postgres database with credentials named "kdpTestEnv"
- Database must contain tables:
youthEntrepreneursRealanduserStatusLog - User needs read/write permissions on both tables
- Database must contain tables:
Environment Variables¶
No environment variables are directly used in this workflow. All configuration is handled through the PostgreSQL credential connection.
Data Flow¶
Input:
- phoneNumber (string): User's phone number for identification
- onboardingStatus (string): New status value to set
Output:
- Success: "User status for phone number [phoneNumber] has been updated"
- Error: "Error updating user status"
Database Tables:
- youthEntrepreneursReal: Main user table containing user profiles and onboarding status
- userStatusLog: Audit table tracking all status changes with previous and new values
Error Handling¶
The workflow includes validation to ensure data integrity:
- User Validation: Checks that exactly one user exists with the provided phone number
- Error Path: If no user or multiple users are found, the workflow returns an error message instead of attempting an update
- Graceful Failure: Error conditions don't crash the workflow but return meaningful error messages
Known Limitations¶
- The workflow assumes phone numbers are unique identifiers in the database
- No validation is performed on the new onboarding status value
- The workflow name suggests this is for testing purposes and may not be production-ready
- Error handling is basic and doesn't distinguish between "no user found" and "multiple users found" scenarios
Related Workflows¶
This workflow is designed to be called by other workflows that need to update user status. The calling workflow must provide the required phone number and onboarding status parameters.
Setup Instructions¶
- Import Workflow: Import this workflow into your n8n instance
- Configure Database Credential:
- Create a PostgreSQL credential named "kdpTestEnv"
- Ensure it has access to the required database and tables
- Verify Database Schema: Ensure your database contains:
youthEntrepreneursRealtable with columns:id,phoneNumber,onboardingStatususerStatusLogtable with columns:phoneNumber,previousStatus,newStatus
- Test the Workflow: Call it from another workflow with test parameters:
1 2 3 4
{ "phoneNumber": "test-phone-number", "onboardingStatus": "new-status" } - Activate: Once tested, activate the workflow to make it available for other workflows to call