Skip to content

Commit

Permalink
Allow schema_dump database config to be set via DATABASE_URL
Browse files Browse the repository at this point in the history
In `database.yml`, `schema_dump` can currently be set to `false`, `nil` or a file path.

I found that if you configure your database via DATABASE_URL, the false value does not work because it comes through as a string.

This change allows `?schema_dump=false` to disable the dump via database_url.
  • Loading branch information
mscoutermarsh committed Jan 14, 2024
1 parent 4fb230d commit 67549bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def initialize(env_name, name, url, configuration_hash = {})
@configuration_hash = @configuration_hash.merge(build_url_hash).freeze
end

def schema_dump(format = ActiveRecord.schema_format)
schema_dump_config = super(format)
return nil if schema_dump_config == "false"

schema_dump_config
end

private
# Return a Hash that can be merged into the main config that represents
# the passed in url
Expand Down
24 changes: 24 additions & 0 deletions activerecord/test/cases/database_configurations/url_config_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "cases/helper"

module ActiveRecord
class DatabaseConfigurations
class UrlConfigTest < ActiveRecord::TestCase
def test_schema_dump_set_to_false
config = UrlConfig.new("default_env", "primary", "postges://localhost/foo?schema_dump=false", {})
assert_nil config.schema_dump
end

def test_schema_dump_set_to_path
config = UrlConfig.new("default_env", "primary", "postges://localhost/foo?schema_dump=db/foo_schema.rb", {})
assert_equal "db/foo_schema.rb", config.schema_dump
end

def test_schema_dump_unset
config = UrlConfig.new("default_env", "primary", "postges://localhost/foo", {})
assert_equal "schema.rb", config.schema_dump
end
end
end
end

0 comments on commit 67549bc

Please sign in to comment.