@@ -1225,19 +1225,11 @@ def _migrate_indices(
12251225 indices are created or replaced.
12261226 """
12271227 with self .transaction () as tx :
1228- index_rows = tx .query (f"PRAGMA index_list({ table } )" )
1229- current_indices = {Index .from_db (tx , row [1 ]) for row in index_rows }
1230-
1231- _indices = set (indices )
1232-
1233- if current_indices .issuperset (_indices ):
1234- return
1235-
1236- # May also include missing indices.
1237- changed_indices = _indices - current_indices
1238-
1239- with self .transaction () as tx :
1240- for index in changed_indices :
1228+ current = {
1229+ Index .from_db (tx , r [1 ])
1230+ for r in tx .query (f"PRAGMA index_list({ table } )" )
1231+ }
1232+ for index in set (indices ) - current :
12411233 index .recreate (tx , table )
12421234
12431235 # Querying.
@@ -1317,22 +1309,18 @@ class Index(NamedTuple):
13171309 """
13181310
13191311 name : str
1320- columns : Sequence [str ]
1312+ columns : tuple [str , ... ]
13211313
13221314 def recreate (self , tx : Transaction , table : str ) -> None :
13231315 """Recreate the index in the database.
13241316
13251317 This is useful when the index has been changed and needs to be
13261318 updated.
13271319 """
1328- tx .script (f"DROP INDEX IF EXISTS { self .name } " )
1329- self .create (tx , table )
1330-
1331- def create (self , tx : Transaction , table : str ) -> None :
1332- """Create the index in the database."""
1333- return tx .script (
1334- f"CREATE INDEX { self .name } ON { table } ({ ', ' .join (self .columns )} )"
1335- )
1320+ tx .script (f"""
1321+ DROP INDEX IF EXISTS { self .name } ;
1322+ CREATE INDEX { self .name } ON { table } ({ ", " .join (self .columns )} )
1323+ """ )
13361324
13371325 @classmethod
13381326 def from_db (cls , tx : Transaction , name : str ) -> Index :
@@ -1342,7 +1330,7 @@ def from_db(cls, tx: Transaction, name: str) -> Index:
13421330 Error will be raised.
13431331 """
13441332 rows = tx .query (f"PRAGMA index_info({ name } )" )
1345- columns = [ row [2 ] for row in rows ]
1333+ columns = tuple ( row [2 ] for row in rows )
13461334 return cls (name , columns )
13471335
13481336 def __hash__ (self ) -> int :
0 commit comments