1- """v13_community_tables
1+ """v14_initial_all_tables
22
3- Revision ID: b5417e864e9c
3+ Revision ID: f03fbc681fc5
44Revises:
5- Create Date: 2026-03-15 10:27:59.592217
5+ Create Date: 2026-03-24 16:07:57.600570
66
77"""
88from typing import Sequence , Union
1212
1313
1414# revision identifiers, used by Alembic.
15- revision : str = 'b5417e864e9c '
15+ revision : str = 'f03fbc681fc5 '
1616down_revision : Union [str , Sequence [str ], None ] = None
1717branch_labels : Union [str , Sequence [str ], None ] = None
1818depends_on : Union [str , Sequence [str ], None ] = None
2121def upgrade () -> None :
2222 """Upgrade schema."""
2323 # ### commands auto generated by Alembic - please adjust! ###
24+ op .create_table ('users' ,
25+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
26+ sa .Column ('email' , sa .String (length = 255 ), nullable = False ),
27+ sa .Column ('username' , sa .String (length = 100 ), nullable = False ),
28+ sa .Column ('hashed_password' , sa .String (length = 255 ), nullable = False ),
29+ sa .Column ('role' , sa .String (length = 20 ), nullable = False ),
30+ sa .Column ('is_active' , sa .Boolean (), nullable = False ),
31+ sa .Column ('max_tests_per_day' , sa .Integer (), nullable = False ),
32+ sa .Column ('max_projects' , sa .Integer (), nullable = False ),
33+ sa .Column ('max_ai_calls_per_day' , sa .Integer (), nullable = False ),
34+ sa .Column ('storage_limit_mb' , sa .Integer (), nullable = False ),
35+ sa .Column ('credits' , sa .Integer (), nullable = False ),
36+ sa .Column ('credits_used' , sa .Integer (), nullable = False ),
37+ sa .Column ('plan' , sa .String (length = 20 ), nullable = False ),
38+ sa .Column ('created_at' , sa .DateTime (timezone = True ), nullable = False ),
39+ sa .Column ('updated_at' , sa .DateTime (timezone = True ), nullable = False ),
40+ sa .PrimaryKeyConstraint ('id' )
41+ )
42+ with op .batch_alter_table ('users' , schema = None ) as batch_op :
43+ batch_op .create_index (batch_op .f ('ix_users_email' ), ['email' ], unique = True )
44+ batch_op .create_index (batch_op .f ('ix_users_username' ), ['username' ], unique = True )
45+
2446 op .create_table ('api_keys' ,
2547 sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
2648 sa .Column ('user_id' , sa .Integer (), nullable = False ),
@@ -89,6 +111,38 @@ def upgrade() -> None:
89111 batch_op .create_index (batch_op .f ('ix_shared_experiences_status' ), ['status' ], unique = False )
90112 batch_op .create_index (batch_op .f ('ix_shared_experiences_user_id' ), ['user_id' ], unique = False )
91113
114+ op .create_table ('teams' ,
115+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
116+ sa .Column ('name' , sa .String (length = 200 ), nullable = False ),
117+ sa .Column ('description' , sa .Text (), nullable = False ),
118+ sa .Column ('owner_id' , sa .Integer (), nullable = False ),
119+ sa .Column ('invite_code' , sa .String (length = 32 ), nullable = False ),
120+ sa .Column ('max_members' , sa .Integer (), nullable = False ),
121+ sa .Column ('is_active' , sa .Boolean (), nullable = False ),
122+ sa .Column ('created_at' , sa .DateTime (timezone = True ), nullable = False ),
123+ sa .Column ('updated_at' , sa .DateTime (timezone = True ), nullable = False ),
124+ sa .ForeignKeyConstraint (['owner_id' ], ['users.id' ], ),
125+ sa .PrimaryKeyConstraint ('id' )
126+ )
127+ with op .batch_alter_table ('teams' , schema = None ) as batch_op :
128+ batch_op .create_index (batch_op .f ('ix_teams_invite_code' ), ['invite_code' ], unique = True )
129+ batch_op .create_index (batch_op .f ('ix_teams_owner_id' ), ['owner_id' ], unique = False )
130+
131+ op .create_table ('usage_records' ,
132+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
133+ sa .Column ('user_id' , sa .Integer (), nullable = False ),
134+ sa .Column ('date' , sa .String (length = 10 ), nullable = False ),
135+ sa .Column ('test_count' , sa .Integer (), nullable = False ),
136+ sa .Column ('ai_call_count' , sa .Integer (), nullable = False ),
137+ sa .Column ('screenshot_count' , sa .Integer (), nullable = False ),
138+ sa .Column ('storage_used_mb' , sa .Float (), nullable = False ),
139+ sa .ForeignKeyConstraint (['user_id' ], ['users.id' ], ),
140+ sa .PrimaryKeyConstraint ('id' )
141+ )
142+ with op .batch_alter_table ('usage_records' , schema = None ) as batch_op :
143+ batch_op .create_index ('idx_usage_user_date' , ['user_id' , 'date' ], unique = True )
144+ batch_op .create_index (batch_op .f ('ix_usage_records_user_id' ), ['user_id' ], unique = False )
145+
92146 op .create_table ('user_badges' ,
93147 sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
94148 sa .Column ('user_id' , sa .Integer (), nullable = False ),
@@ -128,6 +182,41 @@ def upgrade() -> None:
128182 with op .batch_alter_table ('experience_votes' , schema = None ) as batch_op :
129183 batch_op .create_index ('idx_vote_unique' , ['experience_id' , 'user_id' , 'vote_type' ], unique = True )
130184
185+ op .create_table ('projects' ,
186+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
187+ sa .Column ('name' , sa .String (length = 200 ), nullable = False ),
188+ sa .Column ('description' , sa .Text (), nullable = False ),
189+ sa .Column ('owner_id' , sa .Integer (), nullable = False ),
190+ sa .Column ('team_id' , sa .Integer (), nullable = True ),
191+ sa .Column ('base_url' , sa .String (length = 500 ), nullable = False ),
192+ sa .Column ('is_active' , sa .Boolean (), nullable = False ),
193+ sa .Column ('created_at' , sa .DateTime (timezone = True ), nullable = False ),
194+ sa .Column ('updated_at' , sa .DateTime (timezone = True ), nullable = False ),
195+ sa .Column ('test_count' , sa .Integer (), nullable = False ),
196+ sa .Column ('last_pass_rate' , sa .Float (), nullable = False ),
197+ sa .Column ('total_bugs_found' , sa .Integer (), nullable = False ),
198+ sa .ForeignKeyConstraint (['owner_id' ], ['users.id' ], ),
199+ sa .ForeignKeyConstraint (['team_id' ], ['teams.id' ], ),
200+ sa .PrimaryKeyConstraint ('id' )
201+ )
202+ with op .batch_alter_table ('projects' , schema = None ) as batch_op :
203+ batch_op .create_index ('idx_project_owner' , ['owner_id' , 'is_active' ], unique = False )
204+ batch_op .create_index (batch_op .f ('ix_projects_owner_id' ), ['owner_id' ], unique = False )
205+ batch_op .create_index (batch_op .f ('ix_projects_team_id' ), ['team_id' ], unique = False )
206+
207+ op .create_table ('team_members' ,
208+ sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
209+ sa .Column ('team_id' , sa .Integer (), nullable = False ),
210+ sa .Column ('user_id' , sa .Integer (), nullable = False ),
211+ sa .Column ('role' , sa .String (length = 20 ), nullable = False ),
212+ sa .Column ('joined_at' , sa .DateTime (timezone = True ), nullable = False ),
213+ sa .ForeignKeyConstraint (['team_id' ], ['teams.id' ], ),
214+ sa .ForeignKeyConstraint (['user_id' ], ['users.id' ], ),
215+ sa .PrimaryKeyConstraint ('id' )
216+ )
217+ with op .batch_alter_table ('team_members' , schema = None ) as batch_op :
218+ batch_op .create_index ('idx_team_member' , ['team_id' , 'user_id' ], unique = True )
219+
131220 op .create_table ('debug_snapshots' ,
132221 sa .Column ('id' , sa .Integer (), autoincrement = True , nullable = False ),
133222 sa .Column ('user_id' , sa .Integer (), nullable = False ),
@@ -152,27 +241,27 @@ def upgrade() -> None:
152241 batch_op .create_index ('idx_snapshot_user_resolved' , ['user_id' , 'resolved' ], unique = False )
153242 batch_op .create_index (batch_op .f ('ix_debug_snapshots_user_id' ), ['user_id' ], unique = False )
154243
155- with op .batch_alter_table ('users' , schema = None ) as batch_op :
156- batch_op .add_column (sa .Column ('credits' , sa .Integer (), nullable = False ))
157- batch_op .add_column (sa .Column ('credits_used' , sa .Integer (), nullable = False ))
158- batch_op .add_column (sa .Column ('plan' , sa .String (length = 20 ), nullable = False ))
159-
160244 # ### end Alembic commands ###
161245
162246
163247def downgrade () -> None :
164248 """Downgrade schema."""
165249 # ### commands auto generated by Alembic - please adjust! ###
166- with op .batch_alter_table ('users' , schema = None ) as batch_op :
167- batch_op .drop_column ('plan' )
168- batch_op .drop_column ('credits_used' )
169- batch_op .drop_column ('credits' )
170-
171250 with op .batch_alter_table ('debug_snapshots' , schema = None ) as batch_op :
172251 batch_op .drop_index (batch_op .f ('ix_debug_snapshots_user_id' ))
173252 batch_op .drop_index ('idx_snapshot_user_resolved' )
174253
175254 op .drop_table ('debug_snapshots' )
255+ with op .batch_alter_table ('team_members' , schema = None ) as batch_op :
256+ batch_op .drop_index ('idx_team_member' )
257+
258+ op .drop_table ('team_members' )
259+ with op .batch_alter_table ('projects' , schema = None ) as batch_op :
260+ batch_op .drop_index (batch_op .f ('ix_projects_team_id' ))
261+ batch_op .drop_index (batch_op .f ('ix_projects_owner_id' ))
262+ batch_op .drop_index ('idx_project_owner' )
263+
264+ op .drop_table ('projects' )
176265 with op .batch_alter_table ('experience_votes' , schema = None ) as batch_op :
177266 batch_op .drop_index ('idx_vote_unique' )
178267
@@ -183,6 +272,16 @@ def downgrade() -> None:
183272 batch_op .drop_index ('idx_badge_user_type' )
184273
185274 op .drop_table ('user_badges' )
275+ with op .batch_alter_table ('usage_records' , schema = None ) as batch_op :
276+ batch_op .drop_index (batch_op .f ('ix_usage_records_user_id' ))
277+ batch_op .drop_index ('idx_usage_user_date' )
278+
279+ op .drop_table ('usage_records' )
280+ with op .batch_alter_table ('teams' , schema = None ) as batch_op :
281+ batch_op .drop_index (batch_op .f ('ix_teams_owner_id' ))
282+ batch_op .drop_index (batch_op .f ('ix_teams_invite_code' ))
283+
284+ op .drop_table ('teams' )
186285 with op .batch_alter_table ('shared_experiences' , schema = None ) as batch_op :
187286 batch_op .drop_index (batch_op .f ('ix_shared_experiences_user_id' ))
188287 batch_op .drop_index (batch_op .f ('ix_shared_experiences_status' ))
@@ -202,4 +301,9 @@ def downgrade() -> None:
202301 batch_op .drop_index (batch_op .f ('ix_api_keys_user_id' ))
203302
204303 op .drop_table ('api_keys' )
304+ with op .batch_alter_table ('users' , schema = None ) as batch_op :
305+ batch_op .drop_index (batch_op .f ('ix_users_username' ))
306+ batch_op .drop_index (batch_op .f ('ix_users_email' ))
307+
308+ op .drop_table ('users' )
205309 # ### end Alembic commands ###
0 commit comments