检查表中存在的Rails [英] Check if a table exists in Rails

查看:151
本文介绍了检查表中存在的Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个rake任务,将无法正常工作,除非表存在。我有超过20名工程师在网站上的工作,所以我想,以确保他们在迁移表才可以做一个rake任务,将填充了相应的表格。

I have a rake task that won't work unless a table exists. I'm working with more than 20 engineers on a website so I want to make sure they have migrated the table before they can do a rake task which will populate that respective table.

AR是否有一个方法,例如 Table.exists ?我怎么能确保他们已成功迁移的表?

Does AR have a method such as Table.exists? How can I make sure they have migrated the table successfully?

推荐答案

在轨道2,3及4:

# Gives you a listing
ActiveRecord::Base.connection.tables
# Checks for existence of kittens table (Kitten model)
ActiveRecord::Base.connection.table_exists? 'kittens'

# Tells you all migrations run
ActiveRecord::Migrator.get_all_versions
# Tells you the current schema version
ActiveRecord::Migrator.current_version

这篇关于检查表中存在的Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆