For my rails project I want to write a ruby gem which have an ActiveRecord model eg. Animal < ActiveRecord::Base. Is it possible to add migration cretae_animals to the gem in such a way that when the gem installed in my app and I run rake db:migrate that migration will execute? 
            Asked
            
        
        
            Active
            
        
            Viewed 2,237 times
        
    6
            
            
         
    
    
        lx00st
        
- 1,566
- 9
- 17
- 
                    You could add a generator to your gem that creates needed migrations. See: http://stackoverflow.com/a/4725949/2483313 – spickermann Jan 27 '15 at 10:56
- 
                    Yes I know, Im looking for a way when I can run all migrations with a single command – lx00st Jan 27 '15 at 11:02
1 Answers
3
            
            
        You can do this by including the migrations with your gem, as well as including a rake task that runs them. Then you call the rake task as follows:
myGem = Gem::Specification.find_by_name 'gem-name'
load "#{myGem.gem_dir}/lib/tasks/my_migration.rake"
(Proper credit to Andy Atkinson, where I originally learned this for a similar project.)
 
    
    
        taintedzodiac
        
- 2,658
- 1
- 18
- 16