Skip to content

Commit

Permalink
Allow default compatibility to be set via environment and change non-…
Browse files Browse the repository at this point in the history
…production default (#59)
  • Loading branch information
tjwp authored Jan 24, 2018
1 parent 5f7b4a6 commit f6a7588
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 1 addition & 2 deletions app/models/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
# config/environments/production.rb.

config.log_level = :debug

config.x.default_compatibility = ENV.fetch('DEFAULT_COMPATIBILITY', 'NONE')
end
3 changes: 3 additions & 0 deletions config/initializers/default_compatibility.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/requests/subject_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6a7588

Please sign in to comment.