From 0a844a1912934bf5ea235f91578f5b212059119f Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 12 Mar 2026 18:19:06 +0000 Subject: [PATCH] Allow postgresql_execute to wrap commands in a transaction --- cookbooks/postgresql/libraries/postgresql.rb | 3 +++ cookbooks/postgresql/resources/execute.rb | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cookbooks/postgresql/libraries/postgresql.rb b/cookbooks/postgresql/libraries/postgresql.rb index 789120d6b..598f94344 100644 --- a/cookbooks/postgresql/libraries/postgresql.rb +++ b/cookbooks/postgresql/libraries/postgresql.rb @@ -35,6 +35,9 @@ module OpenStreetMap # Set output format args.push("--no-align") unless options.fetch(:align, true) + # Run command in a transaction if requested + args.push("--single-transaction") if options.fetch(:transaction, false) + # Add any SQL command to execute if options[:command] args.push("--command") diff --git a/cookbooks/postgresql/resources/execute.rb b/cookbooks/postgresql/resources/execute.rb index 4f7217ec8..1c32f392f 100644 --- a/cookbooks/postgresql/resources/execute.rb +++ b/cookbooks/postgresql/resources/execute.rb @@ -26,9 +26,15 @@ property :cluster, :kind_of => String, :required => true property :database, :kind_of => String, :required => true property :user, :kind_of => String, :default => "postgres" property :group, :kind_of => String, :default => "postgres" +property :transaction, :kind_of => [TrueClass, FalseClass], :default => false action :run do - options = { :database => new_resource.database, :user => new_resource.user, :group => new_resource.group } + options = { + :database => new_resource.database, + :user => new_resource.user, + :group => new_resource.group, + :transaction => new_resource.transaction + } converge_by "execute #{new_resource.command}" do if ::File.exist?(new_resource.command) -- 2.47.3