55Create Date: 2025-09-29 19:52:52.161683
66
77"""
8+
89from typing import Sequence , Union
910
1011import sqlalchemy as sa
1112from alembic import op
1213from sqlalchemy .dialects import postgresql
1314
1415# revision identifiers, used by Alembic.
15- revision : str = ' ded0314bce37'
16- down_revision : Union [str , None ] = ' seed_intake_forms'
16+ revision : str = " ded0314bce37"
17+ down_revision : Union [str , None ] = " seed_intake_forms"
1718branch_labels : Union [str , Sequence [str ], None ] = None
1819depends_on : Union [str , Sequence [str ], None ] = None
1920
2021
2122def upgrade () -> None :
2223 # Create task_type enum
23- op .execute ("CREATE TYPE task_type AS ENUM ('intake_form_review', 'volunteer_app_review', 'profile_update', 'matching')" )
24+ op .execute (
25+ "CREATE TYPE task_type AS ENUM ('intake_form_review', 'volunteer_app_review', 'profile_update', 'matching')"
26+ )
2427
2528 # Create task_priority enum
2629 op .execute ("CREATE TYPE task_priority AS ENUM ('low', 'medium', 'high', 'no_status')" )
@@ -30,41 +33,57 @@ def upgrade() -> None:
3033
3134 # Create tasks table
3235 op .create_table (
33- 'tasks' ,
34- sa .Column ('id' , sa .UUID (), nullable = False ),
35- sa .Column ('participant_id' , sa .UUID (), nullable = False ),
36- sa .Column ('type' , postgresql .ENUM ('intake_form_review' , 'volunteer_app_review' , 'profile_update' , 'matching' , name = 'task_type' ), nullable = False ),
37- sa .Column ('priority' , postgresql .ENUM ('low' , 'medium' , 'high' , 'no_status' , name = 'task_priority' ), nullable = False , server_default = 'no_status' ),
38- sa .Column ('assignee_id' , sa .UUID (), nullable = True ),
39- sa .Column ('start_date' , sa .DateTime (timezone = True ), nullable = False , server_default = sa .text ('now()' )),
40- sa .Column ('end_date' , sa .DateTime (timezone = True ), nullable = True ),
41- sa .Column ('status' , postgresql .ENUM ('pending' , 'in_progress' , 'completed' , name = 'task_status' ), nullable = False , server_default = 'pending' ),
42- sa .Column ('task_metadata' , postgresql .JSONB (astext_type = sa .Text ()), nullable = True ),
43- sa .Column ('created_at' , sa .DateTime (timezone = True ), nullable = False , server_default = sa .text ('now()' )),
44- sa .Column ('updated_at' , sa .DateTime (timezone = True ), nullable = False , server_default = sa .text ('now()' )),
45- sa .ForeignKeyConstraint (['assignee_id' ], ['users.id' ], ondelete = 'SET NULL' ),
46- sa .ForeignKeyConstraint (['participant_id' ], ['users.id' ], ondelete = 'CASCADE' ),
47- sa .PrimaryKeyConstraint ('id' )
36+ "tasks" ,
37+ sa .Column ("id" , sa .UUID (), nullable = False ),
38+ sa .Column ("participant_id" , sa .UUID (), nullable = False ),
39+ sa .Column (
40+ "type" ,
41+ postgresql .ENUM (
42+ "intake_form_review" , "volunteer_app_review" , "profile_update" , "matching" , name = "task_type"
43+ ),
44+ nullable = False ,
45+ ),
46+ sa .Column (
47+ "priority" ,
48+ postgresql .ENUM ("low" , "medium" , "high" , "no_status" , name = "task_priority" ),
49+ nullable = False ,
50+ server_default = "no_status" ,
51+ ),
52+ sa .Column ("assignee_id" , sa .UUID (), nullable = True ),
53+ sa .Column ("start_date" , sa .DateTime (timezone = True ), nullable = False , server_default = sa .text ("now()" )),
54+ sa .Column ("end_date" , sa .DateTime (timezone = True ), nullable = True ),
55+ sa .Column (
56+ "status" ,
57+ postgresql .ENUM ("pending" , "in_progress" , "completed" , name = "task_status" ),
58+ nullable = False ,
59+ server_default = "pending" ,
60+ ),
61+ sa .Column ("task_metadata" , postgresql .JSONB (astext_type = sa .Text ()), nullable = True ),
62+ sa .Column ("created_at" , sa .DateTime (timezone = True ), nullable = False , server_default = sa .text ("now()" )),
63+ sa .Column ("updated_at" , sa .DateTime (timezone = True ), nullable = False , server_default = sa .text ("now()" )),
64+ sa .ForeignKeyConstraint (["assignee_id" ], ["users.id" ], ondelete = "SET NULL" ),
65+ sa .ForeignKeyConstraint (["participant_id" ], ["users.id" ], ondelete = "CASCADE" ),
66+ sa .PrimaryKeyConstraint ("id" ),
4867 )
4968
5069 # Create indexes for common queries
51- op .create_index (' ix_tasks_participant_id' , ' tasks' , [' participant_id' ])
52- op .create_index (' ix_tasks_assignee_id' , ' tasks' , [' assignee_id' ])
53- op .create_index (' ix_tasks_type' , ' tasks' , [' type' ])
54- op .create_index (' ix_tasks_status' , ' tasks' , [' status' ])
55- op .create_index (' ix_tasks_priority' , ' tasks' , [' priority' ])
70+ op .create_index (" ix_tasks_participant_id" , " tasks" , [" participant_id" ])
71+ op .create_index (" ix_tasks_assignee_id" , " tasks" , [" assignee_id" ])
72+ op .create_index (" ix_tasks_type" , " tasks" , [" type" ])
73+ op .create_index (" ix_tasks_status" , " tasks" , [" status" ])
74+ op .create_index (" ix_tasks_priority" , " tasks" , [" priority" ])
5675
5776
5877def downgrade () -> None :
5978 # Drop indexes
60- op .drop_index (' ix_tasks_priority' , table_name = ' tasks' )
61- op .drop_index (' ix_tasks_status' , table_name = ' tasks' )
62- op .drop_index (' ix_tasks_type' , table_name = ' tasks' )
63- op .drop_index (' ix_tasks_assignee_id' , table_name = ' tasks' )
64- op .drop_index (' ix_tasks_participant_id' , table_name = ' tasks' )
79+ op .drop_index (" ix_tasks_priority" , table_name = " tasks" )
80+ op .drop_index (" ix_tasks_status" , table_name = " tasks" )
81+ op .drop_index (" ix_tasks_type" , table_name = " tasks" )
82+ op .drop_index (" ix_tasks_assignee_id" , table_name = " tasks" )
83+ op .drop_index (" ix_tasks_participant_id" , table_name = " tasks" )
6584
6685 # Drop tasks table
67- op .drop_table (' tasks' )
86+ op .drop_table (" tasks" )
6887
6988 # Drop enums
7089 op .execute ("DROP TYPE task_status" )
0 commit comments