2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-17 14:47:47 +08:00
|
|
|
module FreedomPatches
|
|
|
|
module SchemaMigrationDetails
|
|
|
|
def exec_migration(conn, direction)
|
|
|
|
rval = nil
|
|
|
|
|
|
|
|
time = Benchmark.measure do
|
2017-07-28 09:20:09 +08:00
|
|
|
rval = super
|
2016-02-17 14:47:47 +08:00
|
|
|
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 ""
|
2019-05-07 09:27:05 +08:00
|
|
|
sql = ActiveRecord::Base.public_send(:sanitize_sql_array, [sql, {
|
2016-02-17 14:47:47 +08:00
|
|
|
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
|