also_migrate 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
 - data/lib/also_migrate.rb +11 -1
 - data/lib/also_migrate/base.rb +2 -0
 - data/lib/also_migrate/gems.rb +44 -0
 - data/lib/also_migrate/migration.rb +25 -25
 - data/lib/also_migrate/migrator.rb +5 -3
 - data/lib/also_migrate/version.rb +1 -1
 - metadata +11 -32
 
    
        data/README.md
    CHANGED
    
    
    
        data/lib/also_migrate.rb
    CHANGED
    
    | 
         @@ -1,9 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/also_migrate/gems'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            AlsoMigrate::Gems.require(:lib)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       1 
5 
     | 
    
         
             
            $:.unshift File.dirname(__FILE__) + '/also_migrate'
         
     | 
| 
       2 
6 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require 'version'
         
     | 
| 
       4 
7 
     | 
    
         
             
            require 'base'
         
     | 
| 
       5 
8 
     | 
    
         
             
            require 'migration'
         
     | 
| 
       6 
9 
     | 
    
         
             
            require 'migrator'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'version'
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            module AlsoMigrate
         
     | 
| 
      
 13 
     | 
    
         
            +
              class <<self
         
     | 
| 
      
 14 
     | 
    
         
            +
                attr_accessor :classes
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
       7 
17 
     | 
    
         | 
| 
       8 
18 
     | 
    
         
             
            ActiveRecord::Base.send(:include, AlsoMigrate::Base)
         
     | 
| 
       9 
19 
     | 
    
         
             
            ActiveRecord::Migrator.send(:include, AlsoMigrate::Migrator)
         
     | 
    
        data/lib/also_migrate/base.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            unless defined?(AlsoMigrate::Gems)
         
     | 
| 
      
 2 
     | 
    
         
            +
              
         
     | 
| 
      
 3 
     | 
    
         
            +
              require 'rubygems'
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              module AlsoMigrate
         
     | 
| 
      
 6 
     | 
    
         
            +
                class Gems
         
     | 
| 
      
 7 
     | 
    
         
            +
                
         
     | 
| 
      
 8 
     | 
    
         
            +
                  VERSIONS = {
         
     | 
| 
      
 9 
     | 
    
         
            +
                    :active_wrapper => '=0.3.4',
         
     | 
| 
      
 10 
     | 
    
         
            +
                    :rake => '=0.8.7',
         
     | 
| 
      
 11 
     | 
    
         
            +
                    :rspec => '=1.3.1'
         
     | 
| 
      
 12 
     | 
    
         
            +
                  }
         
     | 
| 
      
 13 
     | 
    
         
            +
                
         
     | 
| 
      
 14 
     | 
    
         
            +
                  TYPES = {
         
     | 
| 
      
 15 
     | 
    
         
            +
                    :gemspec => [],
         
     | 
| 
      
 16 
     | 
    
         
            +
                    :gemspec_dev => [ :rspec ],
         
     | 
| 
      
 17 
     | 
    
         
            +
                    :lib => [],
         
     | 
| 
      
 18 
     | 
    
         
            +
                    :rake => [ :rake, :rspec ],
         
     | 
| 
      
 19 
     | 
    
         
            +
                    :spec => [ :active_wrapper, :rspec ],
         
     | 
| 
      
 20 
     | 
    
         
            +
                    :spec_rake => [ :active_wrapper ]
         
     | 
| 
      
 21 
     | 
    
         
            +
                  }
         
     | 
| 
      
 22 
     | 
    
         
            +
                  
         
     | 
| 
      
 23 
     | 
    
         
            +
                  class <<self
         
     | 
| 
      
 24 
     | 
    
         
            +
                    
         
     | 
| 
      
 25 
     | 
    
         
            +
                    def lockfile
         
     | 
| 
      
 26 
     | 
    
         
            +
                      file = File.expand_path('../../../gems', __FILE__)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      unless File.exists?(file)
         
     | 
| 
      
 28 
     | 
    
         
            +
                        File.open(file, 'w') do |f|
         
     | 
| 
      
 29 
     | 
    
         
            +
                          Gem.loaded_specs.each do |key, value|
         
     | 
| 
      
 30 
     | 
    
         
            +
                            f.puts "#{key} #{value.version.version}"
         
     | 
| 
      
 31 
     | 
    
         
            +
                          end
         
     | 
| 
      
 32 
     | 
    
         
            +
                        end
         
     | 
| 
      
 33 
     | 
    
         
            +
                      end
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
                    
         
     | 
| 
      
 36 
     | 
    
         
            +
                    def require(type=nil)
         
     | 
| 
      
 37 
     | 
    
         
            +
                      (TYPES[type] || TYPES.values.flatten.compact).each do |name|
         
     | 
| 
      
 38 
     | 
    
         
            +
                        gem name.to_s, VERSIONS[name]
         
     | 
| 
      
 39 
     | 
    
         
            +
                      end
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -31,32 +31,32 @@ module AlsoMigrate 
     | 
|
| 
       31 
31 
     | 
    
         
             
                      table_name = ActiveRecord::Migrator.proper_table_name(args[0])
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                      # Find models
         
     | 
| 
       34 
     | 
    
         
            -
                       
     | 
| 
       35 
     | 
    
         
            -
                         
     | 
| 
       36 
     | 
    
         
            -
                           
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                               
     | 
| 
       45 
     | 
    
         
            -
                            end
         
     | 
| 
      
 34 
     | 
    
         
            +
                      if ::AlsoMigrate.classes
         
     | 
| 
      
 35 
     | 
    
         
            +
                        ::AlsoMigrate.classes.uniq.each do |klass|
         
     | 
| 
      
 36 
     | 
    
         
            +
                          if klass.also_migrate_config
         
     | 
| 
      
 37 
     | 
    
         
            +
                            klass.also_migrate_config.each do |config|
         
     | 
| 
      
 38 
     | 
    
         
            +
                              options = config[:options]
         
     | 
| 
      
 39 
     | 
    
         
            +
                              tables = config[:tables]
         
     | 
| 
      
 40 
     | 
    
         
            +
                          
         
     | 
| 
      
 41 
     | 
    
         
            +
                              # Don't change ignored columns
         
     | 
| 
      
 42 
     | 
    
         
            +
                              options[:ignore].each do |column|
         
     | 
| 
      
 43 
     | 
    
         
            +
                                next if args.include?(column) || args.include?(column.intern)
         
     | 
| 
      
 44 
     | 
    
         
            +
                              end
         
     | 
| 
       46 
45 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
                              # Run migration
         
     | 
| 
      
 47 
     | 
    
         
            +
                              config[:tables].each do |table|
         
     | 
| 
      
 48 
     | 
    
         
            +
                                if method == :create_table
         
     | 
| 
      
 49 
     | 
    
         
            +
                                  ActiveRecord::Migrator::AlsoMigrate.create_tables(klass)
         
     | 
| 
      
 50 
     | 
    
         
            +
                                elsif method == :add_index && !options[:indexes].nil?
         
     | 
| 
      
 51 
     | 
    
         
            +
                                  next
         
     | 
| 
      
 52 
     | 
    
         
            +
                                elsif connection.table_exists?(table)
         
     | 
| 
      
 53 
     | 
    
         
            +
                                  args[0] = table
         
     | 
| 
      
 54 
     | 
    
         
            +
                                  args[1] = table if method == :rename_table
         
     | 
| 
      
 55 
     | 
    
         
            +
                                  begin
         
     | 
| 
      
 56 
     | 
    
         
            +
                                    connection.send(method, *args, &block)
         
     | 
| 
      
 57 
     | 
    
         
            +
                                  rescue Exception => e
         
     | 
| 
      
 58 
     | 
    
         
            +
                                    puts "(also_migrate warning) #{e.message}"
         
     | 
| 
      
 59 
     | 
    
         
            +
                                  end
         
     | 
| 
       60 
60 
     | 
    
         
             
                                end
         
     | 
| 
       61 
61 
     | 
    
         
             
                              end
         
     | 
| 
       62 
62 
     | 
    
         
             
                            end
         
     | 
| 
         @@ -14,9 +14,11 @@ module AlsoMigrate 
     | 
|
| 
       14 
14 
     | 
    
         
             
                module InstanceMethods
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                  def migrate_with_also_migrate
         
     | 
| 
       17 
     | 
    
         
            -
                     
     | 
| 
       18 
     | 
    
         
            -
                       
     | 
| 
       19 
     | 
    
         
            -
                         
     | 
| 
      
 17 
     | 
    
         
            +
                    if ::AlsoMigrate.classes
         
     | 
| 
      
 18 
     | 
    
         
            +
                      ::AlsoMigrate.classes.uniq.each do |klass|
         
     | 
| 
      
 19 
     | 
    
         
            +
                        if klass.respond_to?(:also_migrate_config)
         
     | 
| 
      
 20 
     | 
    
         
            +
                          AlsoMigrate.create_tables(klass)
         
     | 
| 
      
 21 
     | 
    
         
            +
                        end
         
     | 
| 
       20 
22 
     | 
    
         
             
                      end
         
     | 
| 
       21 
23 
     | 
    
         
             
                    end
         
     | 
| 
       22 
24 
     | 
    
         
             
                  rescue Exception => e
         
     | 
    
        data/lib/also_migrate/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: also_migrate
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash: 25
         
     | 
| 
       5 
4 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       6 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 7 
     | 
    
         
            +
              - 2
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       11 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
12 
     | 
    
         
             
            - Winton Welsh
         
     | 
| 
         @@ -15,43 +14,24 @@ autorequire: 
     | 
|
| 
       15 
14 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
15 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2010- 
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2010-12-04 00:00:00 -08:00
         
     | 
| 
       19 
18 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
19 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
20 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       22 
     | 
    
         
            -
              type: :development
         
     | 
| 
       23 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              name: bundler
         
     | 
| 
       25 
     | 
    
         
            -
              version_requirements: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
       26 
     | 
    
         
            -
                none: false
         
     | 
| 
       27 
     | 
    
         
            -
                requirements: 
         
     | 
| 
       28 
     | 
    
         
            -
                - - "="
         
     | 
| 
       29 
     | 
    
         
            -
                  - !ruby/object:Gem::Version 
         
     | 
| 
       30 
     | 
    
         
            -
                    hash: 62196361
         
     | 
| 
       31 
     | 
    
         
            -
                    segments: 
         
     | 
| 
       32 
     | 
    
         
            -
                    - 1
         
     | 
| 
       33 
     | 
    
         
            -
                    - 0
         
     | 
| 
       34 
     | 
    
         
            -
                    - 0
         
     | 
| 
       35 
     | 
    
         
            -
                    - beta
         
     | 
| 
       36 
     | 
    
         
            -
                    - 5
         
     | 
| 
       37 
     | 
    
         
            -
                    version: 1.0.0.beta.5
         
     | 
| 
       38 
     | 
    
         
            -
              requirement: *id001
         
     | 
| 
       39 
     | 
    
         
            -
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       40 
     | 
    
         
            -
              type: :development
         
     | 
| 
       41 
     | 
    
         
            -
              prerelease: false
         
     | 
| 
       42 
21 
     | 
    
         
             
              name: rspec
         
     | 
| 
       43 
     | 
    
         
            -
               
     | 
| 
      
 22 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 23 
     | 
    
         
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
       44 
24 
     | 
    
         
             
                none: false
         
     | 
| 
       45 
25 
     | 
    
         
             
                requirements: 
         
     | 
| 
       46 
26 
     | 
    
         
             
                - - "="
         
     | 
| 
       47 
27 
     | 
    
         
             
                  - !ruby/object:Gem::Version 
         
     | 
| 
       48 
     | 
    
         
            -
                    hash: 27
         
     | 
| 
       49 
28 
     | 
    
         
             
                    segments: 
         
     | 
| 
       50 
29 
     | 
    
         
             
                    - 1
         
     | 
| 
       51 
30 
     | 
    
         
             
                    - 3
         
     | 
| 
       52 
     | 
    
         
            -
                    -  
     | 
| 
       53 
     | 
    
         
            -
                    version: 1.3. 
     | 
| 
       54 
     | 
    
         
            -
               
     | 
| 
      
 31 
     | 
    
         
            +
                    - 1
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: 1.3.1
         
     | 
| 
      
 33 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 34 
     | 
    
         
            +
              version_requirements: *id001
         
     | 
| 
       55 
35 
     | 
    
         
             
            description: Migrate multiple tables with similar schema at once
         
     | 
| 
       56 
36 
     | 
    
         
             
            email: 
         
     | 
| 
       57 
37 
     | 
    
         
             
            - mail@wintoni.us
         
     | 
| 
         @@ -63,6 +43,7 @@ extra_rdoc_files: [] 
     | 
|
| 
       63 
43 
     | 
    
         | 
| 
       64 
44 
     | 
    
         
             
            files: 
         
     | 
| 
       65 
45 
     | 
    
         
             
            - lib/also_migrate/base.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/also_migrate/gems.rb
         
     | 
| 
       66 
47 
     | 
    
         
             
            - lib/also_migrate/migration.rb
         
     | 
| 
       67 
48 
     | 
    
         
             
            - lib/also_migrate/migrator.rb
         
     | 
| 
       68 
49 
     | 
    
         
             
            - lib/also_migrate/version.rb
         
     | 
| 
         @@ -83,7 +64,6 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       83 
64 
     | 
    
         
             
              requirements: 
         
     | 
| 
       84 
65 
     | 
    
         
             
              - - ">="
         
     | 
| 
       85 
66 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       86 
     | 
    
         
            -
                  hash: 3
         
     | 
| 
       87 
67 
     | 
    
         
             
                  segments: 
         
     | 
| 
       88 
68 
     | 
    
         
             
                  - 0
         
     | 
| 
       89 
69 
     | 
    
         
             
                  version: "0"
         
     | 
| 
         @@ -92,7 +72,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       92 
72 
     | 
    
         
             
              requirements: 
         
     | 
| 
       93 
73 
     | 
    
         
             
              - - ">="
         
     | 
| 
       94 
74 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       95 
     | 
    
         
            -
                  hash: 3
         
     | 
| 
       96 
75 
     | 
    
         
             
                  segments: 
         
     | 
| 
       97 
76 
     | 
    
         
             
                  - 0
         
     | 
| 
       98 
77 
     | 
    
         
             
                  version: "0"
         
     |