persistStateTool - Francis¶
A utility workflow that updates user state information in the youth entrepreneurs database. This workflow accepts various user parameters and persists them to the PostgreSQL database, providing a centralized way to maintain user progress and configuration data.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
-
Receives Input Parameters: The workflow is triggered by another workflow and receives up to 15 different user state parameters including phone number, current stage, day progress, routing decisions, and business metrics.
-
Updates Database: Executes a PostgreSQL UPDATE query that selectively updates only the provided parameters using COALESCE to preserve existing values for any null inputs. The query also calculates derived fields like daily fixed costs.
-
Returns Confirmation: Formats and returns a confirmation message showing the updated user's phone number, current stage, day, and onboarding status.
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[updateUserState]
B --> C[setOutput]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It accepts 15 input parameters related to user state and business metrics.
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input parameters from calling workflow |
| PostgreSQL | updateUserState | Updates user state in the youthEntrepreneursReal table |
| Set | setOutput | Formats confirmation message with updated state |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to Supabase PostgreSQL instance
- Credential:
PostgresOnSupabase(ID: Hw9XWerQ5RNHaVTk) - Access needed to
youthEntrepreneursRealtable with UPDATE permissions
- Credential:
Environment Variables¶
No environment variables are directly used in this workflow. Database connection details are managed through n8n credentials.
Data Flow¶
Input Parameters¶
phoneNumber(string) - User identifiercurrentStage(string) - Current program stagecurrentDay(number) - Day in current stageroutingDecision(string) - Routing logic decisionconsecutiveMissedDays(number) - Missed days counteronboardingStatus(string) - Onboarding progressinteractionFrequency(string) - How often user interactspreferredTime(string) - User's preferred interaction timeselfInitiated(boolean) - Whether interaction was user-initiatedmonthlyFixedCosts(number) - Monthly business costsbusinessDaysPerMonth(number) - Working days per monthstockType(string) - Type of stock/inventorydurableStockItems(string) - Durable inventory items (stored as JSON)practiceBaselineAvg(number) - Practice baseline averageceaEngagementStatus(string) - CEA engagement status
Output¶
output(string) - Formatted confirmation message containing phone number, current stage, current day, and onboarding status
Error Handling¶
The workflow uses basic PostgreSQL error handling. If the UPDATE query fails (e.g., due to invalid phone number or database connectivity issues), the workflow will stop at the updateUserState node. No custom error handling or retry logic is implemented.
Known Limitations¶
- No validation of input parameters before database update
- No error handling for database connection failures
- Assumes the phone number exists in the database (no INSERT capability)
- Limited feedback on which specific fields were updated
Related Workflows¶
This is a utility workflow designed to be called by other workflows in the system. The calling workflows are not specified in the current configuration.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance
-
Configure Database Credential:
- Create a PostgreSQL credential named
PostgresOnSupabase - Configure connection to your Supabase PostgreSQL instance
- Ensure the credential has UPDATE permissions on the
youthEntrepreneursRealtable
- Create a PostgreSQL credential named
-
Verify Database Schema: Ensure your database has the
youthEntrepreneursRealtable with the following columns:phoneNumber,currentStage,currentDay,routingDecisionconsecutiveMissedDays,onboardingStatus,interactionFrequencypreferredTime,selfInitiated,monthlyFixedCostsbusinessDaysPerMonth,dailyFixedCost,stockTypedurableStockItems,practiceBaselineAvg,ceaEngagementStatus
-
Test the Workflow: Execute from another workflow with sample parameters to verify database connectivity and update functionality
-
Integration: Call this workflow from other workflows using the "Execute Workflow" node, passing the required parameters as input