Skip to content

Commit

Permalink
Merge pull request #87 from tocktix/allow-additions-to-dsn
Browse files Browse the repository at this point in the history
Allow custom additions to general DSN via environment variable
  • Loading branch information
xjunior authored Jan 23, 2023
2 parents 3bf871e + 806d32d commit 011c5a9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Please follow the format in [Keep a Changelog](http://keepachangelog.com/)

## [Unreleased]
- Support for connection to MySQL server over socket
- Support appending items to the general DSN. Used to apply workaround for [PT-2126](https://jira.percona.com/browse/PT-2126)

## [6.4.0] - 2020-06-23

Expand Down
5 changes: 3 additions & 2 deletions lib/departure/dsn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ class DSN
def initialize(database, table_name)
@database = database
@table_name = table_name
@suffix = ENV.fetch('PERCONA_DSN_SUFFIX', nil)
end

# Returns the pt-online-schema-change DSN string. See
# https://www.percona.com/doc/percona-toolkit/2.0/pt-online-schema-change.html#dsn-options
def to_s
"D=#{database},t=#{table_name}"
"D=#{database},t=#{table_name}#{suffix.nil? ? nil : ',' + suffix}"
end

private

attr_reader :table_name, :database
attr_reader :table_name, :database, :suffix
end
end
20 changes: 19 additions & 1 deletion spec/departure/dsn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@
let(:database) { 'development' }
let(:table_name) { 'comments' }

around do |example|
ClimateControl.modify(env_var) do
example.run
end
end

describe '#to_s' do
subject { described_class.new(database, table_name).to_s }
it { is_expected.to eq('D=development,t=comments') }
let(:env_var) { {} }

context 'when a DSN suffix is not specified' do
it { is_expected.to eq('D=development,t=comments') }
end

context 'when a DSN suffix is specified' do
let(:env_var) { { PERCONA_DSN_SUFFIX: 'P=3306' } }

it 'tests for environment modification' do
is_expected.to eq('D=development,t=comments,P=3306')
end
end
end
end

0 comments on commit 011c5a9

Please sign in to comment.