Skip to content

Loading…

Warning on uncopied migrations from railties #36

Closed
wants to merge 1 commit into from

2 participants

@drogus
Ruby on Rails member

Currently, there is a rake task to copy migrations from railties: rake railties:copy_migrations

It would be nice to give user a warning when doing db:migrate with not copied migrations and say how to copy them.

@josevalim

Maybe this method could be in the Rails.application object?

Ruby on Rails member

It's used only here and I can't see any use cases to use it elsewhere, I don't know if it's worth it.

If you are on for moving it, I can of course do it.

@drogus
Ruby on Rails member

This is not relevant by now, copying migrations has been changed.

@Eric-Guo Eric-Guo added a commit that referenced this pull request
@Eric-Guo Eric-Guo After rack 1.6.0, by default, the rack will also out put the log whic…
…h is not intent in rails.

Such change will also close the quiet_assets [#36](evrone/quiet_assets#36) issue.
37e4a67
@Eric-Guo Eric-Guo added a commit that referenced this pull request
@Eric-Guo Eric-Guo After rack 1.6.0, by default, the rack will also out put the log whic…
…h is not intent in rails.

Such change will also close the quiet_assets [#36](evrone/quiet_assets#36) issue.
2bc2c9a
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
View
18 activerecord/lib/active_record/migration.rb
@@ -384,8 +384,8 @@ def method_missing(method, *arguments, &block)
end
end
- def copy(destination, sources)
- copied = []
+ def uncopied_migrations(destination, sources)
+ migrations = []
sources.each do |scope, path|
destination_migrations = ActiveRecord::Migrator.migrations(destination)
@@ -399,11 +399,21 @@ def copy(destination, sources)
last = migration
new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.#{scope}.rb")
- FileUtils.cp(migration.filename, new_path)
- copied << new_path
+ migrations << [scope, migration.filename, new_path]
end
end
+ migrations
+ end
+
+ def copy(destination, sources)
+ copied = []
+
+ uncopied_migrations(destination, sources).each do |scope, path, new_path|
+ FileUtils.cp(path, new_path)
+ copied << new_path
+ end
+
copied
end
View
31 activerecord/lib/active_record/railties/databases.rake
@@ -7,16 +7,8 @@ namespace :db do
task :copy_migrations => :load_config do
to_load = ENV["FROM"].blank? ? :all : ENV["FROM"].split(",").map {|n| n.strip }
- railties = {}
- Rails.application.railties.all do |railtie|
- next unless to_load == :all || to_load.include?(railtie.railtie_name)
- if railtie.config.respond_to?(:paths) && railtie.config.paths.db
- railties[railtie.railtie_name] = railtie.config.paths.db.migrate.to_a.first
- end
- end
-
- copied = ActiveRecord::Migration.copy(ActiveRecord::Migrator.migrations_path, railties)
+ copied = ActiveRecord::Migration.copy(ActiveRecord::Migrator.migrations_path, railties_migrations(to_load))
if copied.blank?
puts "No migrations were copied, project is up to date."
@@ -163,6 +155,14 @@ namespace :db do
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_path, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
+
+ uncopied = ActiveRecord::Migration.uncopied_migrations(ActiveRecord::Migrator.migrations_path, railties_migrations)
+ unless uncopied.blank?
+ puts "Warning: not copied migrations exist, you may want to copy them with `rake railties:copy_migrations`:\n"
+ uncopied.each do |scope, path, new_path|
+ puts " #{scope}: #{path}"
+ end
+ end
end
namespace :migrate do
@@ -537,3 +537,16 @@ end
def firebird_db_string(config)
FireRuby::Database.db_string_for(config.symbolize_keys)
end
+
+def railties_migrations(to_load = :all)
+ railties = {}
+ Rails.application.railties.all do |railtie|
+ next unless to_load == :all || to_load.include?(railtie.railtie_name)
+
+ if railtie.config.respond_to?(:paths) && railtie.config.paths.db
+ railties[railtie.railtie_name] = railtie.config.paths.db.migrate.to_a.first
+ end
+ end
+
+ railties
+end
View
7 railties/test/railties/shared_tests.rb
@@ -38,6 +38,13 @@ class CreateYaffles < ActiveRecord::Migration
add_to_config "ActiveRecord::Base.timestamped_migrations = false"
Dir.chdir(app_path) do
+ output = `rake db:migrate`
+
+ assert_match /not copied migrations exist/, output
+ assert_match /bukkits: .*db\/migrate\/1_create_users.rb/, output
+ assert_match /bukkits: .*db\/migrate\/2_add_last_name_to_users.rb/, output
+ assert_match /acts_as_yaffle: .*db\/migrate\/1_create_yaffles.rb/, output
+
output = `rake railties:copy_migrations FROM=bukkits`
assert File.exists?("#{app_path}/db/migrate/2_create_users.bukkits.rb")
Something went wrong with that request. Please try again.