Froze rails gems
[depot.git] / vendor / rails / activerecord / lib / active_record / schema.rb
1 module ActiveRecord
2 # Allows programmers to programmatically define a schema in a portable
3 # DSL. This means you can define tables, indexes, etc. without using SQL
4 # directly, so your applications can more easily support multiple
5 # databases.
6 #
7 # Usage:
8 #
9 # ActiveRecord::Schema.define do
10 # create_table :authors do |t|
11 # t.string :name, :null => false
12 # end
13 #
14 # add_index :authors, :name, :unique
15 #
16 # create_table :posts do |t|
17 # t.integer :author_id, :null => false
18 # t.string :subject
19 # t.text :body
20 # t.boolean :private, :default => false
21 # end
22 #
23 # add_index :posts, :author_id
24 # end
25 #
26 # ActiveRecord::Schema is only supported by database adapters that also
27 # support migrations, the two features being very similar.
28 class Schema < Migration
29 private_class_method :new
30
31 # Eval the given block. All methods available to the current connection
32 # adapter are available within the block, so you can easily use the
33 # database definition DSL to build up your schema (+create_table+,
34 # +add_index+, etc.).
35 #
36 # The +info+ hash is optional, and if given is used to define metadata
37 # about the current schema (currently, only the schema's version):
38 #
39 # ActiveRecord::Schema.define(:version => 20380119000001) do
40 # ...
41 # end
42 def self.define(info={}, &block)
43 instance_eval(&block)
44
45 unless info[:version].blank?
46 initialize_schema_migrations_table
47 assume_migrated_upto_version info[:version]
48 end
49 end
50 end
51 end