Skip to content

Execute Plan: Updated_at being manually updated (vibe-kanban) #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stunningpixels
Copy link
Contributor

Plan: Implement Automatic updated_at Triggers for SQLite Database

Current Findings Summary

Database Technology

  • SQLite - confirmed from Cargo.toml (sqlx with sqlite feature) and SqlitePool usage throughout the codebase

Tables with updated_at Columns

  1. projects - /private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-69ad-updated-at/backend/migrations/20250617183714_init.sql:9
  2. tasks - /private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-69ad-updated-at/backend/migrations/20250617183714_init.sql:20
  3. task_attempts - /private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-69ad-updated-at/backend/migrations/20250620214100_remove_stdout_stderr_from_task_attempts.sql:15
  4. execution_processes - /private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-69ad-updated-at/backend/migrations/20250620212427_execution_processes.sql:19
  5. task_templates - /private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-69ad-updated-at/backend/migrations/20250715154859_add_task_templates.sql:9
  6. executor_sessions - /private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-69ad-updated-at/backend/migrations/20250623120000_executor_sessions.sql:10

Current Manual Update Patterns

Heavy manual management - 15+ locations where updated_at is manually set:

execution_process.rs (4 manual updates):

  • Line 347: SET status = $1, exit_code = $2, completed_at = $3, updated_at = datetime('now')
  • Line 367: SET stdout = COALESCE(stdout, '') || $1, updated_at = datetime('now')
  • Line 384: SET stderr = COALESCE(stderr, '') || $1, updated_at = datetime('now')

task_attempt.rs (8 manual updates):

  • Line 276: SET worktree_deleted = TRUE, updated_at = datetime('now')
  • Line 579: SET merge_commit = $1, updated_at = datetime('now')
  • Line 654: SET worktree_path = $1, worktree_deleted = FALSE, setup_completed_at = NULL, updated_at = datetime('now')
  • Line 841: SET base_branch = $1, updated_at = datetime('now')
  • Line 923: SET pr_url = $1, pr_number = $2, pr_status = $3, updated_at = datetime('now')
  • Line 958: SET pr_status = $1, pr_merged_at = $2, merge_commit = $3, updated_at = datetime('now')
  • Line 1096: SET setup_completed_at = datetime('now'), updated_at = datetime('now')

task_template.rs (1 manual update):

  • Line 127: SET title = $2, description = $3, template_name = $4, updated_at = datetime('now', 'subsec')

executor_session.rs (3 manual updates):

  • Line 160: SET session_id = $1, updated_at = datetime('now')
  • Line 180: SET prompt = $1, updated_at = datetime('now')
  • Line 199: SET summary = $1, updated_at = datetime('now')

task.rs (1 manual update):

  • Line 245: SET status = $3, updated_at = CURRENT_TIMESTAMP

Missing manual updates: projects table update function doesn't manually set updated_at (Line 167 in project.rs)

Implementation Plan

1. Create SQLite Triggers Migration

Create a new migration file that will:

  • Add AFTER UPDATE triggers for each table with updated_at columns
  • Use SQLite's datetime('now', 'subsec') for consistency with existing patterns
  • Handle the case where updated_at is already being explicitly set

2. Update Strategy

  • Phase 1: Add triggers (this ensures automatic updates going forward)
  • Phase 2: Clean up manual updated_at assignments in the codebase (separate task)
  • This approach ensures no downtime and gradual transition

3. Migration Details

The migration will create triggers for:

  • projects_updated_at_trigger
  • tasks_updated_at_trigger
  • task_attempts_updated_at_trigger
  • execution_processes_updated_at_trigger
  • task_templates_updated_at_trigger
  • executor_sessions_updated_at_trigger

Each trigger will:

  1. Fire on UPDATE operations
  2. Only update updated_at when the row actually changes (using NEW.* != OLD.* comparisons)
  3. Avoid infinite recursion by checking if updated_at was manually set

4. Verification

After implementing triggers:

  • All existing manual updates will continue working (no breaking changes)
  • Any missed manual updates will be automatically handled
  • Future developers won't need to remember to manually update updated_at

Would you like me to proceed with creating this migration?

…tables in the SQLite database.

**Created migration:** [`backend/migrations/20250719000000_add_updated_at_triggers.sql`](file:///private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-06e4-execute-pl/backend/migrations/20250719000000_add_updated_at_triggers.sql)

**Key features:**
- Triggers only fire when `updated_at` hasn't been manually changed (using `WHEN NEW.updated_at = OLD.updated_at`)
- Uses `datetime('now', 'subsec')` for consistency with existing patterns
- Covers all tables: projects, tasks, task_attempts, execution_processes, task_templates, executor_sessions
- Backward compatible - existing manual updates continue working

The migration passed compilation checks and is ready to be applied to the database.
**Removed 17 manual `updated_at` assignments from:**
- [`execution_process.rs`](file:///private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-06e4-execute-pl/backend/src/models/execution_process.rs) (3 locations)
- [`task_attempt.rs`](file:///private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-06e4-execute-pl/backend/src/models/task_attempt.rs) (7 locations)  
- [`task_template.rs`](file:///private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-06e4-execute-pl/backend/src/models/task_template.rs) (1 location)
- [`executor_session.rs`](file:///private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-06e4-execute-pl/backend/src/models/executor_session.rs) (3 locations)
- [`task.rs`](file:///private/var/folders/kr/jdxkcn7129j376nrg0stj9zm0000gn/T/vibe-kanban/vk-06e4-execute-pl/backend/src/models/task.rs) (1 location)

The automatic triggers now handle all `updated_at` updates, eliminating the need for manual maintenance and reducing potential bugs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant