Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

In some Rails model definitions, there is a comment block at the top that contains the schema information.

# == 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?

like image 442
readonly Avatar asked Jan 26 '09 22:01

readonly


People also ask

What is schema RB used for?

The schema. rb serves mainly two purposes: It documents the final current state of the database schema. Often, especially when you have more than a couple of migrations, it's hard to deduce the schema just from the migrations alone.

What are Ruby models?

What are models? In simple terms, models are Ruby classes that can holds value of a single row in a database table. Since they all inherit ActiveRecord::Base through ApplicationRecord class, they are equipped with all the ActiveRecord methods which enables them to interact with the database.


2 Answers

Seems like output of the annotate_models plugin. Just install it and run annotate in your rails root and the schema information will update automatically. Ideally, run it after each migration.

like image 128
Milan Novota Avatar answered Oct 23 '22 07:10

Milan Novota


You could also use the annotate-models gem. It's a bit less intrusive as there's no plugin needed.

Usage:

% gem install annotate % annotate Annotated Product, User, Role 
like image 41
reto Avatar answered Oct 23 '22 05:10

reto