lib/avrolution/compatibility_check.rb in avrolution-0.6.1 vs lib/avrolution/compatibility_check.rb in avrolution-0.7.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'avro-resolution_canonical_form' require 'private_attr' require 'diffy' require 'avro_schema_registry-client' @@ -7,15 +9,15 @@ class CompatibilityCheck extend PrivateAttr attr_reader :incompatible_schemas - NONE = 'NONE'.freeze - FULL = 'FULL'.freeze - BOTH = 'BOTH'.freeze - BACKWARD = 'BACKWARD'.freeze - FORWARD = 'FORWARD'.freeze + NONE = 'NONE' + FULL = 'FULL' + BOTH = 'BOTH' + BACKWARD = 'BACKWARD' + FORWARD = 'FORWARD' private_attr_reader :schema_registry, :compatibility_breaks, :logger def initialize(logger: Avrolution.logger) @@ -53,10 +55,11 @@ fullname = schema.fullname fingerprint = schema.sha256_resolution_fingerprint.to_s(16) logger.info("Checking compatibility: #{fullname}") return if schema_registered?(fullname, schema) + compatible = schema_registry.compatible?(fullname, schema, 'latest') if compatible.nil? # compatible is nil if the subject is not registered logger.info("... New schema: #{fullname}") @@ -78,11 +81,13 @@ def compatibility_fallback(schema, fullname, fingerprint) compatibility_break = compatibility_breaks[[fullname, fingerprint]] if compatibility_break logger.info("... Checking compatibility with level set to #{compatibility_break.with_compatibility}") - schema_registry.compatible?(fullname, schema, 'latest', with_compatibility: compatibility_break.with_compatibility) + schema_registry.compatible?( + fullname, schema, 'latest', with_compatibility: compatibility_break.with_compatibility + ) else false end end @@ -102,15 +107,17 @@ end logger.info("... Compatibility with last version: #{compatibility_with_last}") logger.info(Diffy::Diff.new(last_json, json, context: 3).to_s) unless compatibility_with_last == FULL - compatibility = schema_registry.subject_config(fullname)['compatibility'] || schema_registry.global_config['compatibility'] + compatibility = schema_registry.subject_config(fullname)['compatibility'] || + schema_registry.global_config['compatibility'] compatibility = FULL if compatibility == BOTH logger.info("... Current compatibility level: #{compatibility}") logger.info( "\n To allow a compatibility break, run:\n" \ - " rake avro:add_compatibility_break name=#{fullname} fingerprint=#{fingerprint} with_compatibility=#{compatibility_with_last} [after_compatibility=<LEVEL>]\n" + " rake avro:add_compatibility_break name=#{fullname} fingerprint=#{fingerprint} " \ + "with_compatibility=#{compatibility_with_last} [after_compatibility=<LEVEL>]\n" ) end def build_schema_registry AvroSchemaRegistry::Client.new(Avrolution.compatibility_schema_registry_url,