我想定义一个简单的方法,当通过迁移删除特定表时,获得用户输入的确认,如下所示。
def confirm_drop(table)
if table_exists?(table)
puts "Warning: Did not drop table to protect data."
puts "Drop the table? [y]es | [n]o | [c]ancel"
answer = STDIN.gets.chomp
if (answer == "y" or answer == "yes")
drop_table :table
elsif (answer == "c" or answer == "cancel")
raise exception "Canceled Migration"
elsif (answer != "n" or answer == "no")
raise exception "Input was something other than. [y]es | [n]o | [c]ancel"
end
end
end
答案 0 :(得分:0)
我不建议根据用户输入进行迁移,因为它可能在开发中可以正常运行,但在发布到生产环境时则不能。尤其是在使用CI服务器的情况下。