Skip to content

Commit b1edb6f

Browse files
committed
Lazy load warning about not having text column
1 parent c46f433 commit b1edb6f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/flipper/adapters/active_record.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def initialize(options = {})
6161
@name = options.fetch(:name, :active_record)
6262
@feature_class = options.fetch(:feature_class) { Feature }
6363
@gate_class = options.fetch(:gate_class) { Gate }
64-
65-
warn VALUE_TO_TEXT_WARNING if value_not_text?
6664
end
6765

6866
# Public: The set of known features.
@@ -289,15 +287,23 @@ def result_for_gates(feature, gates)
289287
# Check if value column is text instead of string
290288
# See https://github.com/flippercloud/flipper/pull/692
291289
def value_not_text?
292-
@gate_class.column_for_attribute(:value).type != :text
290+
with_connection(@gate_class) do |connection|
291+
@gate_class.column_for_attribute(:value).type != :text
292+
end
293293
rescue ::ActiveRecord::ActiveRecordError => error
294294
# If the table doesn't exist, the column doesn't exist either
295295
warn "#{error.message}. You likely need to run `rails g flipper:active_record` and/or `rails db:migrate`."
296296
end
297297

298298
def with_connection(model = @feature_class, &block)
299+
warn VALUE_TO_TEXT_WARNING if !warned_about_value_not_text? && value_not_text?
299300
model.connection_pool.with_connection(&block)
300301
end
302+
303+
def warned_about_value_not_text?
304+
return @warned_about_value_not_text if defined?(@warned_about_value_not_text)
305+
@warned_about_value_not_text = true
306+
end
301307
end
302308
end
303309
end

0 commit comments

Comments
 (0)