简体   繁体   English

rails 何时更新包含模型架构信息的注释块?

[英]When does the comment block with schema information for the model get updated by rails?

In some Rails model definitions, there is a comment block at the top that contains the schema information.在某些 Rails 模型定义中,顶部有一个注释块,其中包含模式信息。

# == Schema Information                                   
# Schema version: 20090122060318                          
#                                                         
# Table name: table_name
#                                                         
#  id            :integer(4)      not null, primary key   
...

When does this get updated?这个什么时候更新? Is it only generated once, when you use the generator script to create the model?当您使用生成器脚本创建模型时,它是否只生成一次? Is there a way to update this block when migrations are performed?有没有办法在执行迁移时更新这个块?

Seems like output of the annotate_models plugin.似乎是annotate_models插件的输出。 Just install it and run annotate in your rails root and the schema information will update automatically.只需安装它并在 Rails 根目录中运行annotate ,架构信息就会自动更新。 Ideally, run it after each migration.理想情况下,在每次迁移后运行它。

You could also use the annotate-models gem.您还可以使用annotate-models gem。 It's a bit less intrusive as there's no plugin needed.由于不需要插件,因此侵入性较小。

Usage:用法:

% gem install annotate
% annotate
Annotated Product, User, Role

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM