mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
FEATURE: start tracking information about migrations that run
This commit adds a new tracking table that lets us know - When a migration ran - What version Discourse was at - How long it took - What version Rails was at The built in tracking in Rails is very limited, does not track this info
This commit is contained in:
54
lib/freedom_patches/schema_migration_details.rb
Normal file
54
lib/freedom_patches/schema_migration_details.rb
Normal file
@ -0,0 +1,54 @@
|
||||
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.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
|
Reference in New Issue
Block a user