From: Tom Hughes Date: Wed, 9 Mar 2022 19:30:36 +0000 (+0000) Subject: Force database drops on postgres versions which support it X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/397bc17e69d0ff6716d1beb0741f1719d6183d81?ds=inline Force database drops on postgres versions which support it --- diff --git a/cookbooks/postgresql/libraries/postgresql.rb b/cookbooks/postgresql/libraries/postgresql.rb index feaa508b9..62188795b 100644 --- a/cookbooks/postgresql/libraries/postgresql.rb +++ b/cookbooks/postgresql/libraries/postgresql.rb @@ -12,6 +12,10 @@ module OpenStreetMap @cluster = cluster end + def version + @cluster.split("/").first.to_f + end + def execute(options) # Create argument array args = [] diff --git a/cookbooks/postgresql/resources/database.rb b/cookbooks/postgresql/resources/database.rb index 2d14cdfd1..cd2d4c764 100644 --- a/cookbooks/postgresql/resources/database.rb +++ b/cookbooks/postgresql/resources/database.rb @@ -43,7 +43,11 @@ end action :drop do if cluster.databases.include?(new_resource.database) converge_by "drop database #{new_resource.database}" do - cluster.execute(:command => "DROP DATABASE \"#{new_resource.database}\"") + if cluster.version >= 13 + cluster.execute(:command => "DROP DATABASE \"#{new_resource.database}\" WITH (FORCE)") + else + cluster.execute(:command => "DROP DATABASE \"#{new_resource.database}\"") + end end end end