Skip to content

Commit

Permalink
Validate delta_count value against pull_batch_count (#164)
Browse files Browse the repository at this point in the history
* Validate delta_count value against pull_batch_count

* Make linter happy

* Add Jetbrains IDEs to gitignore
  • Loading branch information
tanelsuurhans authored Aug 20, 2024
1 parent aa05f82 commit bea83d2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/pkg/
/spec/reports/
/tmp/
/.idea/

# rspec failure tracking
.rspec_status
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ PLATFORMS
arm64-darwin-20
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
4 changes: 4 additions & 0 deletions lib/pg_online_schema_change/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def handle_validations
raise Error, "Not a valid ALTER statement: #{@alter_statement}"
end

if delta_count > pull_batch_count
raise Error, "Value for delta_count should be smaller than the value for pull_batch_count"
end

return if Query.same_table?(@alter_statement)

raise Error, "All statements should belong to the same table: #{@alter_statement}"
Expand Down
9 changes: 9 additions & 0 deletions spec/lib/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
)
end

it "raises error if delta count is smaller than pull batch count" do
options = client_options.to_h.merge(delta_count: 100, pull_batch_count: 50)
client_options = Struct.new(*options.keys).new(*options.values)
expect { described_class.new(client_options) }.to raise_error(
PgOnlineSchemaChange::Error,
"Value for delta_count should be smaller than the value for pull_batch_count",
)
end

describe "handle_copy_statement" do
it "reads file and sets statement" do
query = <<~SQL
Expand Down

0 comments on commit bea83d2

Please sign in to comment.