From f6a7588c1ea287653d437348830f90f5f834af5c Mon Sep 17 00:00:00 2001 From: Tim Perkins Date: Wed, 24 Jan 2018 08:44:33 -0500 Subject: [PATCH] Allow default compatibility to be set via environment and change non-production default (#59) --- CHANGELOG.md | 2 ++ app/models/config.rb | 3 +-- config/application.rb | 2 ++ config/environments/production.rb | 3 +++ config/environments/staging.rb | 2 ++ config/initializers/default_compatibility.rb | 3 +++ spec/requests/subject_api_spec.rb | 5 +++++ 7 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 config/initializers/default_compatibility.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index ba396b1b..8d6d7e60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## v0.12.0 (unreleased) - Upgrade to Ruby 2.4.2. - Upgrade to Rails 5.1. +- Allow default compatibility level to be set via environment variable and + change the default for non-production environments. ## v0.11.0 - Change the default fingerprint version to '2'. Set `FINGERPRINT_VERSION=1` diff --git a/app/models/config.rb b/app/models/config.rb index 7fd06a3b..88c27d02 100644 --- a/app/models/config.rb +++ b/app/models/config.rb @@ -12,7 +12,6 @@ class Config < ApplicationRecord # This default differs from the Confluent default of BACKWARD - DEFAULT_COMPATIBILITY = Compatibility::Constants::FULL_TRANSITIVE COMPATIBILITY_NAME = 'compatibility'.freeze belongs_to :subject @@ -28,7 +27,7 @@ def compatibility=(value) def self.global find_or_create_by!(id: 0) do |config| - config.compatibility = DEFAULT_COMPATIBILITY + config.compatibility = Rails.application.config.x.default_compatibility end end diff --git a/config/application.rb b/config/application.rb index 3d498253..a73218b3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -38,5 +38,7 @@ class Application < Rails::Application config.x.disable_schema_registration = ENV['DISABLE_SCHEMA_REGISTRATION'] == 'true' config.x.read_only_mode = ENV['READ_ONLY_MODE'] == 'true' + + config.x.default_compatibility = ENV.fetch('DEFAULT_COMPATIBILITY', 'NONE') end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 02701f52..6a1790ba 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -78,4 +78,7 @@ unless config.x.disable_password config.x.app_password = ENV.fetch('SCHEMA_REGISTRY_PASSWORD') end + + # This default differs from the Confluent default of BACKWARD + config.x.default_compatibility = ENV.fetch('DEFAULT_COMPATIBILITY', 'FULL_TRANSITIVE') end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index a983e9e1..59c4c8f8 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -5,4 +5,6 @@ # config/environments/production.rb. config.log_level = :debug + + config.x.default_compatibility = ENV.fetch('DEFAULT_COMPATIBILITY', 'NONE') end diff --git a/config/initializers/default_compatibility.rb b/config/initializers/default_compatibility.rb new file mode 100644 index 00000000..b3bd9e24 --- /dev/null +++ b/config/initializers/default_compatibility.rb @@ -0,0 +1,3 @@ +if Compatibility::Constants::VALUES.exclude?(Rails.application.config.x.default_compatibility.upcase) + raise "Default compatibility '#{Rails.application.config.x.default_compatibility}' is invalid" +end diff --git a/spec/requests/subject_api_spec.rb b/spec/requests/subject_api_spec.rb index 2d914ded..8dc87add 100644 --- a/spec/requests/subject_api_spec.rb +++ b/spec/requests/subject_api_spec.rb @@ -463,6 +463,11 @@ end context "when a previous version of the schema is registered under the subject" do + before do + allow(Rails.application.config.x).to receive(:default_compatibility) + .and_return(Compatibility::Constants::FULL_TRANSITIVE) + end + let!(:version) { create(:schema_version) } let(:subject) { version.subject } let(:json) do