Skip to content
This repository
Browse code

Adds title.

  • Loading branch information...
commit c86915450af4ee800ca3eba474fe6d01c865c4c3 1 parent cef442f
Rizwan Reza authored June 15, 2010
3  activerecord/lib/active_record/errors.rb
... ...
@@ -1,4 +1,7 @@
1 1
 module ActiveRecord
  2
+
  3
+  # = Active Record Errors
  4
+  #
2 5
   # Generic Active Record exception class.
3 6
   class ActiveRecordError < StandardError
4 7
   end
98  activerecord/lib/active_record/migration.rb
@@ -29,11 +29,15 @@ def initialize(name)
29 29
     end
30 30
   end
31 31
 
32  
-  # Migrations can manage the evolution of a schema used by several physical databases. It's a solution
33  
-  # to the common problem of adding a field to make a new feature work in your local database, but being unsure of how to
34  
-  # push that change to other developers and to the production server. With migrations, you can describe the transformations
35  
-  # in self-contained classes that can be checked into version control systems and executed against another database that
36  
-  # might be one, two, or five versions behind.
  32
+  # Active Record Migrations
  33
+  # 
  34
+  # Migrations can manage the evolution of a schema used by several physical 
  35
+  # databases. It's a solution to the common problem of adding a field to make
  36
+  # a new feature work in your local database, but being unsure of how to
  37
+  # push that change to other developers and to the production server. With 
  38
+  # migrations, you can describe the transformations in self-contained classes
  39
+  # that can be checked into version control systems and executed against 
  40
+  # another database that might be one, two, or five versions behind.
37 41
   #
38 42
   # Example of a simple migration:
39 43
   #
@@ -47,10 +51,13 @@ def initialize(name)
47 51
   #     end
48 52
   #   end
49 53
   #
50  
-  # This migration will add a boolean flag to the accounts table and remove it if you're backing out of the migration.
51  
-  # It shows how all migrations have two class methods +up+ and +down+ that describes the transformations required to implement
52  
-  # or remove the migration. These methods can consist of both the migration specific methods like add_column and remove_column,
53  
-  # but may also contain regular Ruby code for generating data needed for the transformations.
  54
+  # This migration will add a boolean flag to the accounts table and remove it 
  55
+  # if you're backing out of the migration. It shows how all migrations have 
  56
+  # two class methods +up+ and +down+ that describes the transformations 
  57
+  # required to implement or remove the migration. These methods can consist
  58
+  # of both the migration specific methods like add_column and remove_column,
  59
+  # but may also contain regular Ruby code for generating data needed for the 
  60
+  # transformations.
54 61
   #
55 62
   # Example of a more complex migration that also needs to initialize data:
56 63
   #
@@ -64,7 +71,9 @@ def initialize(name)
64 71
   #         t.integer  :position
65 72
   #       end
66 73
   #
67  
-  #       SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
  74
+  #       SystemSetting.create  :name => "notice", 
  75
+  #                             :label => "Use notice?", 
  76
+  #                             :value => 1
68 77
   #     end
69 78
   #
70 79
   #     def self.down
@@ -72,35 +81,49 @@ def initialize(name)
72 81
   #     end
73 82
   #   end
74 83
   #
75  
-  # This migration first adds the system_settings table, then creates the very first row in it using the Active Record model
76  
-  # that relies on the table. It also uses the more advanced create_table syntax where you can specify a complete table schema
77  
-  # in one block call.
  84
+  # This migration first adds the system_settings table, then creates the very 
  85
+  # first row in it using the Active Record model that relies on the table. It
  86
+  # also uses the more advanced create_table syntax where you can specify a 
  87
+  # complete table schema in one block call.
78 88
   #
79 89
   # == Available transformations
80 90
   #
81  
-  # * <tt>create_table(name, options)</tt> Creates a table called +name+ and makes the table object available to a block
82  
-  #   that can then add columns to it, following the same format as add_column. See example above. The options hash is for
83  
-  #   fragments like "DEFAULT CHARSET=UTF-8" that are appended to the create table definition.
  91
+  # * <tt>create_table(name, options)</tt> Creates a table called +name+ and 
  92
+  #   makes the table object available to a block that can then add columns to it,
  93
+  #   following the same format as add_column. See example above. The options hash 
  94
+  #   is for fragments like "DEFAULT CHARSET=UTF-8" that are appended to the create 
  95
+  #   table definition.
84 96
   # * <tt>drop_table(name)</tt>: Drops the table called +name+.
85  
-  # * <tt>rename_table(old_name, new_name)</tt>: Renames the table called +old_name+ to +new_name+.
86  
-  # * <tt>add_column(table_name, column_name, type, options)</tt>: Adds a new column to the table called +table_name+
  97
+  # * <tt>rename_table(old_name, new_name)</tt>: Renames the table called +old_name+ 
  98
+  #   to +new_name+.
  99
+  # * <tt>add_column(table_name, column_name, type, options)</tt>: Adds a new column 
  100
+  #   to the table called +table_name+
87 101
   #   named +column_name+ specified to be one of the following types:
88  
-  #   <tt>:string</tt>, <tt>:text</tt>, <tt>:integer</tt>, <tt>:float</tt>, <tt>:decimal</tt>, <tt>:datetime</tt>, <tt>:timestamp</tt>, <tt>:time</tt>,
89  
-  #   <tt>:date</tt>, <tt>:binary</tt>, <tt>:boolean</tt>. A default value can be specified by passing an
90  
-  #   +options+ hash like <tt>{ :default => 11 }</tt>. Other options include <tt>:limit</tt> and <tt>:null</tt> (e.g. <tt>{ :limit => 50, :null => false }</tt>)
91  
-  #   -- see ActiveRecord::ConnectionAdapters::TableDefinition#column for details.
92  
-  # * <tt>rename_column(table_name, column_name, new_column_name)</tt>: Renames a column but keeps the type and content.
93  
-  # * <tt>change_column(table_name, column_name, type, options)</tt>:  Changes the column to a different type using the same
94  
-  #   parameters as add_column.
95  
-  # * <tt>remove_column(table_name, column_name)</tt>: Removes the column named +column_name+ from the table called +table_name+.
96  
-  # * <tt>add_index(table_name, column_names, options)</tt>: Adds a new index with the name of the column. Other options include
97  
-  #   <tt>:name</tt> and <tt>:unique</tt> (e.g. <tt>{ :name => "users_name_index", :unique => true }</tt>).
98  
-  # * <tt>remove_index(table_name, index_name)</tt>: Removes the index specified by +index_name+.
  102
+  #   <tt>:string</tt>, <tt>:text</tt>, <tt>:integer</tt>, <tt>:float</tt>, 
  103
+  #   <tt>:decimal</tt>, <tt>:datetime</tt>, <tt>:timestamp</tt>, <tt>:time</tt>,
  104
+  #   <tt>:date</tt>, <tt>:binary</tt>, <tt>:boolean</tt>. A default value can be
  105
+  #   specified by passing an +options+ hash like <tt>{ :default => 11 }</tt>. 
  106
+  #   Other options include <tt>:limit</tt> and <tt>:null</tt> (e.g. 
  107
+  #   <tt>{ :limit => 50, :null => false }</tt>) -- see 
  108
+  #   ActiveRecord::ConnectionAdapters::TableDefinition#column for details.
  109
+  # * <tt>rename_column(table_name, column_name, new_column_name)</tt>: Renames
  110
+  #   a column but keeps the type and content.
  111
+  # * <tt>change_column(table_name, column_name, type, options)</tt>:  Changes 
  112
+  #   the column to a different type using the same parameters as add_column.
  113
+  # * <tt>remove_column(table_name, column_name)</tt>: Removes the column named 
  114
+  #   +column_name+ from the table called +table_name+.
  115
+  # * <tt>add_index(table_name, column_names, options)</tt>: Adds a new index 
  116
+  #   with the name of the column. Other options include
  117
+  #   <tt>:name</tt> and <tt>:unique</tt> (e.g. 
  118
+  #   <tt>{ :name => "users_name_index", :unique => true }</tt>).
  119
+  # * <tt>remove_index(table_name, index_name)</tt>: Removes the index specified 
  120
+  #   by +index_name+.
99 121
   #
100 122
   # == Irreversible transformations
101 123
   #
102  
-  # Some transformations are destructive in a manner that cannot be reversed. Migrations of that kind should raise
103  
-  # an <tt>ActiveRecord::IrreversibleMigration</tt> exception in their +down+ method.
  124
+  # Some transformations are destructive in a manner that cannot be reversed. 
  125
+  # Migrations of that kind should raise an <tt>ActiveRecord::IrreversibleMigration</tt> 
  126
+  # exception in their +down+ method.
104 127
   #
105 128
   # == Running migrations from within Rails
106 129
   #
@@ -110,13 +133,15 @@ def initialize(name)
110 133
   #   rails generate migration MyNewMigration
111 134
   #
112 135
   # where MyNewMigration is the name of your migration. The generator will
113  
-  # create an empty migration file <tt>timestamp_my_new_migration.rb</tt> in the <tt>db/migrate/</tt>
114  
-  # directory where <tt>timestamp</tt> is the UTC formatted date and time that the migration was generated.
  136
+  # create an empty migration file <tt>timestamp_my_new_migration.rb</tt> 
  137
+  # in the <tt>db/migrate/</tt> directory where <tt>timestamp</tt> is the 
  138
+  # UTC formatted date and time that the migration was generated.
115 139
   #
116 140
   # You may then edit the <tt>self.up</tt> and <tt>self.down</tt> methods of
117 141
   # MyNewMigration.
118 142
   #
119 143
   # There is a special syntactic shortcut to generate migrations that add fields to a table.
  144
+  #
120 145
   #   rails generate migration add_fieldname_to_tablename fieldname:string
121 146
   #
122 147
   # This will generate the file <tt>timestamp_add_fieldname_to_tablename</tt>, which will look like this:
@@ -191,9 +216,10 @@ def initialize(name)
191 216
   #
192 217
   # == Using a model after changing its table
193 218
   #
194  
-  # Sometimes you'll want to add a column in a migration and populate it immediately after. In that case, you'll need
195  
-  # to make a call to Base#reset_column_information in order to ensure that the model has the latest column data from
196  
-  # after the new column was added. Example:
  219
+  # Sometimes you'll want to add a column in a migration and populate it 
  220
+  # immediately after. In that case, you'll need to make a call to 
  221
+  # <tt>Base#reset_column_information</tt> in order to ensure that the model has the 
  222
+  # latest column data from after the new column was added. Example:
197 223
   #
198 224
   #   class AddPeopleSalary < ActiveRecord::Migration
199 225
   #     def self.up

0 notes on commit c869154

Please sign in to comment.
Something went wrong with that request. Please try again.