<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -12,39 +12,39 @@ require File.join(File.dirname(__FILE__), 'engines/rails_extensions/rails')
 #
 # [+public_directory+]  The directory into which plugin assets should be
 #                       mirrored. Defaults to &lt;tt&gt;RAILS_ROOT/public/plugin_assets&lt;/tt&gt;.
-# [+schema_info_table+] The table to use when storing plugin migration 
+# [+schema_info_table+] The table to use when storing plugin migration
 #                       version information. Defaults to +plugin_schema_info+.
 #
 # Additionally, there are a few flags which control the behaviour of
 # some of the features the engines plugin adds to Rails:
 #
 # [+disable_application_view_loading+] A boolean flag determining whether
-#                                      or not views should be loaded from 
+#                                      or not views should be loaded from
 #                                      the main &lt;tt&gt;app/views&lt;/tt&gt; directory.
-#                                      Defaults to false; probably only 
+#                                      Defaults to false; probably only
 #                                      useful when testing your plugin.
 # [+disable_application_code_loading+] A boolean flag determining whether
-#                                      or not to load controllers/helpers 
+#                                      or not to load controllers/helpers
 #                                      from the main +app+ directory,
-#                                      if corresponding code exists within 
-#                                      a plugin. Defaults to false; again, 
-#                                      probably only useful when testing 
+#                                      if corresponding code exists within
+#                                      a plugin. Defaults to false; again,
+#                                      probably only useful when testing
 #                                      your plugin.
 # [+disable_code_mixing+] A boolean flag indicating whether all plugin
-#                         copies of a particular controller/helper should 
-#                         be loaded and allowed to override each other, 
-#                         or if the first matching file should be loaded 
+#                         copies of a particular controller/helper should
+#                         be loaded and allowed to override each other,
+#                         or if the first matching file should be loaded
 #                         instead. Defaults to false.
 #
 module Engines
   # The set of all loaded plugins
   mattr_accessor :plugins
-  self.plugins = Engines::Plugin::List.new  
-  
+  self.plugins = Engines::Plugin::List.new
+
   # List of extensions to load, can be changed in init.rb before calling Engines.init
   mattr_accessor :rails_extensions
   self.rails_extensions = %w(action_mailer asset_helpers routing migrations dependencies)
-  
+
   # The name of the public directory to mirror public engine assets into.
   # Defaults to &lt;tt&gt;RAILS_ROOT/public/plugin_assets&lt;/tt&gt;.
   mattr_accessor :public_directory
@@ -58,48 +58,48 @@ module Engines
   #--
   # These attributes control the behaviour of the engines extensions
   #++
-  
+
   # Set this to true if views should *only* be loaded from plugins
   mattr_accessor :disable_application_view_loading
   self.disable_application_view_loading = false
-  
-  # Set this to true if controller/helper code shouldn't be loaded 
+
+  # Set this to true if controller/helper code shouldn't be loaded
   # from the application
   mattr_accessor :disable_application_code_loading
   self.disable_application_code_loading = false
-  
+
   # Set this ti true if code should not be mixed (i.e. it will be loaded
   # from the first valid path on $LOAD_PATH)
   mattr_accessor :disable_code_mixing
   self.disable_code_mixing = false
-  
+
   # This is used to determine which files are candidates for the &quot;code
   # mixing&quot; feature that the engines plugin provides, where classes from
   # plugins can be loaded, and then code from the application loaded
   # on top of that code to override certain methods.
   mattr_accessor :code_mixing_file_types
   self.code_mixing_file_types = %w(controller helper)
-  
+
   class &lt;&lt; self
     def init
       load_extensions
       Engines::Assets.initialize_base_public_directory
     end
-    
+
     def logger
       RAILS_DEFAULT_LOGGER
     end
-    
+
     def load_extensions
       rails_extensions.each { |name| require &quot;engines/rails_extensions/#{name}&quot; unless name == 'migrations' }
       # load the testing extensions, if we are in the test environment.
       require &quot;engines/testing&quot; if RAILS_ENV == &quot;test&quot;
     end
-    
+
     def select_existing_paths(paths)
       paths.select { |path| File.directory?(path) }
-    end  
-  
+    end
+
     # The engines plugin will, by default, mix code from controllers and helpers,
     # allowing application code to override specific methods in the corresponding
     # controller or helper classes and modules. However, if other file types should
@@ -122,7 +122,7 @@ module Engines
     #
     # The important point here is that your &quot;things&quot; are named &lt;whatever&gt;_thing.rb,
     # and that they are placed within plugin/app/things (the pluralized form of 'thing').
-    # 
+    #
     # It's important to note that you'll also want to ensure that the &quot;things&quot; are
     # on your load path in your plugin's init.rb:
     #
@@ -131,44 +131,88 @@ module Engines
     def mix_code_from(*types)
       self.code_mixing_file_types += types.map { |x| x.to_s.singularize }
     end
-    
+
     # A general purpose method to mirror a directory (+source+) into a destination
     # directory, including all files and subdirectories. Files will not be mirrored
     # if they are identical already (checked via FileUtils#identical?).
     def mirror_files_from(source, destination)
       return unless File.directory?(source)
-      
-      # TODO: use Rake::FileList#pathmap?    
+
+      # TODO: use Rake::FileList#pathmap?
       source_files = Dir[source + &quot;/**/*&quot;]
       source_dirs = source_files.select { |d| File.directory?(d) }
       source_files -= source_dirs
-      
+
       unless source_files.empty?
         base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
         FileUtils.mkdir_p(base_target_dir)
       end
-      
+
       source_dirs.each do |dir|
         # strip down these paths so we have simple, relative paths we can
         # add to the destination
         target_dir = File.join(destination, dir.gsub(source, ''))
-        begin        
+        begin
           FileUtils.mkdir_p(target_dir)
         rescue Exception =&gt; e
           raise &quot;Could not create directory #{target_dir}: \n&quot; + e
         end
       end
-      
+
       source_files.each do |file|
         begin
           target = File.join(destination, file.gsub(source, ''))
           unless File.exist?(target) &amp;&amp; FileUtils.identical?(file, target)
             FileUtils.cp(file, target)
-          end 
+          end
         rescue Exception =&gt; e
-          raise &quot;Could not copy #{file} to #{target}: \n&quot; + e 
+          raise &quot;Could not copy #{file} to #{target}: \n&quot; + e
         end
-      end  
-    end   
-  end  
+      end
+    end
+
+    # Migrates migrations from multiple paths.  It will interweve the migrations
+    # based on timestamps instead of running all of the migrations grouped by plugin.
+    # This has been placed here instead of in engins/plugin/migrator or
+    # engines/rails_extensions/migrations to make sure neither
+    # of those files are loaded and used.
+    def migrate_multiple paths
+      stamp_paths = []
+      regex = /^\s*(\d+)[^\d].*\.rb\s*$/
+
+      # collect all of the paths in a 2 column array of the form
+      # [[stamp, path], [stamp, path]....]
+      # so that we can sort by stamps and then group by paths
+      paths.each do |path|
+        if File.exists?(path)
+          Dir.new(path).grep(regex).map do |file|
+            regex.match(file)[1]
+          end.compact.map(&amp;:to_i).sort.each do |stamp|
+            stamp_paths &lt;&lt; [stamp,path]
+          end
+        end
+      end
+
+      stamp_paths.sort!
+
+      if stamp_paths.size &gt; 0
+        last_stamp, last_path = stamp_paths.shift
+
+        migrate_proc = proc {ActiveRecord::Migrator.up(last_path, last_stamp)}
+
+        stamp_paths.each do |stamp,path|
+          # if the path doesn't match the last one, then we need to run the
+          # migrations for that last path up to that last stamp
+          if path != last_path
+            migrate_proc.call
+          end
+
+          last_path, last_stamp = path, stamp
+        end
+
+        # this will be the last stamp/path in the array.  We need to migrate to it.
+        migrate_proc.call
+      end
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>lib/engines.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@ unless Rake::TaskManager.methods.include?('redefine_task')
         task.enhance(deps, &amp;block)
         task
       end
-      
+
     end
     class Task
       class &lt;&lt; self
@@ -32,15 +32,15 @@ end
 namespace :db do
   namespace :migrate do
     desc 'Migrate database and plugins to current status.'
-    task :all =&gt; [ 'db:migrate', 'db:migrate:plugins' ]
-    
+    task :all =&gt; :environment do
+      Engines.migrate_multiple(
+        Engines.plugins.map(&amp;:migration_directory) + [File.join(RAILS_ROOT, &quot;db&quot;, &quot;migrate&quot;)]
+      )
+    end
+
     desc 'Migrate plugins to current status.'
     task :plugins =&gt; :environment do
-      Engines.plugins.each do |plugin|
-        next unless File.exists? plugin.migration_directory
-        puts &quot;Migrating plugin #{plugin.name} ...&quot;
-        ActiveRecord::Migrator.migrate(plugin.migration_directory)
-      end
+      Engines.migrate_multiple(Engines.plugins.map(&amp;:migration_directory))
     end
 
     desc 'Migrate a specified plugin.'
@@ -53,30 +53,30 @@ namespace :db do
       else
         puts &quot;Plugin #{name} does not exist.&quot;
       end
-    end    
+    end
   end
 end
 
 
-namespace :db do  
+namespace :db do
   namespace :fixtures do
     namespace :plugins do
-      
+
       desc &quot;Load plugin fixtures into the current environment's database.&quot;
       task :load =&gt; :environment do
         require 'active_record/fixtures'
         ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
-        Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', ENV['PLUGIN'] || '**', 
-                 'test', 'fixtures', '*.yml')).each do |fixture_file|
+        Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', ENV['PLUGIN'] || '**',
+            'test', 'fixtures', '*.yml')).each do |fixture_file|
           Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
         end
       end
-      
+
     end
   end
 end
 
-# this is just a modification of the original task in railties/lib/tasks/documentation.rake, 
+# this is just a modification of the original task in railties/lib/tasks/documentation.rake,
 # because the default task doesn't support subdirectories like &lt;plugin&gt;/app or
 # &lt;plugin&gt;/component. These tasks now include every file under a plugin's code paths (see
 # Plugin#code_paths).
@@ -103,7 +103,7 @@ namespace :doc do
           files.include(&quot;#{plugin_base}/{#{Engines.plugins[plugin].code_paths.join(&quot;,&quot;)}}/**/*.rb&quot;)
         end
         if File.exists?(&quot;#{plugin_base}/README&quot;)
-          files.include(&quot;#{plugin_base}/README&quot;)    
+          files.include(&quot;#{plugin_base}/README&quot;)
           options &lt;&lt; &quot;--main '#{plugin_base}/README'&quot;
         end
         files.include(&quot;#{plugin_base}/CHANGELOG&quot;) if File.exists?(&quot;#{plugin_base}/CHANGELOG&quot;)
@@ -142,25 +142,25 @@ Report any issues on http://dev.rails-engines.org. Thanks!
 
 -~===============( ... as you were ... )============================~-}
   end
-  
+
   namespace :plugins do
 
     desc &quot;Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)&quot;
-    task :all =&gt; [:warn_about_multiple_plugin_testing_with_engines, 
-                  :units, :functionals, :integration]
-    
+    task :all =&gt; [:warn_about_multiple_plugin_testing_with_engines,
+      :units, :functionals, :integration]
+
     desc &quot;Run all plugin unit tests&quot;
     Rake::TestTask.new(:units =&gt; :setup_plugin_fixtures) do |t|
       t.pattern = &quot;vendor/plugins/#{ENV['PLUGIN'] || &quot;**&quot;}/test/unit/**/*_test.rb&quot;
       t.verbose = true
     end
-    
+
     desc &quot;Run all plugin functional tests&quot;
     Rake::TestTask.new(:functionals =&gt; :setup_plugin_fixtures) do |t|
       t.pattern = &quot;vendor/plugins/#{ENV['PLUGIN'] || &quot;**&quot;}/test/functional/**/*_test.rb&quot;
       t.verbose = true
     end
-    
+
     desc &quot;Integration test engines&quot;
     Rake::TestTask.new(:integration =&gt; :setup_plugin_fixtures) do |t|
       t.pattern = &quot;vendor/plugins/#{ENV['PLUGIN'] || &quot;**&quot;}/test/integration/**/*_test.rb&quot;
@@ -171,8 +171,8 @@ Report any issues on http://dev.rails-engines.org. Thanks!
     task :setup_plugin_fixtures =&gt; :environment do
       Engines::Testing.setup_plugin_fixtures
     end
-    
+
     # Patch the default plugin testing task to have setup_plugin_fixtures as a prerequisite
     Rake::Task[&quot;test:plugins&quot;].prerequisites &lt;&lt; &quot;test:plugins:setup_plugin_fixtures&quot;
-  end  
+  end
 end
\ No newline at end of file</diff>
      <filename>tasks/engines.rake</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3870b6bfcc8591fad84b0408865cd1a9a6c10c37</id>
    </parent>
  </parents>
  <author>
    <name>Miles Georgi</name>
    <email>azimux@gmail.com</email>
  </author>
  <url>http://github.com/azimux/engines/commit/ad08502ab43849a22baae8b3305cf6ad1d789957</url>
  <id>ad08502ab43849a22baae8b3305cf6ad1d789957</id>
  <committed-date>2009-09-30T19:23:42-07:00</committed-date>
  <authored-date>2009-09-30T19:23:42-07:00</authored-date>
  <message>Made &quot;rake db:migrate:plugins&quot; and &quot;rake db:migrate:all&quot; interweave
plugin migrations/main project migrations based on timestamp
instead of running all of the migrations for one plugin at a time.</message>
  <tree>795f4563f86353c3751bb4e6e607af5602353cf0</tree>
  <committer>
    <name>Miles Georgi</name>
    <email>azimux@gmail.com</email>
  </committer>
</commit>
