gpt4 book ai didi

ruby-on-rails - 有没有办法在 rails 中找出在运行时已经应用了哪些迁移?

转载 作者:行者123 更新时间:2023-12-04 06:16:12 26 4
gpt4 key购买 nike

我想将当前迁移级别添加到我们用于服务器统计的内部仪表板?是否有一种简单的构建方式来支持这一点?

最佳答案

您可以直接查询迁移表的内容。您将返回一个包含迁移表中所有内容的哈希数组,它会告诉您当前正在进行哪些迁移:

# 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}")

关于ruby-on-rails - 有没有办法在 rails 中找出在运行时已经应用了哪些迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7209835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com