Update Migration number from 5.0 to current 6.0 [ci skip]
This commit is contained in:
parent
2d7ff70b3f
commit
ca60488ef9
|
@ -34,7 +34,7 @@ history to the latest version. Active Record will also update your
|
|||
Here's an example of a migration:
|
||||
|
||||
```ruby
|
||||
class CreateProducts < ActiveRecord::Migration[5.0]
|
||||
class CreateProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :products do |t|
|
||||
t.string :name
|
||||
|
@ -71,7 +71,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[5.0]
|
||||
class ChangeProductsPrice < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
reversible do |dir|
|
||||
change_table :products do |t|
|
||||
|
@ -86,7 +86,7 @@ end
|
|||
Alternatively, you can use `up` and `down` instead of `change`:
|
||||
|
||||
```ruby
|
||||
class ChangeProductsPrice < ActiveRecord::Migration[5.0]
|
||||
class ChangeProductsPrice < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
change_table :products do |t|
|
||||
t.change :price, :string
|
||||
|
@ -128,7 +128,7 @@ $ bin/rails generate migration AddPartNumberToProducts
|
|||
This will create an appropriately named empty migration:
|
||||
|
||||
```ruby
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration[5.0]
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
end
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ $ bin/rails generate migration AddPartNumberToProducts part_number:string
|
|||
will generate
|
||||
|
||||
```ruby
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration[5.0]
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :products, :part_number, :string
|
||||
end
|
||||
|
@ -166,7 +166,7 @@ $ bin/rails generate migration AddPartNumberToProducts part_number:string:index
|
|||
will generate
|
||||
|
||||
```ruby
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration[5.0]
|
||||
class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :products, :part_number, :string
|
||||
add_index :products, :part_number
|
||||
|
@ -184,7 +184,7 @@ $ bin/rails generate migration RemovePartNumberFromProducts part_number:string
|
|||
generates
|
||||
|
||||
```ruby
|
||||
class RemovePartNumberFromProducts < ActiveRecord::Migration[5.0]
|
||||
class RemovePartNumberFromProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
remove_column :products, :part_number, :string
|
||||
end
|
||||
|
@ -200,7 +200,7 @@ $ bin/rails generate migration AddDetailsToProducts part_number:string price:dec
|
|||
generates
|
||||
|
||||
```ruby
|
||||
class AddDetailsToProducts < ActiveRecord::Migration[5.0]
|
||||
class AddDetailsToProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :products, :part_number, :string
|
||||
add_column :products, :price, :decimal
|
||||
|
@ -219,7 +219,7 @@ $ bin/rails generate migration CreateProducts name:string part_number:string
|
|||
generates
|
||||
|
||||
```ruby
|
||||
class CreateProducts < ActiveRecord::Migration[5.0]
|
||||
class CreateProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :products do |t|
|
||||
t.string :name
|
||||
|
@ -245,7 +245,7 @@ $ bin/rails generate migration AddUserRefToProducts user:references
|
|||
generates
|
||||
|
||||
```ruby
|
||||
class AddUserRefToProducts < ActiveRecord::Migration[5.0]
|
||||
class AddUserRefToProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_reference :products, :user, foreign_key: true
|
||||
end
|
||||
|
@ -264,7 +264,7 @@ $ bin/rails generate migration CreateJoinTableCustomerProduct customer product
|
|||
will produce the following migration:
|
||||
|
||||
```ruby
|
||||
class CreateJoinTableCustomerProduct < ActiveRecord::Migration[5.0]
|
||||
class CreateJoinTableCustomerProduct < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_join_table :customers, :products do |t|
|
||||
# t.index [:customer_id, :product_id]
|
||||
|
@ -288,7 +288,7 @@ $ bin/rails generate model Product name:string description:text
|
|||
will create a migration that looks like this
|
||||
|
||||
```ruby
|
||||
class CreateProducts < ActiveRecord::Migration[5.0]
|
||||
class CreateProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :products do |t|
|
||||
t.string :name
|
||||
|
@ -316,7 +316,7 @@ $ bin/rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplie
|
|||
will produce a migration that looks like this
|
||||
|
||||
```ruby
|
||||
class AddDetailsToProducts < ActiveRecord::Migration[5.0]
|
||||
class AddDetailsToProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :products, :price, :decimal, precision: 5, scale: 2
|
||||
add_reference :products, :supplier, polymorphic: true
|
||||
|
@ -578,7 +578,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[5.0]
|
||||
class ExampleMigration < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :distributors do |t|
|
||||
t.string :zipcode
|
||||
|
@ -631,7 +631,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[5.0]
|
||||
class ExampleMigration < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
create_table :distributors do |t|
|
||||
t.string :zipcode
|
||||
|
@ -674,7 +674,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[5.0]
|
||||
class FixupExampleMigration < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
revert ExampleMigration
|
||||
|
||||
|
@ -692,7 +692,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[5.0]
|
||||
class DontUseConstraintForZipcodeValidationMigration < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
revert do
|
||||
# copy-pasted code from ExampleMigration
|
||||
|
@ -856,7 +856,7 @@ Several methods are provided in migrations that allow you to control all this:
|
|||
For example, this migration:
|
||||
|
||||
```ruby
|
||||
class CreateProducts < ActiveRecord::Migration[5.0]
|
||||
class CreateProducts < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
suppress_messages do
|
||||
create_table :products do |t|
|
||||
|
@ -1021,7 +1021,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[5.0]
|
||||
class AddInitialProducts < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
5.times do |i|
|
||||
Product.create(name: "Product ##{i}", description: "A product.")
|
||||
|
|
Loading…
Reference in New Issue