discourse/lib/freedom_patches/schema_migration_details.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

57 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module FreedomPatches
module SchemaMigrationDetails
def exec_migration(conn, direction)
rval = nil
time = Benchmark.measure do
rval = super
end
sql = <<SQL
INSERT INTO schema_migration_details(
version,
hostname,
name,
git_version,
duration,
direction,
rails_version,
created_at
) values (
:version,
:hostname,
:name,
:git_version,
:duration,
:direction,
:rails_version,
:created_at
)
SQL
hostname = `hostname` rescue ""
sql = ActiveRecord::Base.public_send(:sanitize_sql_array, [sql, {
version: version || "",
duration: (time.real * 1000).to_i,
hostname: hostname,
name: name,
git_version: Discourse.git_version,
created_at: Time.zone.now,
direction: direction.to_s,
rails_version: Rails.version
}])
conn.execute(sql)
rval
end
end
end
class ActiveRecord::Migration
prepend FreedomPatches::SchemaMigrationDetails
end