[Schema] Tree Forking Model - Database Schema #36

Closed
opened 2026-02-07 22:46:47 +00:00 by chihlasm · 1 comment
chihlasm commented 2026-02-07 22:46:47 +00:00 (Migrated from github.com)

Overview

Implement tree forking schema to enable engineers to fork company trees, customize them, and track parent tree updates.

Design Document

See: docs/plans/2026-02-07-foundational-schema-design.md (Part 1)

Database Changes

Migration 022: Add Tree Forking Fields

Add three columns to trees table:

  • parent_tree_id (UUID nullable, FK to trees.id, ondelete SET NULL)
  • fork_reason (String 255)
  • parent_updated_at (Datetime nullable)

Index: ix_trees_parent_tree_id

Model Updates

  • Add self-referential relationship on Tree model
  • parent relationship (many-to-one)
  • forks relationship (one-to-many)

Key Behaviors

  • Fork creation: copy tree_structure, set parent_tree_id, snapshot parent_updated_at
  • Parent deletion: orphan forks (parent_tree_id → NULL)
  • Update detection: compare fork.parent_updated_at vs parent.updated_at

Acceptance Criteria

  • Migration 022 created and tested
  • Tree model updated with new fields
  • Self-referential relationship working
  • Fork creation sets all fields correctly
  • Parent hard delete orphans forks
  • Parent soft delete preserves parent_tree_id
  • Update detection logic implemented

Part of foundational schema work (Issue #11)

## Overview Implement tree forking schema to enable engineers to fork company trees, customize them, and track parent tree updates. ## Design Document See: `docs/plans/2026-02-07-foundational-schema-design.md` (Part 1) ## Database Changes ### Migration 022: Add Tree Forking Fields Add three columns to `trees` table: - `parent_tree_id` (UUID nullable, FK to trees.id, ondelete SET NULL) - `fork_reason` (String 255) - `parent_updated_at` (Datetime nullable) **Index**: `ix_trees_parent_tree_id` ### Model Updates - Add self-referential relationship on Tree model - `parent` relationship (many-to-one) - `forks` relationship (one-to-many) ## Key Behaviors - Fork creation: copy tree_structure, set parent_tree_id, snapshot parent_updated_at - Parent deletion: orphan forks (parent_tree_id → NULL) - Update detection: compare fork.parent_updated_at vs parent.updated_at ## Acceptance Criteria - [ ] Migration 022 created and tested - [ ] Tree model updated with new fields - [ ] Self-referential relationship working - [ ] Fork creation sets all fields correctly - [ ] Parent hard delete orphans forks - [ ] Parent soft delete preserves parent_tree_id - [ ] Update detection logic implemented ## Related Issues Part of foundational schema work (Issue #11)
chihlasm commented 2026-02-08 00:40:49 +00:00 (Migrated from github.com)

Completed in PR #39. Migration 022 adds parent_tree_id, root_tree_id, fork_depth, fork_reason, and parent_updated_at to the trees table. Self-referential relationships working with 9 passing tests covering fork creation, lineage, access control, and structure preservation.

Completed in PR #39. Migration 022 adds `parent_tree_id`, `root_tree_id`, `fork_depth`, `fork_reason`, and `parent_updated_at` to the trees table. Self-referential relationships working with 9 passing tests covering fork creation, lineage, access control, and structure preservation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: chihlasm/resolutionflow#36