def test_change_version_3(self): """Verify the version is decremented by 5.""" data = {"Version": 10, "SchemaVersion": 1} test_db_utils.insert_version_data(data) mysqldb.change_version(self.engine, amount=-5) result = test_db_utils.get_data(test_db_utils.version_table_query) output_value = result[0]["Version"] self.assertEqual(output_value, 5)
def test_change_version_1(self): """Verify the version is incremented by 1.""" data = {"Version": 10, "SchemaVersion": 1} test_db_utils.insert_data(VERSION, data) mysqldb.change_version(self.engine) result = test_db_utils.get_data(test_db_utils.version_table_query) output_value = result[0]["Version"] self.assertEqual(output_value, 11)
def main(unparsed_args): """Runs the complete update pipeline.""" args = parse_args(unparsed_args) # Verify database connection and schema compatibility. print("Connecting to the MySQL database...") engine = mysqldb.connect_to_db(args.database) mysqldb.check_schema_compatibility(engine, "the update pipeline") if args.version == True: mysqldb.change_version(engine) print("Database version updated.") if args.ticket_table is not None: update_table_path = basic.set_path(args.ticket_table, kind="file", expect=True) # Iterate through the tickets and process them sequentially. list_of_update_tickets = [] with update_table_path.open(mode='r') as f: file_reader = csv.DictReader(f) for dict in file_reader: list_of_update_tickets.append(dict) # Variables to be used for end summary processed = 0 succeeded = 0 failed = 0 for dict in list_of_update_tickets: conn = engine.connect() # Pass the raw db_api connection handler = RandomFieldUpdateHandler(conn.connection) handler.table = dict["table"] # Which table will be updated? handler.field = dict["field"] # Which field will be updated? handler.value = dict[ "value"] # What value will be put in that field? handler.key_name = dict[ "key_name"] # How will we know which row is the right one? handler.key_value = dict[ "key_value"] # How will we know which row is the right one? handler.validate_ticket( ) # Make sure all handler attributes are valid status = handler.execute_ticket() # Do what was requested if status == 1: processed += 1 succeeded += 1 else: processed += 1 failed += 1 engine.dispose() print("\nDone iterating through tickets.") if succeeded > 0: print(f"{succeeded} / {processed} tickets successfully handled.") if failed > 0: print(f"{failed} / {processed} tickets failed to be handled.")
def main(unparsed_args): """Runs the complete update pipeline.""" args = parse_args(unparsed_args[2:]) # Verify database connection and schema compatibility. print("Connecting to the MySQL database...") # Create config object with data obtained from file and/or defaults. config = configfile.build_complete_config(args.config_file) mysql_creds = config["mysql"] alchemist = AlchemyHandler(database=args.database, username=mysql_creds["user"], password=mysql_creds["password"]) alchemist.connect(pipeline=True) engine = alchemist.engine mysqldb.check_schema_compatibility(engine, "the update pipeline") if args.version is True: mysqldb.change_version(engine) print("Database version updated.") if args.ticket_table is not None: update_table_path = basic.set_path(args.ticket_table, kind="file", expect=True) # Iterate through the tickets and process them sequentially. list_of_update_tickets = [] with update_table_path.open(mode='r') as f: file_reader = csv.DictReader(f) for dict in file_reader: list_of_update_tickets.append(dict) # Variables to be used for end summary processed = 0 succeeded = 0 failed = 0 for dict in list_of_update_tickets: status = update_field(alchemist, dict) if status == 1: processed += 1 succeeded += 1 else: processed += 1 failed += 1 engine.dispose() print("\nDone iterating through tickets.") if succeeded > 0: print(f"{succeeded} / {processed} tickets successfully handled.") if failed > 0: print(f"{failed} / {processed} tickets failed to be handled.")