def create_indexes(self): """ method to create indexes on the database """ with db.engine.connect() as conn: with conn.execution_options(isolation_level='AUTOCOMMIT'): try: Pairing.create_index(conn) Pairing_Codes.create_index(conn) Imei.create_index(conn) Devices.create_index(conn) Owner.create_index(conn) except Exception as e: sys.exit(1)
def test_pairing_indexes(db, session): """Verify that the Pairing model works correctly.""" with db.engine.connect() as conn: Pairing.create_index(conn) qry = session.execute( text(""" select * from pg_stat_user_indexes; """)).fetchall() for p in qry: if p.indexrelname == 'devices_msisdn_index': device_index = True elif p.indexrelname == 'devices_imsi_index': device_index = True elif p.indexrelname == 'devices_creation_date_index': device_index = True elif p.indexrelname == 'devices_end_date_index': device_index = True elif p.indexrelname == 'devices_operator_index': device_index = True print(p.indexrelname) # noinspection PyUnboundLocalVariable assert device_index