]> git.openstreetmap.org Git - chef.git/commitdiff
Force database drops on postgres versions which support it
authorTom Hughes <tom@compton.nu>
Wed, 9 Mar 2022 19:30:36 +0000 (19:30 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 9 Mar 2022 19:30:36 +0000 (19:30 +0000)
cookbooks/postgresql/libraries/postgresql.rb
cookbooks/postgresql/resources/database.rb

index feaa508b9c9ff5bccb5854e5694aba36bfa6085c..62188795bd3f3aa6d168e5b172bdae217533f250 100644 (file)
@@ -12,6 +12,10 @@ module OpenStreetMap
       @cluster = cluster
     end
 
+    def version
+      @cluster.split("/").first.to_f
+    end
+
     def execute(options)
       # Create argument array
       args = []
index 2d14cdfd15421847b0d9767a9ce728c76e4a6e9d..cd2d4c7644f27f9bcac74ac326ab64dbcd2a8730 100644 (file)
@@ -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