Skip to content

Commit

Permalink
Use a real migration version number in docs
Browse files Browse the repository at this point in the history
Even though this means more things to change when we bump after a
release, it's more important that our examples are directly copyable.
  • Loading branch information
matthewd committed Dec 15, 2015
1 parent 6d2469d commit 97c7716
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion activerecord/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ This would also define the following accessors: <tt>Product#name</tt> and

* Database agnostic schema management with Migrations.

class AddSystemSettings < ActiveRecord::Migration[0.0]
class AddSystemSettings < ActiveRecord::Migration[5.0]
def up
create_table :system_settings do |t|
t.string :name
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ def belongs_to(name, scope = nil, options = {})
# The join table should not have a primary key or a model associated with it. You must manually generate the
# join table with a migration such as this:
#
# class CreateDevelopersProjectsJoinTable < ActiveRecord::Migration[0.0]
# class CreateDevelopersProjectsJoinTable < ActiveRecord::Migration[5.0]
# def change
# create_join_table :developers, :projects
# end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def #{column_type}(*args, **options)
# Inside migration files, the +t+ object in {create_table}[rdoc-ref:SchemaStatements#create_table]
# is actually of this type:
#
# class SomeMigration < ActiveRecord::Migration[0.0]
# class SomeMigration < ActiveRecord::Migration[5.0]
# def up
# create_table :foo do |t|
# puts t.class # => "ActiveRecord::ConnectionAdapters::TableDefinition"
Expand Down
30 changes: 15 additions & 15 deletions activerecord/lib/active_record/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(message = nil)
# For example the following migration is not reversible.
# Rolling back this migration will raise an ActiveRecord::IrreversibleMigration error.
#
# class IrreversibleMigrationExample < ActiveRecord::Migration[0.0]
# class IrreversibleMigrationExample < ActiveRecord::Migration[5.0]
# def change
# create_table :distributors do |t|
# t.string :zipcode
Expand All @@ -31,7 +31,7 @@ def initialize(message = nil)
#
# 1. Define <tt>#up</tt> and <tt>#down</tt> methods instead of <tt>#change</tt>:
#
# class ReversibleMigrationExample < ActiveRecord::Migration[0.0]
# class ReversibleMigrationExample < ActiveRecord::Migration[5.0]
# def up
# create_table :distributors do |t|
# t.string :zipcode
Expand All @@ -56,7 +56,7 @@ def initialize(message = nil)
#
# 2. Use the #reversible method in <tt>#change</tt> method:
#
# class ReversibleMigrationExample < ActiveRecord::Migration[0.0]
# class ReversibleMigrationExample < ActiveRecord::Migration[5.0]
# def change
# create_table :distributors do |t|
# t.string :zipcode
Expand Down Expand Up @@ -155,7 +155,7 @@ def initialize(message = DEFAULT_MESSAGE)
#
# Example of a simple migration:
#
# class AddSsl < ActiveRecord::Migration[0.0]
# class AddSsl < ActiveRecord::Migration[5.0]
# def up
# add_column :accounts, :ssl_enabled, :boolean, default: true
# end
Expand All @@ -175,7 +175,7 @@ def initialize(message = DEFAULT_MESSAGE)
#
# Example of a more complex migration that also needs to initialize data:
#
# class AddSystemSettings < ActiveRecord::Migration[0.0]
# class AddSystemSettings < ActiveRecord::Migration[5.0]
# def up
# create_table :system_settings do |t|
# t.string :name
Expand Down Expand Up @@ -301,7 +301,7 @@ def initialize(message = DEFAULT_MESSAGE)
# rails generate migration add_fieldname_to_tablename fieldname:string
#
# This will generate the file <tt>timestamp_add_fieldname_to_tablename.rb</tt>, which will look like this:
# class AddFieldnameToTablename < ActiveRecord::Migration[0.0]
# class AddFieldnameToTablename < ActiveRecord::Migration[5.0]
# def change
# add_column :tablenames, :fieldname, :string
# end
Expand Down Expand Up @@ -332,7 +332,7 @@ def initialize(message = DEFAULT_MESSAGE)
#
# Not all migrations change the schema. Some just fix the data:
#
# class RemoveEmptyTags < ActiveRecord::Migration[0.0]
# class RemoveEmptyTags < ActiveRecord::Migration[5.0]
# def up
# Tag.all.each { |tag| tag.destroy if tag.pages.empty? }
# end
Expand All @@ -345,7 +345,7 @@ def initialize(message = DEFAULT_MESSAGE)
#
# Others remove columns when they migrate up instead of down:
#
# class RemoveUnnecessaryItemAttributes < ActiveRecord::Migration[0.0]
# class RemoveUnnecessaryItemAttributes < ActiveRecord::Migration[5.0]
# def up
# remove_column :items, :incomplete_items_count
# remove_column :items, :completed_items_count
Expand All @@ -359,7 +359,7 @@ def initialize(message = DEFAULT_MESSAGE)
#
# And sometimes you need to do something in SQL not abstracted directly by migrations:
#
# class MakeJoinUnique < ActiveRecord::Migration[0.0]
# class MakeJoinUnique < ActiveRecord::Migration[5.0]
# def up
# execute "ALTER TABLE `pages_linked_pages` ADD UNIQUE `page_id_linked_page_id` (`page_id`,`linked_page_id`)"
# end
Expand All @@ -376,7 +376,7 @@ def initialize(message = DEFAULT_MESSAGE)
# <tt>Base#reset_column_information</tt> in order to ensure that the model has the
# latest column data from after the new column was added. Example:
#
# class AddPeopleSalary < ActiveRecord::Migration[0.0]
# class AddPeopleSalary < ActiveRecord::Migration[5.0]
# def up
# add_column :people, :salary, :integer
# Person.reset_column_information
Expand Down Expand Up @@ -434,7 +434,7 @@ def initialize(message = DEFAULT_MESSAGE)
# To define a reversible migration, define the +change+ method in your
# migration like this:
#
# class TenderloveMigration < ActiveRecord::Migration[0.0]
# class TenderloveMigration < ActiveRecord::Migration[5.0]
# def change
# create_table(:horses) do |t|
# t.column :content, :text
Expand Down Expand Up @@ -464,7 +464,7 @@ def initialize(message = DEFAULT_MESSAGE)
# can't execute inside a transaction though, and for these situations
# you can turn the automatic transactions off.
#
# class ChangeEnum < ActiveRecord::Migration[0.0]
# class ChangeEnum < ActiveRecord::Migration[5.0]
# disable_ddl_transaction!
#
# def up
Expand Down Expand Up @@ -605,7 +605,7 @@ def initialize(name = self.class.name, version = nil)
# and create the table 'apples' on the way up, and the reverse
# on the way down.
#
# class FixTLMigration < ActiveRecord::Migration[0.0]
# class FixTLMigration < ActiveRecord::Migration[5.0]
# def change
# revert do
# create_table(:horses) do |t|
Expand All @@ -624,7 +624,7 @@ def initialize(name = self.class.name, version = nil)
#
# require_relative '20121212123456_tenderlove_migration'
#
# class FixupTLMigration < ActiveRecord::Migration[0.0]
# class FixupTLMigration < ActiveRecord::Migration[5.0]
# def change
# revert TenderloveMigration
#
Expand Down Expand Up @@ -677,7 +677,7 @@ def down
# when the three columns 'first_name', 'last_name' and 'full_name' exist,
# even when migrating down:
#
# class SplitNameMigration < ActiveRecord::Migration[0.0]
# class SplitNameMigration < ActiveRecord::Migration[5.0]
# def change
# add_column :users, :first_name, :string
# add_column :users, :last_name, :string
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/model_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def content_columns
# when just after creating a table you want to populate it with some default
# values, eg:
#
# class CreateJobLevels < ActiveRecord::Migration[0.0]
# class CreateJobLevels < ActiveRecord::Migration[5.0]
# def up
# create_table :job_levels do |t|
# t.integer :id
Expand Down
2 changes: 1 addition & 1 deletion guides/source/active_record_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ database that Active Record supports using `rake`. Here's a migration that
creates a table:

```ruby
class CreatePublications < ActiveRecord::Migration[0.0]
class CreatePublications < ActiveRecord::Migration[5.0]
def change
create_table :publications do |t|
t.string :title
Expand Down
38 changes: 19 additions & 19 deletions guides/source/active_record_migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ history to the latest version. Active Record will also update your
Here's an example of a migration:

```ruby
class CreateProducts < ActiveRecord::Migration[0.0]
class CreateProducts < ActiveRecord::Migration[5.0]
def change
create_table :products do |t|
t.string :name
Expand Down Expand Up @@ -72,7 +72,7 @@ If you wish for a migration to do something that Active Record doesn't know how
to reverse, you can use `reversible`:

```ruby
class ChangeProductsPrice < ActiveRecord::Migration[0.0]
class ChangeProductsPrice < ActiveRecord::Migration[5.0]
def change
reversible do |dir|
change_table :products do |t|
Expand All @@ -87,7 +87,7 @@ end
Alternatively, you can use `up` and `down` instead of `change`:

```ruby
class ChangeProductsPrice < ActiveRecord::Migration[0.0]
class ChangeProductsPrice < ActiveRecord::Migration[5.0]
def up
change_table :products do |t|
t.change :price, :string
Expand Down Expand Up @@ -129,7 +129,7 @@ $ bin/rails generate migration AddPartNumberToProducts
This will create an empty but appropriately named migration:

```ruby
class AddPartNumberToProducts < ActiveRecord::Migration[0.0]
class AddPartNumberToProducts < ActiveRecord::Migration[5.0]
def change
end
end
Expand All @@ -146,7 +146,7 @@ $ bin/rails generate migration AddPartNumberToProducts part_number:string
will generate

```ruby
class AddPartNumberToProducts < ActiveRecord::Migration[0.0]
class AddPartNumberToProducts < ActiveRecord::Migration[5.0]
def change
add_column :products, :part_number, :string
end
Expand All @@ -162,7 +162,7 @@ $ bin/rails generate migration AddPartNumberToProducts part_number:string:index
will generate

```ruby
class AddPartNumberToProducts < ActiveRecord::Migration[0.0]
class AddPartNumberToProducts < ActiveRecord::Migration[5.0]
def change
add_column :products, :part_number, :string
add_index :products, :part_number
Expand All @@ -180,7 +180,7 @@ $ bin/rails generate migration RemovePartNumberFromProducts part_number:string
generates

```ruby
class RemovePartNumberFromProducts < ActiveRecord::Migration[0.0]
class RemovePartNumberFromProducts < ActiveRecord::Migration[5.0]
def change
remove_column :products, :part_number, :string
end
Expand All @@ -196,7 +196,7 @@ $ bin/rails generate migration AddDetailsToProducts part_number:string price:dec
generates

```ruby
class AddDetailsToProducts < ActiveRecord::Migration[0.0]
class AddDetailsToProducts < ActiveRecord::Migration[5.0]
def change
add_column :products, :part_number, :string
add_column :products, :price, :decimal
Expand All @@ -215,7 +215,7 @@ $ bin/rails generate migration CreateProducts name:string part_number:string
generates

```ruby
class CreateProducts < ActiveRecord::Migration[0.0]
class CreateProducts < ActiveRecord::Migration[5.0]
def change
create_table :products do |t|
t.string :name
Expand All @@ -239,7 +239,7 @@ $ bin/rails generate migration AddUserRefToProducts user:references
generates

```ruby
class AddUserRefToProducts < ActiveRecord::Migration[0.0]
class AddUserRefToProducts < ActiveRecord::Migration[5.0]
def change
add_reference :products, :user, index: true, foreign_key: true
end
Expand All @@ -257,7 +257,7 @@ $ bin/rails g migration CreateJoinTableCustomerProduct customer product
will produce the following migration:

```ruby
class CreateJoinTableCustomerProduct < ActiveRecord::Migration[0.0]
class CreateJoinTableCustomerProduct < ActiveRecord::Migration[5.0]
def change
create_join_table :customers, :products do |t|
# t.index [:customer_id, :product_id]
Expand All @@ -281,7 +281,7 @@ $ bin/rails generate model Product name:string description:text
will create a migration that looks like this

```ruby
class CreateProducts < ActiveRecord::Migration[0.0]
class CreateProducts < ActiveRecord::Migration[5.0]
def change
create_table :products do |t|
t.string :name
Expand Down Expand Up @@ -309,7 +309,7 @@ $ bin/rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplie
will produce a migration that looks like this

```ruby
class AddDetailsToProducts < ActiveRecord::Migration[0.0]
class AddDetailsToProducts < ActiveRecord::Migration[5.0]
def change
add_column :products, :price, :decimal, precision: 5, scale: 2
add_reference :products, :supplier, polymorphic: true, index: true
Expand Down Expand Up @@ -563,7 +563,7 @@ to reverse. You can use `reversible` to specify what to do when running a
migration and what else to do when reverting it. For example:

```ruby
class ExampleMigration < ActiveRecord::Migration[0.0]
class ExampleMigration < ActiveRecord::Migration[5.0]
def change
create_table :distributors do |t|
t.string :zipcode
Expand Down Expand Up @@ -616,7 +616,7 @@ is wise to perform the transformations in precisely the reverse order they were
made in the `up` method. The example in the `reversible` section is equivalent to:

```ruby
class ExampleMigration < ActiveRecord::Migration[0.0]
class ExampleMigration < ActiveRecord::Migration[5.0]
def up
create_table :distributors do |t|
t.string :zipcode
Expand Down Expand Up @@ -659,7 +659,7 @@ You can use Active Record's ability to rollback migrations using the `revert` me
```ruby
require_relative '20121212123456_example_migration'

class FixupExampleMigration < ActiveRecord::Migration[0.0]
class FixupExampleMigration < ActiveRecord::Migration[5.0]
def change
revert ExampleMigration

Expand All @@ -677,7 +677,7 @@ is later decided it would be best to use Active Record validations,
in place of the `CHECK` constraint, to verify the zipcode.

```ruby
class DontUseConstraintForZipcodeValidationMigration < ActiveRecord::Migration[0.0]
class DontUseConstraintForZipcodeValidationMigration < ActiveRecord::Migration[5.0]
def change
revert do
# copy-pasted code from ExampleMigration
Expand Down Expand Up @@ -841,7 +841,7 @@ Several methods are provided in migrations that allow you to control all this:
For example, this migration:

```ruby
class CreateProducts < ActiveRecord::Migration[0.0]
class CreateProducts < ActiveRecord::Migration[5.0]
def change
suppress_messages do
create_table :products do |t|
Expand Down Expand Up @@ -1015,7 +1015,7 @@ to add or modify data. This is useful in an existing database that can't be dest
and recreated, such as a production database.
```ruby
class AddInitialProducts < ActiveRecord::Migration[0.0]
class AddInitialProducts < ActiveRecord::Migration[5.0]
def up
5.times do |i|
Product.create(name: "Product ##{i}", description: "A product.")
Expand Down
Loading

0 comments on commit 97c7716

Please sign in to comment.