Backend features: - Tree sharing via secure tokens with expiration (Issue #16) - Draft tree status with conditional validation (Issue #25) - Save session as custom tree with fork tracking (Issue #17) - Tree validation system for publish requirements - Session-to-tree conversion preserving custom steps Database migrations: - 024: Tree sharing (tree_shares table, visibility field) - 025: Tree status field (draft/published) - 25b: Merge migration for indexes New endpoints: - POST /api/v1/trees/{id}/share - Generate share token - GET /api/v1/shared/{token} - Public tree access - POST /api/v1/trees/{id}/can-publish - Validate tree - POST /api/v1/sessions/{id}/save-as-tree - Convert session Test coverage: - 20 tests for draft trees functionality - 14 tests for session-to-tree conversion - 15 tests for tree sharing Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""add tree status field for draft/published workflow
|
|
|
|
Revision ID: 025
|
|
Revises: 25b001abd0f7
|
|
Create Date: 2026-02-08
|
|
|
|
Adds status field to trees table for draft/published workflow:
|
|
- status: enum ('draft', 'published') - defaults to 'published' for existing trees
|
|
- Drafts allow incomplete/invalid structures for work-in-progress
|
|
- Published trees require validation before saving
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '025'
|
|
down_revision: Union[str, None] = '25b001abd0f7'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Add status field with default 'published' (for backward compatibility)
|
|
op.add_column('trees', sa.Column(
|
|
'status',
|
|
sa.String(20),
|
|
nullable=False,
|
|
server_default='published',
|
|
comment="Status: draft (work in progress) or published (validated and available)"
|
|
))
|
|
op.create_index('ix_trees_status', 'trees', ['status'])
|
|
|
|
# Add CHECK constraint for status values
|
|
op.create_check_constraint(
|
|
'ck_trees_status',
|
|
'trees',
|
|
"status IN ('draft', 'published')"
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index('ix_trees_status', table_name='trees')
|
|
op.drop_constraint('ck_trees_status', 'trees', type_='check')
|
|
op.drop_column('trees', 'status')
|