diff options
author | Xavier Noria <fxn@hashref.com> | 2011-07-23 12:15:41 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-07-23 12:15:41 +0200 |
commit | ace3723d2fcb1a96d51c2c82050594129328d7c0 (patch) | |
tree | d95d16b7dfee13037987913ed71d1708b5484f15 /railties/guides/source/migrations.textile | |
parent | 94978b9a46173b875bcb0d5cb724e5119e4aa8f4 (diff) | |
parent | 38310ab1a6f559860e25b0e28bef9560bb452ae6 (diff) | |
download | rails-ace3723d2fcb1a96d51c2c82050594129328d7c0.tar.gz rails-ace3723d2fcb1a96d51c2c82050594129328d7c0.tar.bz2 rails-ace3723d2fcb1a96d51c2c82050594129328d7c0.zip |
Merge branch 'master' of git://github.com/lifo/docrails
Diffstat (limited to 'railties/guides/source/migrations.textile')
-rw-r--r-- | railties/guides/source/migrations.textile | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index dbbf8f3b51..c88e3cc338 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -17,7 +17,7 @@ endprologue. h3. Anatomy of a Migration -Before I dive into the details of a migration, here are a few examples of the sorts of things you can do: +Before we dive into the details of a migration, here are a few examples of the sorts of things you can do: <ruby> class CreateProducts < ActiveRecord::Migration @@ -117,6 +117,33 @@ Occasionally you will make a mistake when writing a migration. If you have alrea In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. +h4. Supported Types + +Active Record supports the following types: + +* +:primary_key+ +* +:string+ +* +:text+ +* +:integer+ +* +:float+ +* +:decimal+ +* +:datetime+ +* +:timestamp+ +* +:time+ +* +:date+ +* +:binary+ +* +:boolean+ + +These will be mapped onto an appropriate underlying database type, for example with MySQL +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example + +<ruby> +create_table :products do |t| + t.column :name, 'polygon', :null => false +end +</ruby> + +This may however hinder portability to other databases. + h3. Creating a Migration h4. Creating a Model @@ -261,18 +288,6 @@ end will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table (when using MySQL the default is +ENGINE=InnoDB+). -The types supported by Active Record are +:primary_key+, +:string+, +:text+, +:integer+, +:float+, +:decimal+, +:datetime+, +:timestamp+, +:time+, +:date+, +:binary+, +:boolean+. - -These will be mapped onto an appropriate underlying database type, for example with MySQL +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example - -<ruby> -create_table :products do |t| - t.column :name, 'polygon', :null => false -end -</ruby> - -This may however hinder portability to other databases. - h4. Changing Tables A close cousin of +create_table+ is +change_table+, used for changing existing tables. It is used in a similar fashion to +create_table+ but the object yielded to the block knows more tricks. For example |