17
17
from rich .progress import BarColumn , MofNCompleteColumn , Progress , TaskProgressColumn , TextColumn , TimeRemainingColumn
18
18
from sqlalchemy import desc , select
19
19
from sqlalchemy .dialects import sqlite
20
+ from sqlalchemy .exc import IdentifierError
20
21
from sqlalchemy .ext .automap import automap_base
21
22
from sqlalchemy .orm import Session
22
23
@@ -205,12 +206,16 @@ def upgrade(name: str = '') -> None:
205
206
206
207
migrate_old_data ()
207
208
208
- with op .batch_alter_table ('nonebot_plugin_tetris_stats_historicaldata' , schema = None ) as batch_op :
209
- batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_command_type' )
210
- batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_game_platform' )
211
- batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_source_account' )
212
- batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_source_type' )
213
- batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_user_unique_identifier' )
209
+ try :
210
+ with op .batch_alter_table ('nonebot_plugin_tetris_stats_historicaldata' , schema = None ) as batch_op :
211
+ batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_command_type' )
212
+ batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_game_platform' )
213
+ batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_source_account' )
214
+ batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_source_type' )
215
+ batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_user_unique_identifier' )
216
+ except IdentifierError :
217
+ with op .batch_alter_table ('nonebot_plugin_tetris_stats_historicaldata' , schema = None ) as batch_op :
218
+ batch_op .drop_index ('ix_nonebot_plugin_tetris_stats_historicaldata_user_uniq_5301' )
214
219
215
220
op .drop_table ('nonebot_plugin_tetris_stats_historicaldata' )
216
221
# ### end Alembic commands ###
@@ -222,40 +227,48 @@ def downgrade(name: str = '') -> None:
222
227
# ### commands auto generated by Alembic - please adjust! ###
223
228
op .create_table (
224
229
'nonebot_plugin_tetris_stats_historicaldata' ,
225
- sa .Column ('id' , sa .INTEGER (), nullable = False ),
226
- sa .Column ('trigger_time' , sa .DATETIME (), nullable = False ),
227
- sa .Column ('bot_platform' , sa .VARCHAR (length = 32 ), nullable = True ),
228
- sa .Column ('bot_account' , sa .VARCHAR (), nullable = True ),
229
- sa .Column ('source_type' , sa .VARCHAR (length = 32 ), nullable = True ),
230
- sa .Column ('source_account' , sa .VARCHAR (), nullable = True ),
231
- sa .Column ('message' , sa .BLOB (), nullable = True ),
232
- sa .Column ('game_platform' , sa .VARCHAR (length = 32 ), nullable = False ),
233
- sa .Column ('command_type' , sa .VARCHAR (length = 16 ), nullable = False ),
230
+ sa .Column ('id' , sa .Integer (), nullable = False ),
231
+ sa .Column ('trigger_time' , sa .DateTime (), nullable = False ),
232
+ sa .Column ('bot_platform' , sa .String (length = 32 ), nullable = True ),
233
+ sa .Column ('bot_account' , sa .String (), nullable = True ),
234
+ sa .Column ('source_type' , sa .String (length = 32 ), nullable = True ),
235
+ sa .Column ('source_account' , sa .String (), nullable = True ),
236
+ sa .Column ('message' , sa .PickleType (), nullable = True ),
237
+ sa .Column ('game_platform' , sa .String (length = 32 ), nullable = False ),
238
+ sa .Column ('command_type' , sa .String (length = 16 ), nullable = False ),
234
239
sa .Column ('command_args' , sqlite .JSON (), nullable = False ),
235
240
sa .Column ('game_user' , sqlite .JSON (), nullable = False ),
236
241
sa .Column ('processed_data' , sqlite .JSON (), nullable = False ),
237
- sa .Column ('finish_time' , sa .DATETIME (), nullable = False ),
238
- sa .Column ('user_unique_identifier' , sa .VARCHAR (length = 32 ), nullable = False ),
242
+ sa .Column ('finish_time' , sa .DateTime (), nullable = False ),
243
+ sa .Column ('user_unique_identifier' , sa .String (length = 32 ), nullable = False ),
239
244
sa .PrimaryKeyConstraint ('id' , name = 'pk_nonebot_plugin_tetris_stats_historicaldata' ),
240
245
)
241
- with op .batch_alter_table ('nonebot_plugin_tetris_stats_historicaldata' , schema = None ) as batch_op :
242
- batch_op .create_index (
243
- 'ix_nonebot_plugin_tetris_stats_historicaldata_user_unique_identifier' ,
244
- ['user_unique_identifier' ],
245
- unique = False ,
246
- )
247
- batch_op .create_index (
248
- 'ix_nonebot_plugin_tetris_stats_historicaldata_source_type' , ['source_type' ], unique = False
249
- )
250
- batch_op .create_index (
251
- 'ix_nonebot_plugin_tetris_stats_historicaldata_source_account' , ['source_account' ], unique = False
252
- )
253
- batch_op .create_index (
254
- 'ix_nonebot_plugin_tetris_stats_historicaldata_game_platform' , ['game_platform' ], unique = False
255
- )
256
- batch_op .create_index (
257
- 'ix_nonebot_plugin_tetris_stats_historicaldata_command_type' , ['command_type' ], unique = False
258
- )
246
+ try :
247
+ with op .batch_alter_table ('nonebot_plugin_tetris_stats_historicaldata' , schema = None ) as batch_op :
248
+ batch_op .create_index (
249
+ 'ix_nonebot_plugin_tetris_stats_historicaldata_source_type' , ['source_type' ], unique = False
250
+ )
251
+ batch_op .create_index (
252
+ 'ix_nonebot_plugin_tetris_stats_historicaldata_source_account' , ['source_account' ], unique = False
253
+ )
254
+ batch_op .create_index (
255
+ 'ix_nonebot_plugin_tetris_stats_historicaldata_game_platform' , ['game_platform' ], unique = False
256
+ )
257
+ batch_op .create_index (
258
+ 'ix_nonebot_plugin_tetris_stats_historicaldata_command_type' , ['command_type' ], unique = False
259
+ )
260
+ batch_op .create_index (
261
+ 'ix_nonebot_plugin_tetris_stats_historicaldata_user_unique_identifier' ,
262
+ ['user_unique_identifier' ],
263
+ unique = False ,
264
+ )
265
+ except IdentifierError :
266
+ with op .batch_alter_table ('nonebot_plugin_tetris_stats_historicaldata' , schema = None ) as batch_op :
267
+ batch_op .create_index (
268
+ 'ix_nonebot_plugin_tetris_stats_historicaldata_user_uniq_5301' ,
269
+ ['user_unique_identifier' ],
270
+ unique = False ,
271
+ )
259
272
260
273
with op .batch_alter_table ('nonebot_plugin_tetris_stats_triggerhistoricaldata' , schema = None ) as batch_op :
261
274
batch_op .drop_index (batch_op .f ('ix_nonebot_plugin_tetris_stats_triggerhistoricaldata_game_platform' ))
0 commit comments