Skip to content

Commit 35881c9

Browse files
authored
Remove unnecessary explicit adapter requires from monkeypatch (#5086)
The sequel_case_insensitive_string_monkeypatch unconditionally required sequel/adapters/postgres and sequel/adapters/mysql2, even though the file is only ever loaded via DBMigrator.apply_migrations after a DB connection is already established (which auto-loads the adapter). Replace the explicit requires with `defined?` guards so each adapter is only patched when actually in use. This avoids loading cross-adapter code unnecessarily and makes tests that reference adapter-specific constants (like Sequel::Postgres::Dataset) fail visibly when the adapter is not loaded, rather than being silently masked.
1 parent 143fa87 commit 35881c9

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

lib/vcap/sequel_case_insensitive_string_monkeypatch.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
require 'sequel'
2-
require 'sequel/adapters/postgres'
3-
require 'sequel/adapters/mysql2'
42

53
# Add :case_insensitive as an option to the string type during migrations.
64
# This results in case insensitive comparisions for indexing and querying, but
@@ -26,24 +24,28 @@
2624
# In the above migration, name will will have case insensitive comparisions,
2725
# but case preserving data, whereas base64_data will be case sensitive.
2826

29-
Sequel::Postgres::Database.class_eval do
30-
def case_insensitive_string_column_type
31-
'CIText'
32-
end
27+
if defined?(Sequel::Postgres::Database)
28+
Sequel::Postgres::Database.class_eval do
29+
def case_insensitive_string_column_type
30+
'CIText'
31+
end
3332

34-
def case_insensitive_string_column_opts
35-
{}
33+
def case_insensitive_string_column_opts
34+
{}
35+
end
3636
end
3737
end
3838

39-
Sequel::Mysql2::Database.class_eval do
40-
# Mysql is case insensitive by default
41-
def case_insensitive_string_column_type
42-
'VARCHAR(255)'
43-
end
39+
if defined?(Sequel::Mysql2::Database)
40+
Sequel::Mysql2::Database.class_eval do
41+
# Mysql is case insensitive by default
42+
def case_insensitive_string_column_type
43+
'VARCHAR(255)'
44+
end
4445

45-
def case_insensitive_string_column_opts
46-
{ collate: 'utf8_general_ci' }
46+
def case_insensitive_string_column_opts
47+
{ collate: 'utf8_general_ci' }
48+
end
4749
end
4850
end
4951

0 commit comments

Comments
 (0)