Project

General

Profile

« Previous | Next » 

Revision 2772

sql.py: Added add_indexes()

View differences:

sql.py
968 968
        index.name = next_version(index.name)
969 969
        # try again with next version of name
970 970

  
971
already_indexed = object() # tells add_indexes() the pkey has already been added
972

  
973
def add_indexes(db, table, has_pkey=True):
974
    '''Adds an index on all columns in a table.
975
    @param has_pkey bool|already_indexed Whether a pkey instead of a regular
976
        index should be added on the first column.
977
        * If already_indexed, the pkey is assumed to have already been added
978
    '''
979
    cols = table_cols(db, table)
980
    if has_pkey:
981
        if has_pkey is not already_indexed: add_pkey(db, table)
982
        cols = cols[1:]
983
    for col in cols: add_index(db, col, table)
984

  
971 985
def add_row_num(db, table):
972 986
    '''Adds a row number column to a table. Its name is in row_num_col. It will
973 987
    be the primary key.'''

Also available in: Unified diff