开发者

Is there a way in rails to find out what migrations have already been applied at run-time?

I would like to add the current migration level to an internal dashboard we use for server statistics? Is there an 开发者_开发问答easy build in way to support this?


You can query the contents of the migrations table directly. You'll get back an array of hashes containing everything in the migrations table, which will tell you which migrations are currently up:

# Get the SQL connection adapter
connection = ActiveRecord::Base.connection

# Get the migrations table name
migrations_table = ActiveRecord::Migrator.schema_migrations_table_name

# Execute query
connection.execute("select * from #{migrations_table}")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜