# File lib/rubyrep/replication_extenders/mysql_replication.rb, line 195
      def update_sequences(
          rep_prefix, table_name, increment, offset,
          left_sequence_values, right_sequence_values, adjustment_buffer)
        return if left_sequence_values.empty?
        column_name = left_sequence_values.keys[0]

        # check if the sequences table exists, create if necessary
        sequence_table_name = "#{rep_prefix}_sequences"
        current_max =
          [left_sequence_values[column_name][:value], right_sequence_values[column_name][:value]].max +
          adjustment_buffer
        new_start = current_max - (current_max % increment) + increment + offset

        sequence_row = select_one("select current_value, increment, offset from #{sequence_table_name} where name = '#{table_name}'")
        if sequence_row == nil
          # no sequence exists yet for the table, create it and the according
          # sequence trigger
          execute("insert into \#{sequence_table_name}(name, current_value, increment, offset)\nvalues('\#{table_name}', \#{new_start}, \#{increment}, \#{offset})\n")
          trigger_name = "#{rep_prefix}_#{table_name}_sequence"
          execute("DROP TRIGGER IF EXISTS `\#{trigger_name}`;\n")

          execute("CREATE TRIGGER `\#{trigger_name}`\nBEFORE INSERT ON `\#{table_name}` FOR EACH ROW BEGIN\nIF NEW.`\#{column_name}` = 0 THEN\nUPDATE \#{sequence_table_name}\nSET current_value = LAST_INSERT_ID(current_value + increment)\nWHERE name = '\#{table_name}';\nSET NEW.`\#{column_name}` = LAST_INSERT_ID();\nEND IF;\nEND;\n")
        elsif sequence_row['increment'].to_i != increment or sequence_row['offset'].to_i != offset
          # sequence exists but with incorrect values; update it
          execute("update \#{sequence_table_name}\nset current_value = \#{new_start},\nincrement = \#{increment}, offset = \#{offset}\nwhere name = '\#{table_name}'\n")
        end
      end