Skip to content

Commit

Permalink
Move connection-specific code
Browse files Browse the repository at this point in the history
  • Loading branch information
teoljungberg committed May 25, 2024
1 parent feeef19 commit 6516a66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 1 addition & 9 deletions lib/fx/adapters/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def update_trigger(name, on:, sql_definition:)
#
# @return [void]
def drop_function(name)
if support_drop_function_without_args
if connection.support_drop_function_without_args
execute("DROP FUNCTION #{name};")
else
execute("DROP FUNCTION #{name}();")
Expand Down Expand Up @@ -154,14 +154,6 @@ def drop_trigger(name, on:)
def connection
Connection.new(connectable.connection)
end

def support_drop_function_without_args
# https://www.postgresql.org/docs/9.6/sql-dropfunction.html
# https://www.postgresql.org/docs/10/sql-dropfunction.html

pg_connection = connectable.connection.raw_connection
pg_connection.server_version >= 10_00_00
end
end
end
end
19 changes: 19 additions & 0 deletions lib/fx/adapters/postgres/connection.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
module Fx
module Adapters
class Postgres
# Decorates an ActiveRecord connection with methods that help determine
# the connections capabilities.
#
# Every attempt is made to use the versions of these methods defined by
# Rails where they are available and public before falling back to our own
# implementations for older Rails versions.
#
# @api private
class Connection < SimpleDelegator
# https://www.postgresql.org/docs/9.6/sql-dropfunction.html
# https://www.postgresql.org/docs/10/sql-dropfunction.html
def support_drop_function_without_args
pg_connection = undecorated_connection.raw_connection
pg_connection.server_version >= 10_00_00
end

private

def undecorated_connection
__getobj__
end
end
end
end
Expand Down

0 comments on commit 6516a66

Please sign in to comment.