<s> import logging <EOL> from synapse . storage . prepare_database import get_statements <EOL> from synapse . storage . engines import PostgresEngine , Sqlite3Engine <EOL> import ujson <EOL> logger = logging . getLogger ( __name__ ) <EOL> POSTGRES_TABLE = """<STR_LIT>""" <EOL> SQLITE_TABLE = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def run_upgrade ( cur , database_engine , * args , ** kwargs ) : <EOL> if isinstance ( database_engine , PostgresEngine ) : <EOL> for statement in get_statements ( POSTGRES_TABLE . splitlines ( ) ) : <EOL> cur . execute ( statement ) <EOL> elif isinstance ( database_engine , Sqlite3Engine ) : <EOL> cur . execute ( SQLITE_TABLE ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> rows = cur . fetchall ( ) <EOL> min_stream_id = rows [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> cur . execute ( "<STR_LIT>" ) <EOL> rows = cur . fetchall ( ) <EOL> max_stream_id = rows [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> if min_stream_id is not None and max_stream_id is not None : <EOL> progress = { <EOL> "<STR_LIT>" : min_stream_id , <EOL> "<STR_LIT>" : max_stream_id + <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> } <EOL> progress_json = ujson . dumps ( progress ) <EOL> sql = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> sql = database_engine . convert_param_style ( sql ) <EOL> cur . execute ( sql , ( "<STR_LIT>" , progress_json ) ) </s>
