def maybe_update_skill(ts_seq, skill_value, na_skill_value,
                               calc_skill_description):
            # Skill exists, check if it needs an update
            item = monster_skill.MonsterSkillItem(ts_seq, skill_value,
                                                  na_skill_value,
                                                  calc_skill_description)

            if not db_wrapper.check_existing(item.exists_sql()):
                fail_logger.fatal('Unexpected empty skill lookup: %s',
                                  repr(item))
                exit()

            # It exists, check if the updatable values have changed
            if not db_wrapper.check_existing(item.needs_update_sql()):
                logger.warn('Updating: %s', repr(item))
                db_wrapper.insert_item(item.update_sql())
            else:
                fail_logger.debug(
                    'Skipping existing item that needs no updates: %s',
                    repr(item))
        def find_or_create_skill(monster_field_name, skill_value,
                                 na_skill_value, calc_skill_description):
            # Try to look up another monster with that skill
            ts_seq = lookup_existing_skill_id(monster_field_name,
                                              skill_value.skill_id)

            if ts_seq is None:
                # Lookup failed, insert a new skill
                nonlocal next_skill_id
                item = monster_skill.MonsterSkillItem(next_skill_id,
                                                      skill_value,
                                                      na_skill_value,
                                                      calc_skill_description)

                logger.warn('Inserting new monster skill: %s - %s',
                            repr(merged_card), repr(item))
                db_wrapper.insert_item(item.insert_sql())
                ts_seq = next_skill_id
                next_skill_id += 1

            return ts_seq