From 397bc17e69d0ff6716d1beb0741f1719d6183d81 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 9 Mar 2022 19:30:36 +0000 Subject: [PATCH] Force database drops on postgres versions which support it --- cookbooks/postgresql/libraries/postgresql.rb | 4 ++++ cookbooks/postgresql/resources/database.rb | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) 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 -- 2.39.5