After quick googling I didn't find ready-made method of achieving this without raw SQL. You can, however, make your own solution by mimicking what annotate_models does.
A piece from https://github.com/ctran/annotate_models/blob/master/lib/annotate/annotate_models.rb
# Use the column information in an ActiveRecord class
# to create a comment block containing a line for
# each column. The line contains the column name,
# the type (and length), and any optional attributes
def get_schema_info(klass, header, options = {})
info = "# #{header}\n#\n"
info << "# Table name: #{klass.table_name}\n#\n"
max_size = klass.column_names.collect{|name| name.size}.max + 1
klass.columns.each do |col|
attrs = []
attrs << "default(#{quote(col.default)})" unless col.default.nil?
attrs << "not null" unless col.null
attrs << "primary key" if col.name == klass.primary_key
col_type = col.type.to_s
if col_type == "decimal"
col_type << "(#{col.precision}, #{col.scale})"
Also, you might want to read what ActiveRecord Migrations Guide has to offer.
ActiveRecord::Schema.define(:version => 20080906171750) do
create_table "authors", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
end
This file is created by inspecting the database and expressing its structure using create_table, add_index, and so on. Because this is database-independent, it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.
There is however a trade-off: db/schema.rb cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to :sql.
Instead of using Active Record’s schema dumper, the database’s structure will be dumped using a tool specific to the database (via the db:structure:dump Rake task) into db/structure.sql. For example, for the PostgreSQL RDBMS, the pg_dump utility is used. For MySQL, this file will contain the output of SHOW CREATE TABLE for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database’s structure. Using the :sql schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
show create table, right? You just don't want to call it yourself? :)