Skip to content

Commit 91ff1a6

Browse files
committed
feat: add map step type in sql
1 parent 08a197e commit 91ff1a6

16 files changed

+788
-415
lines changed

.changeset/yummy-geckos-marry.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
'@pgflow/core': patch
3+
---
4+
5+
Add map step type infrastructure in SQL core
6+
7+
## 🚨🚨🚨 CRITICAL MIGRATION WARNING 🚨🚨🚨
8+
9+
**THIS MIGRATION REQUIRES MANUAL DATA UPDATE BEFORE DEPLOYMENT!**
10+
11+
The migration adds a new constraint `remaining_tasks_state_consistency` that will **FAIL ON EXISTING DATA** if not handled properly.
12+
13+
### Required Data Migration:
14+
15+
Before applying this migration to any environment with existing data, you MUST include:
16+
17+
```sql
18+
-- CRITICAL: Update existing step_states to satisfy new constraint
19+
UPDATE pgflow.step_states
20+
SET remaining_tasks = NULL
21+
WHERE status = 'created';
22+
```
23+
24+
**Without this update, the migration WILL FAIL in production!** The new constraint requires that `remaining_tasks` can only be set when `status != 'created'`.
25+
26+
---
27+
28+
## Changes
29+
30+
This patch introduces the foundation for map step functionality in the SQL core layer:
31+
32+
### Schema Changes
33+
- Added `step_type` column to `steps` table with constraint allowing 'single' or 'map' values
34+
- Added `initial_tasks` column to `step_states` table (defaults to 1, stores planned task count)
35+
- Modified `remaining_tasks` column to be nullable (NULL = not started, >0 = active countdown)
36+
- Added constraint `remaining_tasks_state_consistency` to ensure `remaining_tasks` is only set when step has started
37+
- Removed `only_single_task_per_step` constraint from `step_tasks` table to allow multiple tasks per step
38+
39+
### Function Updates
40+
- **`add_step()`**: Now accepts `step_type` parameter (defaults to 'single') with validation that map steps can have at most 1 dependency
41+
- **`start_flow()`**: Sets `initial_tasks = 1` for all steps (map step array handling will come in future phases)
42+
- **`start_ready_steps()`**: Copies `initial_tasks` to `remaining_tasks` when starting a step, maintaining proper task counting semantics
43+
44+
### Testing
45+
- Added comprehensive test coverage for map step creation and validation
46+
- All existing tests pass with the new schema changes
47+
- Tests validate the new step_type parameter and dependency constraints for map steps
48+
49+
This is Phase 2a of the map step implementation, establishing the SQL infrastructure needed for parallel task execution in future phases.

0 commit comments

Comments
 (0)