提交 c0fb8d0b 编写于 作者: X Xavier Noria

Merge branch 'dump-schema-after-migration-flag' of...

Merge branch 'dump-schema-after-migration-flag' of git://github.com/emilsoman/rails into emilsoman-dump-schema-after-migration-flag

Conflicts:
	activerecord/CHANGELOG.md
* Add flag to disable schema dump after migration.
Add a config parameter on Active Record named `dump_schema_after_migration`
which is true by default. Now schema dump does not happen at the
end of migration rake task if `dump_schema_after_migration` is false.
*Emil Soman*
* `find_in_batches`, `find_each`, `Result#each` and `Enumerable#index_by` now
return an `Enumerator` that can calculate its size.
......
......@@ -76,6 +76,15 @@ def self.configurations
mattr_accessor :timestamped_migrations, instance_writer: false
self.timestamped_migrations = true
##
# :singleton-method:
# Specify whether schema dump should happen at the end of the
# db:migrate rake task. This is true by default, which is useful for the
# development environment. This should ideally be false in the production
# environment where dumping schema is rarely needed.
mattr_accessor :dump_schema_after_migration, instance_writer: false
self.dump_schema_after_migration = true
# :nodoc:
mattr_accessor :maintain_test_schema, instance_accessor: false
......
......@@ -34,7 +34,7 @@ db_namespace = namespace :db do
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
end
db_namespace['_dump'].invoke
db_namespace['_dump'].invoke if ActiveRecord::Base.dump_schema_after_migration
end
task :_dump do
......
......@@ -292,6 +292,12 @@ All these configuration options are delegated to the `I18n` library.
* `config.active_record.maintain_test_schema` is a boolean value which controls whether Active Record should try to keep your test database schema up-to-date with `db/schema.rb` (or `db/structure.sql`) when you run your tests. The default is true.
* `config.active_record.dump_schema_after_migration` is a flag which
controls whether or not schema dump should happen (`db/schema.rb` or
`db/structure.sql`) when you run migrations. This is set to false in
`config/environments/production.rb` which is generated by Rails. The
default value is true if this configuration is not set.
The MySQL adapter adds one additional configuration option:
* `ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans` controls whether Active Record will consider all `tinyint(1)` columns in a MySQL database to be booleans and is true by default.
......
* Set `dump_schema_after_migration` config values in production.
Set `config.active_record.dump_schema_after_migration` as false
in the generated `config/environments/production.rb` file.
*Emil Soman*
* Added Thor-action for creation of migrations.
Fixes #13588, #12674.
......
......@@ -81,4 +81,9 @@ Rails.application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
<%- unless options.skip_active_record? -%>
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
<%- end -%>
end
......@@ -781,5 +781,22 @@ def index
assert_not Rails.configuration.respond_to?(:method_missing)
assert Rails.configuration.respond_to?(:method_missing, true)
end
test "config.active_record.dump_schema_after_migration is false on production" do
build_app
ENV["RAILS_ENV"] = "production"
require "#{app_path}/config/environment"
assert_not ActiveRecord::Base.dump_schema_after_migration
end
test "config.active_record.dump_schema_after_migration is true by default on development" do
ENV["RAILS_ENV"] = "development"
require "#{app_path}/config/environment"
assert ActiveRecord::Base.dump_schema_after_migration
end
end
end
......@@ -153,6 +153,37 @@ class AMigration < ActiveRecord::Migration
assert_match(/up\s+\d{3,}\s+Add email to users/, output)
end
end
test 'schema generation when dump_schema_after_migration is set' do
add_to_config('config.active_record.dump_schema_after_migration = false')
Dir.chdir(app_path) do
`rails generate model book title:string;
bundle exec rake db:migrate`
assert !File.exist?("db/schema.rb")
end
add_to_config('config.active_record.dump_schema_after_migration = true')
Dir.chdir(app_path) do
`rails generate model author name:string;
bundle exec rake db:migrate`
structure_dump = File.read("db/schema.rb")
assert_match(/create_table "authors"/, structure_dump)
end
end
test 'default schema generation after migration' do
Dir.chdir(app_path) do
`rails generate model book title:string;
bundle exec rake db:migrate`
structure_dump = File.read("db/schema.rb")
assert_match(/create_table "books"/, structure_dump)
end
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册