11"""empty message
22
3- Revision ID: dcc0b6c56552
3+ Revision ID: eb8aa708478f
44Revises:
5- Create Date: 2025-06-17 11:34:47.015293
5+ Create Date: 2025-06-24 09:30:05.267898
66
77"""
88from typing import Sequence , Union
1212from pgvector .sqlalchemy import Vector
1313
1414# revision identifiers, used by Alembic.
15- revision : str = 'dcc0b6c56552 '
15+ revision : str = 'eb8aa708478f '
1616down_revision : Union [str , None ] = None
1717branch_labels : Union [str , Sequence [str ], None ] = None
1818depends_on : Union [str , Sequence [str ], None ] = None
@@ -36,6 +36,36 @@ def upgrade() -> None:
3636 op .create_index (op .f ('ix_api_key_gmt_deleted' ), 'api_key' , ['gmt_deleted' ], unique = False )
3737 op .create_index (op .f ('ix_api_key_status' ), 'api_key' , ['status' ], unique = False )
3838 op .create_index (op .f ('ix_api_key_user' ), 'api_key' , ['user' ], unique = False )
39+ op .create_table ('audit_log' ,
40+ sa .Column ('id' , sa .String (length = 36 ), nullable = False ),
41+ sa .Column ('user_id' , sa .String (length = 36 ), nullable = True , comment = 'User ID' ),
42+ sa .Column ('username' , sa .String (length = 255 ), nullable = True , comment = 'Username' ),
43+ sa .Column ('resource_type' , sa .Enum ('collection' , 'document' , 'bot' , 'chat' , 'message' , 'api_key' , 'llm_provider' , 'llm_provider_model' , 'model_service_provider' , 'user' , 'config' , 'invitation' , 'auth' , 'chat_completion' , 'search' , 'llm' , 'flow' , 'system' , name = 'auditresource' ), nullable = True , comment = 'Resource type' ),
44+ sa .Column ('resource_id' , sa .String (length = 255 ), nullable = True , comment = 'Resource ID (extracted at query time)' ),
45+ sa .Column ('api_name' , sa .String (length = 255 ), nullable = False , comment = 'API operation name' ),
46+ sa .Column ('http_method' , sa .String (length = 10 ), nullable = False , comment = 'HTTP method (POST, PUT, DELETE)' ),
47+ sa .Column ('path' , sa .String (length = 512 ), nullable = False , comment = 'API path' ),
48+ sa .Column ('status_code' , sa .Integer (), nullable = True , comment = 'HTTP status code' ),
49+ sa .Column ('request_data' , sa .Text (), nullable = True , comment = 'Request data (JSON)' ),
50+ sa .Column ('response_data' , sa .Text (), nullable = True , comment = 'Response data (JSON)' ),
51+ sa .Column ('error_message' , sa .Text (), nullable = True , comment = 'Error message if failed' ),
52+ sa .Column ('ip_address' , sa .String (length = 45 ), nullable = True , comment = 'Client IP address' ),
53+ sa .Column ('user_agent' , sa .String (length = 500 ), nullable = True , comment = 'User agent string' ),
54+ sa .Column ('request_id' , sa .String (length = 255 ), nullable = False , comment = 'Request ID for tracking' ),
55+ sa .Column ('start_time' , sa .BigInteger (), nullable = False , comment = 'Request start time (milliseconds since epoch)' ),
56+ sa .Column ('end_time' , sa .BigInteger (), nullable = True , comment = 'Request end time (milliseconds since epoch)' ),
57+ sa .Column ('gmt_created' , sa .DateTime (timezone = True ), nullable = False , comment = 'Created time' ),
58+ sa .PrimaryKeyConstraint ('id' )
59+ )
60+ op .create_index ('idx_audit_api_name' , 'audit_log' , ['api_name' ], unique = False )
61+ op .create_index ('idx_audit_gmt_created' , 'audit_log' , ['gmt_created' ], unique = False )
62+ op .create_index ('idx_audit_http_method' , 'audit_log' , ['http_method' ], unique = False )
63+ op .create_index ('idx_audit_request_id' , 'audit_log' , ['request_id' ], unique = False )
64+ op .create_index ('idx_audit_resource_id' , 'audit_log' , ['resource_id' ], unique = False )
65+ op .create_index ('idx_audit_resource_type' , 'audit_log' , ['resource_type' ], unique = False )
66+ op .create_index ('idx_audit_start_time' , 'audit_log' , ['start_time' ], unique = False )
67+ op .create_index ('idx_audit_status_code' , 'audit_log' , ['status_code' ], unique = False )
68+ op .create_index ('idx_audit_user_id' , 'audit_log' , ['user_id' ], unique = False )
3969 op .create_table ('bot' ,
4070 sa .Column ('id' , sa .String (length = 24 ), nullable = False ),
4171 sa .Column ('user' , sa .String (length = 256 ), nullable = False ),
@@ -125,7 +155,7 @@ def upgrade() -> None:
125155 op .create_table ('document_index' ,
126156 sa .Column ('id' , sa .Integer (), nullable = False ),
127157 sa .Column ('document_id' , sa .String (length = 24 ), nullable = False ),
128- sa .Column ('index_type' , sa .Enum ('vector ' , 'fulltext ' , 'graph ' , name = 'documentindextype' ), nullable = False ),
158+ sa .Column ('index_type' , sa .Enum ('VECTOR ' , 'FULLTEXT ' , 'GRAPH ' , name = 'documentindextype' ), nullable = False ),
129159 sa .Column ('desired_state' , sa .Enum ('present' , 'absent' , name = 'indexdesiredstate' ), nullable = False ),
130160 sa .Column ('version' , sa .Integer (), nullable = False ),
131161 sa .Column ('created_by' , sa .String (length = 256 ), nullable = False ),
@@ -293,7 +323,7 @@ def upgrade() -> None:
293323 op .create_index (op .f ('ix_model_service_provider_gmt_deleted' ), 'model_service_provider' , ['gmt_deleted' ], unique = False )
294324 op .create_index (op .f ('ix_model_service_provider_name' ), 'model_service_provider' , ['name' ], unique = False )
295325 op .create_index (op .f ('ix_model_service_provider_status' ), 'model_service_provider' , ['status' ], unique = False )
296- op .create_table ('searchtesthistory ' ,
326+ op .create_table ('searchhistory ' ,
297327 sa .Column ('id' , sa .String (length = 24 ), nullable = False ),
298328 sa .Column ('user' , sa .String (length = 256 ), nullable = False ),
299329 sa .Column ('collection_id' , sa .String (length = 24 ), nullable = True ),
@@ -306,9 +336,9 @@ def upgrade() -> None:
306336 sa .Column ('gmt_deleted' , sa .DateTime (timezone = True ), nullable = True ),
307337 sa .PrimaryKeyConstraint ('id' )
308338 )
309- op .create_index (op .f ('ix_searchtesthistory_collection_id ' ), 'searchtesthistory ' , ['collection_id' ], unique = False )
310- op .create_index (op .f ('ix_searchtesthistory_gmt_deleted ' ), 'searchtesthistory ' , ['gmt_deleted' ], unique = False )
311- op .create_index (op .f ('ix_searchtesthistory_user ' ), 'searchtesthistory ' , ['user' ], unique = False )
339+ op .create_index (op .f ('ix_searchhistory_collection_id ' ), 'searchhistory ' , ['collection_id' ], unique = False )
340+ op .create_index (op .f ('ix_searchhistory_gmt_deleted ' ), 'searchhistory ' , ['gmt_deleted' ], unique = False )
341+ op .create_index (op .f ('ix_searchhistory_user ' ), 'searchhistory ' , ['user' ], unique = False )
312342 op .create_table ('user' ,
313343 sa .Column ('id' , sa .String (length = 24 ), nullable = False ),
314344 sa .Column ('username' , sa .String (length = 256 ), nullable = False ),
@@ -344,10 +374,10 @@ def downgrade() -> None:
344374 # ### commands auto generated by Alembic - please adjust! ###
345375 op .drop_table ('user_quota' )
346376 op .drop_table ('user' )
347- op .drop_index (op .f ('ix_searchtesthistory_user ' ), table_name = 'searchtesthistory ' )
348- op .drop_index (op .f ('ix_searchtesthistory_gmt_deleted ' ), table_name = 'searchtesthistory ' )
349- op .drop_index (op .f ('ix_searchtesthistory_collection_id ' ), table_name = 'searchtesthistory ' )
350- op .drop_table ('searchtesthistory ' )
377+ op .drop_index (op .f ('ix_searchhistory_user ' ), table_name = 'searchhistory ' )
378+ op .drop_index (op .f ('ix_searchhistory_gmt_deleted ' ), table_name = 'searchhistory ' )
379+ op .drop_index (op .f ('ix_searchhistory_collection_id ' ), table_name = 'searchhistory ' )
380+ op .drop_table ('searchhistory ' )
351381 op .drop_index (op .f ('ix_model_service_provider_status' ), table_name = 'model_service_provider' )
352382 op .drop_index (op .f ('ix_model_service_provider_name' ), table_name = 'model_service_provider' )
353383 op .drop_index (op .f ('ix_model_service_provider_gmt_deleted' ), table_name = 'model_service_provider' )
@@ -393,6 +423,16 @@ def downgrade() -> None:
393423 op .drop_index (op .f ('ix_bot_status' ), table_name = 'bot' )
394424 op .drop_index (op .f ('ix_bot_gmt_deleted' ), table_name = 'bot' )
395425 op .drop_table ('bot' )
426+ op .drop_index ('idx_audit_user_id' , table_name = 'audit_log' )
427+ op .drop_index ('idx_audit_status_code' , table_name = 'audit_log' )
428+ op .drop_index ('idx_audit_start_time' , table_name = 'audit_log' )
429+ op .drop_index ('idx_audit_resource_type' , table_name = 'audit_log' )
430+ op .drop_index ('idx_audit_resource_id' , table_name = 'audit_log' )
431+ op .drop_index ('idx_audit_request_id' , table_name = 'audit_log' )
432+ op .drop_index ('idx_audit_http_method' , table_name = 'audit_log' )
433+ op .drop_index ('idx_audit_gmt_created' , table_name = 'audit_log' )
434+ op .drop_index ('idx_audit_api_name' , table_name = 'audit_log' )
435+ op .drop_table ('audit_log' )
396436 op .drop_index (op .f ('ix_api_key_user' ), table_name = 'api_key' )
397437 op .drop_index (op .f ('ix_api_key_status' ), table_name = 'api_key' )
398438 op .drop_index (op .f ('ix_api_key_gmt_deleted' ), table_name = 'api_key' )
0 commit comments