-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconnection_patches.rb
More file actions
66 lines (52 loc) · 1.53 KB
/
connection_patches.rb
File metadata and controls
66 lines (52 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require "active_record"
require "active_support/concern"
require "active_id/railtie" if defined?(Rails::Railtie)
module ActiveID
module ConnectionPatches
module ColumnMethods
def uuid(*args, **options)
args.each { |name| column(name, :uuid, **options) }
end
end
module Quoting
extend ActiveSupport::Concern
def self.prepended(_klass)
def native_database_types
super.merge(uuid: { name: "binary", limit: 16 })
end
end
end
module PostgreSQLQuoting
extend ActiveSupport::Concern
def self.prepended(_klass)
def native_database_types
super.merge(uuid: { name: "uuid" })
end
end
end
module ConnectionHandling
def establish_connection(*_args) # rubocop:disable Metrics/MethodLength
super
arca = ActiveRecord::ConnectionAdapters
arca::Table.include(ColumnMethods)
arca::TableDefinition.include(ColumnMethods)
if defined? arca::MysqlAdapter
arca::MysqlAdapter.prepend(Quoting)
end
if defined? arca::Mysql2Adapter
arca::Mysql2Adapter.prepend(Quoting)
end
if defined? arca::SQLite3Adapter
arca::SQLite3Adapter.prepend(Quoting)
end
if defined? arca::PostgreSQLAdapter
arca::PostgreSQLAdapter.prepend(PostgreSQLQuoting)
end
end
end
def self.apply!
ActiveRecord::Base.singleton_class.prepend ConnectionHandling
end
end
end
ActiveID::ConnectionPatches.apply!