mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 11:07:55 -05:00
92 lines
4.2 KiB
Python
92 lines
4.2 KiB
Python
"""add tasks
|
|
|
|
Revision ID: d8f2a6c41e7b
|
|
Revises: b7e4c2a9d1f3
|
|
Create Date: 2026-12-04 12:00:00
|
|
|
|
A task is a unit of work that lives in a folder, numbered per folder from the folder's
|
|
task_counter, so a number is never reused. Its status is an id from the folder's statuses,
|
|
which also say its category. Its history keeps one row per changed field, as Jira does:
|
|
the value the task held, and the name it went by then when that value is an id.
|
|
A chat started from a task points back to it with task_id.
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = 'd8f2a6c41e7b'
|
|
down_revision: str | None = 'b7e4c2a9d1f3'
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
inspector = sa.inspect(op.get_bind())
|
|
existing_tables = set(inspector.get_table_names())
|
|
|
|
if 'task' not in existing_tables:
|
|
op.create_table(
|
|
'task',
|
|
sa.Column('id', sa.Text(), primary_key=True, nullable=False),
|
|
sa.Column('folder_id', sa.Text(), nullable=False),
|
|
sa.Column('number', sa.BigInteger(), nullable=False),
|
|
sa.Column('user_id', sa.Text(), nullable=False),
|
|
sa.Column('title', sa.Text(), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=True),
|
|
sa.Column('status', sa.Text(), nullable=False),
|
|
sa.Column('priority', sa.Text(), nullable=True),
|
|
sa.Column('assignee_id', sa.Text(), nullable=True),
|
|
sa.Column('due_date', sa.Text(), nullable=True),
|
|
sa.Column('status_at', sa.BigInteger(), nullable=False),
|
|
sa.Column('status_durations', sa.JSON(), nullable=True),
|
|
sa.Column('started_at', sa.BigInteger(), nullable=True),
|
|
sa.Column('completed_at', sa.BigInteger(), nullable=True),
|
|
sa.Column('canceled_at', sa.BigInteger(), nullable=True),
|
|
sa.Column('data', sa.JSON(), nullable=True),
|
|
sa.Column('meta', sa.JSON(), nullable=True),
|
|
sa.Column('created_at', sa.BigInteger(), nullable=False),
|
|
sa.Column('updated_at', sa.BigInteger(), nullable=False),
|
|
sa.UniqueConstraint('folder_id', 'number', name='uq_task_folder_number'),
|
|
)
|
|
op.create_index('ix_task_assignee_id', 'task', ['assignee_id'])
|
|
op.create_index('ix_task_user_id', 'task', ['user_id'])
|
|
|
|
if 'task_history' not in existing_tables:
|
|
op.create_table(
|
|
'task_history',
|
|
sa.Column('id', sa.Text(), primary_key=True, nullable=False),
|
|
sa.Column('task_id', sa.Text(), sa.ForeignKey('task.id', ondelete='CASCADE'), nullable=False),
|
|
sa.Column('user_id', sa.Text(), nullable=True),
|
|
sa.Column('field', sa.Text(), nullable=False),
|
|
sa.Column('old_value', sa.Text(), nullable=True),
|
|
sa.Column('new_value', sa.Text(), nullable=True),
|
|
sa.Column('old_name', sa.Text(), nullable=True),
|
|
sa.Column('new_name', sa.Text(), nullable=True),
|
|
sa.Column('created_at', sa.BigInteger(), nullable=False),
|
|
)
|
|
op.create_index('ix_task_history_task_id_created_at', 'task_history', ['task_id', 'created_at'])
|
|
|
|
folder_columns = {column['name'] for column in inspector.get_columns('folder')}
|
|
if 'task_counter' not in folder_columns:
|
|
op.add_column('folder', sa.Column('task_counter', sa.BigInteger(), nullable=False, server_default='0'))
|
|
|
|
chat_columns = {column['name'] for column in inspector.get_columns('chat')}
|
|
if 'task_id' not in chat_columns:
|
|
op.add_column('chat', sa.Column('task_id', sa.Text(), nullable=True))
|
|
op.create_index('ix_chat_task_id', 'chat', ['task_id'])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index('ix_chat_task_id', table_name='chat')
|
|
with op.batch_alter_table('chat') as batch:
|
|
batch.drop_column('task_id')
|
|
with op.batch_alter_table('folder') as batch:
|
|
batch.drop_column('task_counter')
|
|
op.drop_index('ix_task_history_task_id_created_at', table_name='task_history')
|
|
op.drop_table('task_history')
|
|
op.drop_index('ix_task_user_id', table_name='task')
|
|
op.drop_index('ix_task_assignee_id', table_name='task')
|
|
op.drop_table('task')
|