11import asyncio
2+ from foxglove import glove
23from foxglove .db .patches import patch , run_sql_section
34from textwrap import dedent , indent
45from time import time
56from tqdm import tqdm
67
78
89@patch
9- async def run_logic_sql (conn , settings , ** kwargs ):
10+ async def run_logic_sql (conn , ** kwargs ):
1011 """
1112 run the "logic" section of models.sql
1213 """
14+ settings = glove .settings
1315 await run_sql_section ('logic' , settings .sql_path .read_text (), conn )
1416
1517
@@ -35,7 +37,7 @@ async def chunked_update(conn, table, sql, sleep_time: float = 0):
3537
3638
3739@patch
38- async def performance_step1 (conn , settings , ** kwargs ):
40+ async def performance_step1 (conn , ** kwargs ):
3941 """
4042 First step to changing schema to improve performance. THIS WILL BE SLOW, but can be run in the background.
4143 """
@@ -81,7 +83,7 @@ async def performance_step1(conn, settings, **kwargs):
8183
8284
8385@patch (direct = True )
84- async def performance_step2 (conn , settings , ** kwargs ):
86+ async def performance_step2 (conn , ** kwargs ):
8587 """
8688 Second step to changing schema to improve performance. THIS WILL BE VERY SLOW, but can be run in the background.
8789 """
@@ -119,7 +121,7 @@ async def performance_step2(conn, settings, **kwargs):
119121
120122
121123@patch (direct = True )
122- async def performance_step3 (conn , settings , ** kwargs ):
124+ async def performance_step3 (conn , ** kwargs ):
123125 """
124126 Third step to changing schema to improve performance. THIS WILL BE VERY SLOW, but can be run in the background.
125127 """
@@ -145,7 +147,7 @@ async def performance_step3(conn, settings, **kwargs):
145147
146148
147149@patch
148- async def performance_step4 (conn , settings , ** kwargs ):
150+ async def performance_step4 (conn , ** kwargs ):
149151 """
150152 Fourth step to changing schema to improve performance. This should not be too slow, but will LOCK ENTIRE TABLES.
151153 """
@@ -197,8 +199,25 @@ async def performance_step4(conn, settings, **kwargs):
197199
198200
199201@patch
200- async def add_aggregation_view (conn , settings , ** kwargs ):
202+ async def add_aggregation_view (conn , ** kwargs ):
201203 """
202204 run the "message_aggregation" section of models.sql
203205 """
206+ settings = glove .settings
204207 await run_sql_section ('message_aggregation' , settings .sql_path .read_text (), conn )
208+
209+
210+ @patch (auto_run = True )
211+ async def add_spam_status_and_reason_to_messages (conn , ** kwargs ):
212+ """
213+ Add spam_status and spam_reason columns to the messages table.
214+ """
215+ print ('Adding spam_status and spam_reason columns to messages table' )
216+ await conn .execute (
217+ """
218+ ALTER TABLE messages
219+ ADD COLUMN IF NOT EXISTS spam_status BOOLEAN DEFAULT FALSE,
220+ ADD COLUMN IF NOT EXISTS spam_reason TEXT;
221+ """
222+ )
223+ print ('Added spam_status and spam_reason columns' )
0 commit comments