X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools%2Fupgrade-db.py;h=4c9d1d51511e5e9de7fea3f5cc126751a9401769;hb=HEAD;hp=8fae60710d329e32cd0879d6e74a9c116ef4e9de;hpb=e026a19a5cfc0f95b0b4ffa48e569f9002812768;p=plcapi.git diff --git a/tools/upgrade-db.py b/tools/upgrade-db.py index 8fae607..4c9d1d5 100755 --- a/tools/upgrade-db.py +++ b/tools/upgrade-db.py @@ -134,7 +134,7 @@ def create_item_from_schema(item_name): def fix_row(row, table_name, table_fields): - if table_name in ['nodenetworks']: + if table_name in ['interfaces']: # convert str bwlimit to bps int bwlimit_index = table_fields.index('bwlimit') if isinstance(row[bwlimit_index], int): @@ -152,9 +152,13 @@ def fix_row(row, table_name, table_fields): row[attribute_type_index] = 10016 elif row[attribute_type_index] == 10006: row[attribute_type_index] = 10017 + elif row[attribute_type_index] in [10031, 10033]: + row[attribute_type_index] = 10037 + elif row[attribute_type_index] in [10034, 10035]: + row[attribute_type_index] = 10036 elif table_name in ['slice_attribute_types']: type_id_index = table_fields.index('attribute_type_id') - if row[type_id_index] in [10004, 10006]: + if row[type_id_index] in [10004, 10006, 10031, 10033, 10034, 10035]: return None return row @@ -163,7 +167,7 @@ def fix_table(table, table_name, table_fields): # remove duplicate/redundant primary keys type_id_index = table_fields.index('attribute_type_id') for row in table: - if row[type_id_index] in [10004, 10006]: + if row[type_id_index] in [10004, 10006, 10031, 10033, 10034, 10035]: table.remove(row) return table @@ -197,17 +201,16 @@ def generate_temp_table(table_name, db): if body_line.find(field) > -1 and \ body_line.upper().find("NOT NULL") > -1: not_null_indices.append(table_fields.index(field)) - # get index of primary key primary_key_indices = [] for body_line in body_list: if body_line.find("PRIMARY KEY") > -1: primary_key = body_line for field in table_fields: - if primary_key.find(field) > -1: + if primary_key.find(" "+field+" ") > -1: primary_key_indices.append(table_fields.index(field)) - break - + #break + # get old data get_old_data = "SELECT DISTINCT %s FROM %s" % \ (", ".join(old_fields), old_fields[0].split(".")[0]) @@ -347,9 +350,14 @@ try: lines = file.readlines() while index < len(lines): line = lines[index] + if line.find("--") > -1: + line_parts = line.split("--") + line = line_parts[0] # find all created objects if line.startswith("CREATE"): line_parts = line.split(" ") + if line_parts[1:3] == ['OR', 'REPLACE']: + line_parts = line_parts[2:] item_type = line_parts[1] item_name = line_parts[2] schema_items_ordered.append(item_name) @@ -363,6 +371,9 @@ try: while index < len(lines): index = index + 1 nextline =lines[index] + if nextline.find("--") > -1: + new_line_parts = nextline.split("--") + nextline = new_line_parts[0] # look for any sequences if item_type in ['TABLE'] and nextline.find('serial') > -1: sequences[item_name] = nextline.strip().split()[0] @@ -438,9 +449,9 @@ except: " 'ALTER DATABASE %s RENAME TO %s;'; > /dev/null" % \ (config['PLC_DB_NAME'], config['PLC_DB_NAME']+'_archived', config['PLC_DB_NAME']) os.system(undo_command) - remove_temp_tables() + #remove_temp_tables() raise -remove_temp_tables() +#remove_temp_tables() print "upgrade complete"