1-
21"""Initial schema
32
43Revision ID: 20250617
54Revises:
65Create Date: 2025-06-17 15:00:00.000000
76
87"""
9- from alembic import op
10- import sqlalchemy as sa
8+
119import json
1210
11+ import sqlalchemy as sa
12+
13+ from alembic import op
14+
1315# revision identifiers, used by Alembic.
14- revision = ' 20250617'
16+ revision = " 20250617"
1517down_revision = None
1618branch_labels = None
1719depends_on = None
1820
1921
2022def upgrade () -> None :
2123 # ### commands auto-generated by Alembic - please adjust! ###
22- op .create_table ('active_context' ,
23- sa .Column ('id' , sa .Integer (), nullable = False ),
24- sa .Column ('content' , sa .Text (), nullable = False ),
25- sa .PrimaryKeyConstraint ('id' )
24+ op .create_table (
25+ "active_context" ,
26+ sa .Column ("id" , sa .Integer (), nullable = False ),
27+ sa .Column ("content" , sa .Text (), nullable = False ),
28+ sa .PrimaryKeyConstraint ("id" ),
29+ )
30+ op .create_table (
31+ "active_context_history" ,
32+ sa .Column ("id" , sa .Integer (), nullable = False ),
33+ sa .Column ("timestamp" , sa .DateTime (), nullable = False ),
34+ sa .Column ("version" , sa .Integer (), nullable = False ),
35+ sa .Column ("content" , sa .Text (), nullable = False ),
36+ sa .Column ("change_source" , sa .String (length = 255 ), nullable = True ),
37+ sa .PrimaryKeyConstraint ("id" ),
38+ )
39+ op .create_table (
40+ "context_links" ,
41+ sa .Column ("id" , sa .Integer (), nullable = False ),
42+ sa .Column ("workspace_id" , sa .String (length = 1024 ), nullable = False ),
43+ sa .Column ("source_item_type" , sa .String (length = 255 ), nullable = False ),
44+ sa .Column ("source_item_id" , sa .String (length = 255 ), nullable = False ),
45+ sa .Column ("target_item_type" , sa .String (length = 255 ), nullable = False ),
46+ sa .Column ("target_item_id" , sa .String (length = 255 ), nullable = False ),
47+ sa .Column ("relationship_type" , sa .String (length = 255 ), nullable = False ),
48+ sa .Column ("description" , sa .Text (), nullable = True ),
49+ sa .Column (
50+ "timestamp" ,
51+ sa .DateTime (),
52+ server_default = sa .text ("(CURRENT_TIMESTAMP)" ),
53+ nullable = False ,
54+ ),
55+ sa .PrimaryKeyConstraint ("id" ),
2656 )
27- op .create_table ('active_context_history' ,
28- sa .Column ('id' , sa .Integer (), nullable = False ),
29- sa .Column ('timestamp' , sa .DateTime (), nullable = False ),
30- sa .Column ('version' , sa .Integer (), nullable = False ),
31- sa .Column ('content' , sa .Text (), nullable = False ),
32- sa .Column ('change_source' , sa .String (length = 255 ), nullable = True ),
33- sa .PrimaryKeyConstraint ('id' )
57+ op .create_index (
58+ op .f ("ix_context_links_source_item_id" ),
59+ "context_links" ,
60+ ["source_item_id" ],
61+ unique = False ,
3462 )
35- op .create_table ('context_links' ,
36- sa .Column ('id' , sa .Integer (), nullable = False ),
37- sa .Column ('workspace_id' , sa .String (length = 1024 ), nullable = False ),
38- sa .Column ('source_item_type' , sa .String (length = 255 ), nullable = False ),
39- sa .Column ('source_item_id' , sa .String (length = 255 ), nullable = False ),
40- sa .Column ('target_item_type' , sa .String (length = 255 ), nullable = False ),
41- sa .Column ('target_item_id' , sa .String (length = 255 ), nullable = False ),
42- sa .Column ('relationship_type' , sa .String (length = 255 ), nullable = False ),
43- sa .Column ('description' , sa .Text (), nullable = True ),
44- sa .Column ('timestamp' , sa .DateTime (), server_default = sa .text ('(CURRENT_TIMESTAMP)' ), nullable = False ),
45- sa .PrimaryKeyConstraint ('id' )
63+ op .create_index (
64+ op .f ("ix_context_links_source_item_type" ),
65+ "context_links" ,
66+ ["source_item_type" ],
67+ unique = False ,
4668 )
47- op .create_index (op .f ('ix_context_links_source_item_id' ), 'context_links' , ['source_item_id' ], unique = False )
48- op .create_index (op .f ('ix_context_links_source_item_type' ), 'context_links' , ['source_item_type' ], unique = False )
49- op .create_index (op .f ('ix_context_links_target_item_id' ), 'context_links' , ['target_item_id' ], unique = False )
50- op .create_index (op .f ('ix_context_links_target_item_type' ), 'context_links' , ['target_item_type' ], unique = False )
51- op .create_table ('custom_data' ,
52- sa .Column ('id' , sa .Integer (), nullable = False ),
53- sa .Column ('timestamp' , sa .DateTime (), nullable = False ),
54- sa .Column ('category' , sa .String (length = 255 ), nullable = False ),
55- sa .Column ('key' , sa .String (length = 255 ), nullable = False ),
56- sa .Column ('value' , sa .Text (), nullable = False ),
57- sa .PrimaryKeyConstraint ('id' ),
58- sa .UniqueConstraint ('category' , 'key' )
69+ op .create_index (
70+ op .f ("ix_context_links_target_item_id" ),
71+ "context_links" ,
72+ ["target_item_id" ],
73+ unique = False ,
5974 )
60- op .create_table ('decisions' ,
61- sa .Column ('id' , sa .Integer (), nullable = False ),
62- sa .Column ('timestamp' , sa .DateTime (), nullable = False ),
63- sa .Column ('summary' , sa .Text (), nullable = False ),
64- sa .Column ('rationale' , sa .Text (), nullable = True ),
65- sa .Column ('implementation_details' , sa .Text (), nullable = True ),
66- sa .Column ('tags' , sa .Text (), nullable = True ),
67- sa .PrimaryKeyConstraint ('id' )
75+ op .create_index (
76+ op .f ("ix_context_links_target_item_type" ),
77+ "context_links" ,
78+ ["target_item_type" ],
79+ unique = False ,
6880 )
69- op .create_table ('product_context' ,
70- sa .Column ('id' , sa .Integer (), nullable = False ),
71- sa .Column ('content' , sa .Text (), nullable = False ),
72- sa .PrimaryKeyConstraint ('id' )
81+ op .create_table (
82+ "custom_data" ,
83+ sa .Column ("id" , sa .Integer (), nullable = False ),
84+ sa .Column ("timestamp" , sa .DateTime (), nullable = False ),
85+ sa .Column ("category" , sa .String (length = 255 ), nullable = False ),
86+ sa .Column ("key" , sa .String (length = 255 ), nullable = False ),
87+ sa .Column ("value" , sa .Text (), nullable = False ),
88+ sa .PrimaryKeyConstraint ("id" ),
89+ sa .UniqueConstraint ("category" , "key" ),
7390 )
74- op .create_table ('product_context_history' ,
75- sa .Column ('id' , sa .Integer (), nullable = False ),
76- sa .Column ('timestamp' , sa .DateTime (), nullable = False ),
77- sa .Column ('version' , sa .Integer (), nullable = False ),
78- sa .Column ('content' , sa .Text (), nullable = False ),
79- sa .Column ('change_source' , sa .String (length = 255 ), nullable = True ),
80- sa .PrimaryKeyConstraint ('id' )
91+ op .create_table (
92+ "decisions" ,
93+ sa .Column ("id" , sa .Integer (), nullable = False ),
94+ sa .Column ("timestamp" , sa .DateTime (), nullable = False ),
95+ sa .Column ("summary" , sa .Text (), nullable = False ),
96+ sa .Column ("rationale" , sa .Text (), nullable = True ),
97+ sa .Column ("implementation_details" , sa .Text (), nullable = True ),
98+ sa .Column ("tags" , sa .Text (), nullable = True ),
99+ sa .PrimaryKeyConstraint ("id" ),
81100 )
82- op .create_table ('progress_entries' ,
83- sa .Column ('id' , sa .Integer (), nullable = False ),
84- sa .Column ('timestamp' , sa .DateTime (), nullable = False ),
85- sa .Column ('status' , sa .String (length = 50 ), nullable = False ),
86- sa .Column ('description' , sa .Text (), nullable = False ),
87- sa .Column ('parent_id' , sa .Integer (), nullable = True ),
88- sa .ForeignKeyConstraint (['parent_id' ], ['progress_entries.id' ], ondelete = 'SET NULL' ),
89- sa .PrimaryKeyConstraint ('id' )
101+ op .create_table (
102+ "product_context" ,
103+ sa .Column ("id" , sa .Integer (), nullable = False ),
104+ sa .Column ("content" , sa .Text (), nullable = False ),
105+ sa .PrimaryKeyConstraint ("id" ),
90106 )
91- op .create_table ('system_patterns' ,
92- sa . Column ( 'id' , sa . Integer (), nullable = False ) ,
93- sa .Column ('timestamp' , sa .DateTime (), nullable = False ),
94- sa .Column ('name' , sa .String ( length = 255 ), nullable = False ),
95- sa .Column ('description' , sa .Text (), nullable = True ),
96- sa .Column ('tags' , sa .Text (), nullable = True ),
97- sa .PrimaryKeyConstraint ( 'id' ),
98- sa .UniqueConstraint ( 'name' )
107+ op .create_table (
108+ "product_context_history" ,
109+ sa .Column ("id" , sa .Integer (), nullable = False ),
110+ sa .Column ("timestamp" , sa .DateTime ( ), nullable = False ),
111+ sa .Column ("version" , sa .Integer (), nullable = False ),
112+ sa .Column ("content" , sa .Text (), nullable = False ),
113+ sa .Column ( "change_source" , sa . String ( length = 255 ), nullable = True ),
114+ sa .PrimaryKeyConstraint ( "id" ),
99115 )
100-
116+ op .create_table (
117+ "progress_entries" ,
118+ sa .Column ("id" , sa .Integer (), nullable = False ),
119+ sa .Column ("timestamp" , sa .DateTime (), nullable = False ),
120+ sa .Column ("status" , sa .String (length = 50 ), nullable = False ),
121+ sa .Column ("description" , sa .Text (), nullable = False ),
122+ sa .Column ("parent_id" , sa .Integer (), nullable = True ),
123+ sa .ForeignKeyConstraint (
124+ ["parent_id" ], ["progress_entries.id" ], ondelete = "SET NULL"
125+ ),
126+ sa .PrimaryKeyConstraint ("id" ),
127+ )
128+ op .create_table (
129+ "system_patterns" ,
130+ sa .Column ("id" , sa .Integer (), nullable = False ),
131+ sa .Column ("timestamp" , sa .DateTime (), nullable = False ),
132+ sa .Column ("name" , sa .String (length = 255 ), nullable = False ),
133+ sa .Column ("description" , sa .Text (), nullable = True ),
134+ sa .Column ("tags" , sa .Text (), nullable = True ),
135+ sa .PrimaryKeyConstraint ("id" ),
136+ sa .UniqueConstraint ("name" ),
137+ )
138+
101139 # Seed initial data
102140 op .execute ("INSERT INTO product_context (id, content) VALUES (1, '{}')" )
103141 op .execute ("INSERT INTO active_context (id, content) VALUES (1, '{}')" )
@@ -106,17 +144,17 @@ def upgrade() -> None:
106144
107145def downgrade () -> None :
108146 # ### commands auto-generated by Alembic - please adjust! ###
109- op .drop_table (' system_patterns' )
110- op .drop_table (' progress_entries' )
111- op .drop_table (' product_context_history' )
112- op .drop_table (' product_context' )
113- op .drop_table (' decisions' )
114- op .drop_table (' custom_data' )
115- op .drop_index (op .f (' ix_context_links_target_item_type' ), table_name = ' context_links' )
116- op .drop_index (op .f (' ix_context_links_target_item_id' ), table_name = ' context_links' )
117- op .drop_index (op .f (' ix_context_links_source_item_type' ), table_name = ' context_links' )
118- op .drop_index (op .f (' ix_context_links_source_item_id' ), table_name = ' context_links' )
119- op .drop_table (' context_links' )
120- op .drop_table (' active_context_history' )
121- op .drop_table (' active_context' )
147+ op .drop_table (" system_patterns" )
148+ op .drop_table (" progress_entries" )
149+ op .drop_table (" product_context_history" )
150+ op .drop_table (" product_context" )
151+ op .drop_table (" decisions" )
152+ op .drop_table (" custom_data" )
153+ op .drop_index (op .f (" ix_context_links_target_item_type" ), table_name = " context_links" )
154+ op .drop_index (op .f (" ix_context_links_target_item_id" ), table_name = " context_links" )
155+ op .drop_index (op .f (" ix_context_links_source_item_type" ), table_name = " context_links" )
156+ op .drop_index (op .f (" ix_context_links_source_item_id" ), table_name = " context_links" )
157+ op .drop_table (" context_links" )
158+ op .drop_table (" active_context_history" )
159+ op .drop_table (" active_context" )
122160 # ### end Alembic commands ###
0 commit comments