@@ -25,7 +25,9 @@ def init_db():
2525 commit_messages TEXT,
2626 score INTEGER,
2727 url TEXT,
28- review_result TEXT
28+ review_result TEXT,
29+ additions INTEGER DEFAULT 0,
30+ deletions INTEGER DEFAULT 0
2931 )
3032 ''' )
3133 cursor .execute ('''
@@ -37,9 +39,20 @@ def init_db():
3739 updated_at INTEGER,
3840 commit_messages TEXT,
3941 score INTEGER,
40- review_result TEXT
42+ review_result TEXT,
43+ additions INTEGER DEFAULT 0,
44+ deletions INTEGER DEFAULT 0
4145 )
4246 ''' )
47+ # 确保旧版本的mr_review_log、push_review_log表添加additions、deletions列
48+ tables = ["mr_review_log" , "push_review_log" ]
49+ columns = ["additions" , "deletions" ]
50+ for table in tables :
51+ cursor .execute (f"PRAGMA table_info({ table } )" )
52+ current_columns = [col [1 ] for col in cursor .fetchall ()]
53+ for column in columns :
54+ if column not in current_columns :
55+ cursor .execute (f"ALTER TABLE { table } ADD COLUMN { column } INTEGER DEFAULT 0" )
4356 conn .commit ()
4457 except sqlite3 .DatabaseError as e :
4558 print (f"Database initialization failed: { e } " )
@@ -51,13 +64,13 @@ def insert_mr_review_log(entity: MergeRequestReviewEntity):
5164 with sqlite3 .connect (ReviewService .DB_FILE ) as conn :
5265 cursor = conn .cursor ()
5366 cursor .execute ('''
54- INSERT INTO mr_review_log (project_name,author, source_branch, target_branch, updated_at, commit_messages, score, url,review_result)
55- VALUES (?,?, ?, ?, ?, ?, ?, ?, ?)
67+ INSERT INTO mr_review_log (project_name,author, source_branch, target_branch, updated_at, commit_messages, score, url,review_result, additions, deletions )
68+ VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
5669 ''' ,
5770 (entity .project_name , entity .author , entity .source_branch ,
5871 entity .target_branch ,
5972 entity .updated_at , entity .commit_messages , entity .score ,
60- entity .url , entity .review_result ))
73+ entity .url , entity .review_result , entity . additions , entity . deletions ))
6174 conn .commit ()
6275 except sqlite3 .DatabaseError as e :
6376 print (f"Error inserting review log: { e } " )
@@ -69,7 +82,7 @@ def get_mr_review_logs(authors: list = None, project_names: list = None, updated
6982 try :
7083 with sqlite3 .connect (ReviewService .DB_FILE ) as conn :
7184 query = """
72- SELECT project_name, author, source_branch, target_branch, updated_at, commit_messages, score, url, review_result
85+ SELECT project_name, author, source_branch, target_branch, updated_at, commit_messages, score, url, review_result, additions, deletions
7386 FROM mr_review_log
7487 WHERE 1=1
7588 """
@@ -106,12 +119,12 @@ def insert_push_review_log(entity: PushReviewEntity):
106119 with sqlite3 .connect (ReviewService .DB_FILE ) as conn :
107120 cursor = conn .cursor ()
108121 cursor .execute ('''
109- INSERT INTO push_review_log (project_name,author, branch, updated_at, commit_messages, score,review_result)
110- VALUES (?, ?, ?, ?, ?, ?, ?)
122+ INSERT INTO push_review_log (project_name,author, branch, updated_at, commit_messages, score,review_result, additions, deletions )
123+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )
111124 ''' ,
112125 (entity .project_name , entity .author , entity .branch ,
113126 entity .updated_at , entity .commit_messages , entity .score ,
114- entity .review_result ))
127+ entity .review_result , entity . additions , entity . deletions ))
115128 conn .commit ()
116129 except sqlite3 .DatabaseError as e :
117130 print (f"Error inserting review log: { e } " )
@@ -124,7 +137,7 @@ def get_push_review_logs(authors: list = None, project_names: list = None, updat
124137 with sqlite3 .connect (ReviewService .DB_FILE ) as conn :
125138 # 基础查询
126139 query = """
127- SELECT project_name, author, branch, updated_at, commit_messages, score, review_result
140+ SELECT project_name, author, branch, updated_at, commit_messages, score, review_result, additions, deletions
128141 FROM push_review_log
129142 WHERE 1=1
130143 """
0 commit comments