1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Update all Migration version references

Migration version references has been updated 2 times in less than 3
weeks (#41894, #42113).

I'd not want to receive the same tweaks in the near future.
This commit is contained in:
Ryuta Kamizono 2021-05-02 21:17:04 +09:00
parent 2c8821abfd
commit 35bf079aed
10 changed files with 56 additions and 56 deletions

View file

@ -140,7 +140,7 @@ This would also define the following accessors: <tt>Product#name</tt> and
* Database agnostic schema management with Migrations.
class AddSystemSettings < ActiveRecord::Migration[6.0]
class AddSystemSettings < ActiveRecord::Migration[7.0]
def up
create_table :system_settings do |t|
t.string :name

View file

@ -1780,7 +1780,7 @@ module ActiveRecord
# 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[6.0]
# class CreateDevelopersProjectsJoinTable < ActiveRecord::Migration[7.0]
# def change
# create_join_table :developers, :projects
# end

View file

@ -278,7 +278,7 @@ module ActiveRecord
# Inside migration files, the +t+ object in {create_table}[rdoc-ref:SchemaStatements#create_table]
# is actually of this type:
#
# class SomeMigration < ActiveRecord::Migration[6.0]
# class SomeMigration < ActiveRecord::Migration[7.0]
# def up
# create_table :foo do |t|
# puts t.class # => "ActiveRecord::ConnectionAdapters::TableDefinition"

View file

@ -20,7 +20,7 @@ module ActiveRecord
# For example the following migration is not reversible.
# Rolling back this migration will raise an ActiveRecord::IrreversibleMigration error.
#
# class IrreversibleMigrationExample < ActiveRecord::Migration[6.0]
# class IrreversibleMigrationExample < ActiveRecord::Migration[7.0]
# def change
# create_table :distributors do |t|
# t.string :zipcode
@ -38,7 +38,7 @@ module ActiveRecord
#
# 1. Define <tt>#up</tt> and <tt>#down</tt> methods instead of <tt>#change</tt>:
#
# class ReversibleMigrationExample < ActiveRecord::Migration[6.0]
# class ReversibleMigrationExample < ActiveRecord::Migration[7.0]
# def up
# create_table :distributors do |t|
# t.string :zipcode
@ -63,7 +63,7 @@ module ActiveRecord
#
# 2. Use the #reversible method in <tt>#change</tt> method:
#
# class ReversibleMigrationExample < ActiveRecord::Migration[6.0]
# class ReversibleMigrationExample < ActiveRecord::Migration[7.0]
# def change
# create_table :distributors do |t|
# t.string :zipcode
@ -228,7 +228,7 @@ module ActiveRecord
#
# Example of a simple migration:
#
# class AddSsl < ActiveRecord::Migration[6.0]
# class AddSsl < ActiveRecord::Migration[7.0]
# def up
# add_column :accounts, :ssl_enabled, :boolean, default: true
# end
@ -248,7 +248,7 @@ module ActiveRecord
#
# Example of a more complex migration that also needs to initialize data:
#
# class AddSystemSettings < ActiveRecord::Migration[6.0]
# class AddSystemSettings < ActiveRecord::Migration[7.0]
# def up
# create_table :system_settings do |t|
# t.string :name
@ -376,7 +376,7 @@ module ActiveRecord
# bin/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[6.0]
# class AddFieldnameToTablename < ActiveRecord::Migration[7.0]
# def change
# add_column :tablenames, :fieldname, :string
# end
@ -402,7 +402,7 @@ module ActiveRecord
#
# Not all migrations change the schema. Some just fix the data:
#
# class RemoveEmptyTags < ActiveRecord::Migration[6.0]
# class RemoveEmptyTags < ActiveRecord::Migration[7.0]
# def up
# Tag.all.each { |tag| tag.destroy if tag.pages.empty? }
# end
@ -415,7 +415,7 @@ module ActiveRecord
#
# Others remove columns when they migrate up instead of down:
#
# class RemoveUnnecessaryItemAttributes < ActiveRecord::Migration[6.0]
# class RemoveUnnecessaryItemAttributes < ActiveRecord::Migration[7.0]
# def up
# remove_column :items, :incomplete_items_count
# remove_column :items, :completed_items_count
@ -429,7 +429,7 @@ module ActiveRecord
#
# And sometimes you need to do something in SQL not abstracted directly by migrations:
#
# class MakeJoinUnique < ActiveRecord::Migration[6.0]
# class MakeJoinUnique < ActiveRecord::Migration[7.0]
# def up
# execute "ALTER TABLE `pages_linked_pages` ADD UNIQUE `page_id_linked_page_id` (`page_id`,`linked_page_id`)"
# end
@ -446,7 +446,7 @@ module ActiveRecord
# <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[6.0]
# class AddPeopleSalary < ActiveRecord::Migration[7.0]
# def up
# add_column :people, :salary, :integer
# Person.reset_column_information
@ -504,7 +504,7 @@ module ActiveRecord
# To define a reversible migration, define the +change+ method in your
# migration like this:
#
# class TenderloveMigration < ActiveRecord::Migration[6.0]
# class TenderloveMigration < ActiveRecord::Migration[7.0]
# def change
# create_table(:horses) do |t|
# t.column :content, :text
@ -534,7 +534,7 @@ module ActiveRecord
# can't execute inside a transaction though, and for these situations
# you can turn the automatic transactions off.
#
# class ChangeEnum < ActiveRecord::Migration[6.0]
# class ChangeEnum < ActiveRecord::Migration[7.0]
# disable_ddl_transaction!
#
# def up
@ -698,7 +698,7 @@ module ActiveRecord
# and create the table 'apples' on the way up, and the reverse
# on the way down.
#
# class FixTLMigration < ActiveRecord::Migration[6.0]
# class FixTLMigration < ActiveRecord::Migration[7.0]
# def change
# revert do
# create_table(:horses) do |t|
@ -717,7 +717,7 @@ module ActiveRecord
#
# require_relative "20121212123456_tenderlove_migration"
#
# class FixupTLMigration < ActiveRecord::Migration[6.0]
# class FixupTLMigration < ActiveRecord::Migration[7.0]
# def change
# revert TenderloveMigration
#
@ -768,7 +768,7 @@ module ActiveRecord
# when the three columns 'first_name', 'last_name' and 'full_name' exist,
# even when migrating down:
#
# class SplitNameMigration < ActiveRecord::Migration[6.0]
# class SplitNameMigration < ActiveRecord::Migration[7.0]
# def change
# add_column :users, :first_name, :string
# add_column :users, :last_name, :string
@ -796,7 +796,7 @@ module ActiveRecord
# In the following example, the new column +published+ will be given
# the value +true+ for all existing records.
#
# class AddPublishedToPosts < ActiveRecord::Migration[6.0]
# class AddPublishedToPosts < ActiveRecord::Migration[7.0]
# def change
# add_column :posts, :published, :boolean, default: false
# up_only do

View file

@ -489,7 +489,7 @@ module ActiveRecord
# when just after creating a table you want to populate it with some default
# values, eg:
#
# class CreateJobLevels < ActiveRecord::Migration[6.0]
# class CreateJobLevels < ActiveRecord::Migration[7.0]
# def up
# create_table :job_levels do |t|
# t.integer :id

View file

@ -29,7 +29,7 @@ end
class Payment < ActiveRecord::Base
end
class ChangeAmountToAddScale < ActiveRecord::Migration[6.0]
class ChangeAmountToAddScale < ActiveRecord::Migration[6.1]
def change
reversible do |dir|
dir.up do

View file

@ -28,7 +28,7 @@ end
class Payment < ActiveRecord::Base
end
class ChangeAmountToAddScale < ActiveRecord::Migration[6.0]
class ChangeAmountToAddScale < ActiveRecord::Migration[7.0]
def change
reversible do |dir|
dir.up do

View file

@ -368,7 +368,7 @@ database that Active Record supports using `rake`. Here's a migration that
creates a table:
```ruby
class CreatePublications < ActiveRecord::Migration[6.0]
class CreatePublications < ActiveRecord::Migration[7.0]
def change
create_table :publications do |t|
t.string :title

View file

@ -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[6.0]
class CreateProducts < ActiveRecord::Migration[7.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[6.0]
class ChangeProductsPrice < ActiveRecord::Migration[7.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[6.0]
class ChangeProductsPrice < ActiveRecord::Migration[7.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[6.0]
class AddPartNumberToProducts < ActiveRecord::Migration[7.0]
def change
end
end
@ -150,7 +150,7 @@ $ bin/rails generate migration AddPartNumberToProducts part_number:string
will generate
```ruby
class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
class AddPartNumberToProducts < ActiveRecord::Migration[7.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 the appropriate `add_column` and [`add_index`][] statements:
```ruby
class AddPartNumberToProducts < ActiveRecord::Migration[6.0]
class AddPartNumberToProducts < ActiveRecord::Migration[7.0]
def change
add_column :products, :part_number, :string
add_index :products, :part_number
@ -183,7 +183,7 @@ $ bin/rails generate migration RemovePartNumberFromProducts part_number:string
generates
```ruby
class RemovePartNumberFromProducts < ActiveRecord::Migration[6.0]
class RemovePartNumberFromProducts < ActiveRecord::Migration[7.0]
def change
remove_column :products, :part_number, :string
end
@ -199,7 +199,7 @@ $ bin/rails generate migration AddDetailsToProducts part_number:string price:dec
generates
```ruby
class AddDetailsToProducts < ActiveRecord::Migration[6.0]
class AddDetailsToProducts < ActiveRecord::Migration[7.0]
def change
add_column :products, :part_number, :string
add_column :products, :price, :decimal
@ -218,7 +218,7 @@ $ bin/rails generate migration CreateProducts name:string part_number:string
generates
```ruby
class CreateProducts < ActiveRecord::Migration[6.0]
class CreateProducts < ActiveRecord::Migration[7.0]
def change
create_table :products do |t|
t.string :name
@ -244,7 +244,7 @@ $ bin/rails generate migration AddUserRefToProducts user:references
generates the following [`add_reference`][] call:
```ruby
class AddUserRefToProducts < ActiveRecord::Migration[6.0]
class AddUserRefToProducts < ActiveRecord::Migration[7.0]
def change
add_reference :products, :user, foreign_key: true
end
@ -262,7 +262,7 @@ $ bin/rails generate migration CreateJoinTableCustomerProduct customer product
will produce the following migration:
```ruby
class CreateJoinTableCustomerProduct < ActiveRecord::Migration[6.0]
class CreateJoinTableCustomerProduct < ActiveRecord::Migration[7.0]
def change
create_join_table :customers, :products do |t|
# t.index [:customer_id, :product_id]
@ -291,7 +291,7 @@ $ bin/rails generate model Product name:string description:text
will create a migration that looks like this
```ruby
class CreateProducts < ActiveRecord::Migration[6.0]
class CreateProducts < ActiveRecord::Migration[7.0]
def change
create_table :products do |t|
t.string :name
@ -319,7 +319,7 @@ $ bin/rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplie
will produce a migration that looks like this
```ruby
class AddDetailsToProducts < ActiveRecord::Migration[6.0]
class AddDetailsToProducts < ActiveRecord::Migration[7.0]
def change
add_column :products, :price, :decimal, precision: 5, scale: 2
add_reference :products, :supplier, polymorphic: true
@ -605,7 +605,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[6.0]
class ExampleMigration < ActiveRecord::Migration[7.0]
def change
create_table :distributors do |t|
t.string :zipcode
@ -660,7 +660,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[6.0]
class ExampleMigration < ActiveRecord::Migration[7.0]
def up
create_table :distributors do |t|
t.string :zipcode
@ -703,7 +703,7 @@ You can use Active Record's ability to rollback migrations using the [`revert`][
```ruby
require_relative "20121212123456_example_migration"
class FixupExampleMigration < ActiveRecord::Migration[6.0]
class FixupExampleMigration < ActiveRecord::Migration[7.0]
def change
revert ExampleMigration
@ -721,7 +721,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[6.0]
class DontUseConstraintForZipcodeValidationMigration < ActiveRecord::Migration[7.0]
def change
revert do
# copy-pasted code from ExampleMigration
@ -883,7 +883,7 @@ Several methods are provided in migrations that allow you to control all this:
For example, this migration:
```ruby
class CreateProducts < ActiveRecord::Migration[6.0]
class CreateProducts < ActiveRecord::Migration[7.0]
def change
suppress_messages do
create_table :products do |t|
@ -1052,7 +1052,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[6.0]
class AddInitialProducts < ActiveRecord::Migration[7.0]
def up
5.times do |i|
Product.create(name: "Product ##{i}", description: "A product.")

View file

@ -106,7 +106,7 @@ NOTE: `belongs_to` associations _must_ use the singular term. If you used the pl
The corresponding migration might look like this:
```ruby
class CreateBooks < ActiveRecord::Migration[6.0]
class CreateBooks < ActiveRecord::Migration[7.0]
def change
create_table :authors do |t|
t.string :name
@ -153,7 +153,7 @@ The main difference from `belongs_to` is that the link column `supplier_id` is l
The corresponding migration might look like this:
```ruby
class CreateSuppliers < ActiveRecord::Migration[6.0]
class CreateSuppliers < ActiveRecord::Migration[7.0]
def change
create_table :suppliers do |t|
t.string :name
@ -199,7 +199,7 @@ NOTE: The name of the other model is pluralized when declaring a `has_many` asso
The corresponding migration might look like this:
```ruby
class CreateAuthors < ActiveRecord::Migration[6.0]
class CreateAuthors < ActiveRecord::Migration[7.0]
def change
create_table :authors do |t|
t.string :name
@ -251,7 +251,7 @@ end
The corresponding migration might look like this:
```ruby
class CreateAppointments < ActiveRecord::Migration[6.0]
class CreateAppointments < ActiveRecord::Migration[7.0]
def change
create_table :physicians do |t|
t.string :name
@ -337,7 +337,7 @@ end
The corresponding migration might look like this:
```ruby
class CreateAccountHistories < ActiveRecord::Migration[6.0]
class CreateAccountHistories < ActiveRecord::Migration[7.0]
def change
create_table :suppliers do |t|
t.string :name
@ -380,7 +380,7 @@ end
The corresponding migration might look like this:
```ruby
class CreateAssembliesAndParts < ActiveRecord::Migration[6.0]
class CreateAssembliesAndParts < ActiveRecord::Migration[7.0]
def change
create_table :assemblies do |t|
t.string :name
@ -419,7 +419,7 @@ end
The corresponding migration might look like this:
```ruby
class CreateSuppliers < ActiveRecord::Migration[6.0]
class CreateSuppliers < ActiveRecord::Migration[7.0]
def change
create_table :suppliers do |t|
t.string :name
@ -501,7 +501,7 @@ Similarly, you can retrieve `@product.pictures`.
If you have an instance of the `Picture` model, you can get to its parent via `@picture.imageable`. To make this work, you need to declare both a foreign key column and a type column in the model that declares the polymorphic interface:
```ruby
class CreatePictures < ActiveRecord::Migration[6.0]
class CreatePictures < ActiveRecord::Migration[7.0]
def change
create_table :pictures do |t|
t.string :name
@ -518,7 +518,7 @@ end
This migration can be simplified by using the `t.references` form:
```ruby
class CreatePictures < ActiveRecord::Migration[6.0]
class CreatePictures < ActiveRecord::Migration[7.0]
def change
create_table :pictures do |t|
t.string :name
@ -549,7 +549,7 @@ With this setup, you can retrieve `@employee.subordinates` and `@employee.manage
In your migrations/schema, you will add a references column to the model itself.
```ruby
class CreateEmployees < ActiveRecord::Migration[6.0]
class CreateEmployees < ActiveRecord::Migration[7.0]
def change
create_table :employees do |t|
t.references :manager, foreign_key: { to_table: :employees }
@ -619,7 +619,7 @@ end
This declaration needs to be backed up by a corresponding foreign key column in the books table. For a brand new table, the migration might look something like this:
```ruby
class CreateBooks < ActiveRecord::Migration[6.0]
class CreateBooks < ActiveRecord::Migration[7.0]
def change
create_table :books do |t|
t.datetime :published_at
@ -633,7 +633,7 @@ end
Whereas for an existing table, it might look like this:
```ruby
class AddAuthorToBooks < ActiveRecord::Migration[6.0]
class AddAuthorToBooks < ActiveRecord::Migration[7.0]
def change
add_reference :books, :author
end
@ -663,7 +663,7 @@ end
These need to be backed up by a migration to create the `assemblies_parts` table. This table should be created without a primary key:
```ruby
class CreateAssembliesPartsJoinTable < ActiveRecord::Migration[6.0]
class CreateAssembliesPartsJoinTable < ActiveRecord::Migration[7.0]
def change
create_table :assemblies_parts, id: false do |t|
t.bigint :assembly_id
@ -681,7 +681,7 @@ We pass `id: false` to `create_table` because that table does not represent a mo
You can also use the method `create_join_table`
```ruby
class CreateAssembliesPartsJoinTable < ActiveRecord::Migration[6.0]
class CreateAssembliesPartsJoinTable < ActiveRecord::Migration[7.0]
def change
create_join_table :assemblies, :parts do |t|
t.index :assembly_id