Skip to content

Commit

Permalink
fix: support database.yml with explicit primary
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorton committed Mar 16, 2024
1 parent 7a07e29 commit 99ecb90
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/veksel/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def self.fork
require 'fileutils'

config = read_config('config/database.yml')[:development]
if config.key?(:primary)
config = config[:primary]
$stderr.puts "Warning: Only your primary database will be forked"
end

target_database = config[:database] + Veksel.suffix
db = OpenStruct.new(configuration_hash: config, database: target_database)
Expand Down
19 changes: 19 additions & 0 deletions test/dummy/config/database.primary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
development:
primary:
adapter: postgresql
encoding: unicode
database: veksel_dummy_development
port: 5555
host: localhost
username: veksel
password: foobar

test:
primary:
adapter: postgresql
encoding: unicode
database: veksel_dummy_test
port: 5555
host: localhost
username: veksel
password: foobar
10 changes: 10 additions & 0 deletions test/veksel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def run_fork_test
end
end
end

test "veksel fork should work when using primary: db config" do
swap_db_config('database.primary.yml') do
Dir.chdir('test/dummy') do
git_checkout('somebranch') do
run_fork_test
end
end
end
end
end

test "performance" do
Expand Down

0 comments on commit 99ecb90

Please sign in to comment.