lib/strong_migrations/checker.rb in strong_migrations-0.7.6 vs lib/strong_migrations/checker.rb in strong_migrations-0.7.7
- old
+ new
@@ -338,15 +338,11 @@
result = yield
# outdated statistics + a new index can hurt performance of existing queries
if StrongMigrations.auto_analyze && direction == :up && method == :add_index
- if postgresql?
- connection.execute "ANALYZE #{connection.quote_table_name(args[0].to_s)}"
- elsif mariadb? || mysql?
- connection.execute "ANALYZE TABLE #{connection.quote_table_name(args[0].to_s)}"
- end
+ analyze_table(args[0])
end
result
end
@@ -394,12 +390,11 @@
def version
@migration.version
end
def safe?
- @safe || ENV["SAFETY_ASSURED"] || @migration.is_a?(ActiveRecord::Schema) ||
- (direction == :down && !StrongMigrations.check_down) || version_safe?
+ @safe || ENV["SAFETY_ASSURED"] || (direction == :down && !StrongMigrations.check_down) || version_safe?
end
def version_safe?
version && version <= StrongMigrations.start_after
end
@@ -503,9 +498,17 @@
if timeout.is_a?(String)
timeout
else
# use ceil to prevent no timeout for values under 1 ms
(timeout.to_f * 1000).ceil
+ end
+ end
+
+ def analyze_table(table)
+ if postgresql?
+ connection.execute "ANALYZE #{connection.quote_table_name(table.to_s)}"
+ elsif mariadb? || mysql?
+ connection.execute "ANALYZE TABLE #{connection.quote_table_name(table.to_s)}"
end
end
def constraints(table_name)
query = <<~SQL