citrusbyte-schemer 0.0.9 → 0.0.10
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/lib/schemer.rb +11 -4
 - data/{tasks → lib/schemer/tasks}/schemer.rake +0 -0
 - data/test/schemer_test.rb +6 -0
 - metadata +2 -2
 
    
        data/lib/schemer.rb
    CHANGED
    
    | 
         @@ -37,13 +37,20 @@ module Schemer 
     | 
|
| 
       37 
37 
     | 
    
         
             
                def update_schema
         
     | 
| 
       38 
38 
     | 
    
         
             
                  create_table unless table_exists?
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
      
 40 
     | 
    
         
            +
                  columns.reject{ |column| protected_columns.include?(column.name) }.each do |column|
         
     | 
| 
      
 41 
     | 
    
         
            +
                    if !schema_columns.has_key?(column.name)
         
     | 
| 
      
 42 
     | 
    
         
            +
                      # remove any extraneous columns
         
     | 
| 
      
 43 
     | 
    
         
            +
                      ActiveRecord::Migration.remove_column(table_name, column.name)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    elsif column.type != schema_columns[column.name]
         
     | 
| 
      
 45 
     | 
    
         
            +
                      # change any columns w/ wrong type
         
     | 
| 
      
 46 
     | 
    
         
            +
                      ActiveRecord::Migration.change_column(table_name, column.name, schema_columns[column.name])
         
     | 
| 
      
 47 
     | 
    
         
            +
                    end
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  # add any missing columns
         
     | 
| 
       40 
51 
     | 
    
         
             
                  (schema_columns.keys - column_names).each do |column|
         
     | 
| 
       41 
52 
     | 
    
         
             
                    ActiveRecord::Migration.add_column(table_name, column, schema_columns[column])
         
     | 
| 
       42 
53 
     | 
    
         
             
                  end
         
     | 
| 
       43 
     | 
    
         
            -
                  
         
     | 
| 
       44 
     | 
    
         
            -
                  (column_names - protected_columns - schema_columns.keys).each do |column|
         
     | 
| 
       45 
     | 
    
         
            -
                    ActiveRecord::Migration.remove_column(table_name, column)
         
     | 
| 
       46 
     | 
    
         
            -
                  end
         
     | 
| 
       47 
54 
     | 
    
         
             
                end
         
     | 
| 
       48 
55 
     | 
    
         
             
              end
         
     | 
| 
       49 
56 
     | 
    
         
             
            end
         
     | 
| 
         
            File without changes
         
     | 
    
        data/test/schemer_test.rb
    CHANGED
    
    | 
         @@ -69,6 +69,12 @@ class FooTest < Test::Unit::TestCase 
     | 
|
| 
       69 
69 
     | 
    
         
             
                should "create foo column using string datatype" do
         
     | 
| 
       70 
70 
     | 
    
         
             
                  assert_equal '5', @foo.foo
         
     | 
| 
       71 
71 
     | 
    
         
             
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
                
         
     | 
| 
      
 73 
     | 
    
         
            +
                should "recreate foo column as integer" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  Foo.schema({ :foo => :integer }, { :bar => :integer }, :baz)
         
     | 
| 
      
 75 
     | 
    
         
            +
                  foo = Foo.find(Foo.create!(:foo => '5', :bar => '5').id)
         
     | 
| 
      
 76 
     | 
    
         
            +
                  assert_equal 5, foo.foo
         
     | 
| 
      
 77 
     | 
    
         
            +
                end
         
     | 
| 
       72 
78 
     | 
    
         
             
              end
         
     | 
| 
       73 
79 
     | 
    
         | 
| 
       74 
80 
     | 
    
         
             
              context "building a Rails migration" do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: citrusbyte-schemer
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.10
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ben Alavi
         
     | 
| 
         @@ -27,9 +27,9 @@ files: 
     | 
|
| 
       27 
27 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       28 
28 
     | 
    
         
             
            - lib/schemer/migrator.rb
         
     | 
| 
       29 
29 
     | 
    
         
             
            - lib/schemer.rb
         
     | 
| 
      
 30 
     | 
    
         
            +
            - lib/schemer/tasks/schemer.rake
         
     | 
| 
       30 
31 
     | 
    
         
             
            - rails/init.rb
         
     | 
| 
       31 
32 
     | 
    
         
             
            - test/schemer_test.rb
         
     | 
| 
       32 
     | 
    
         
            -
            - tasks/schemer.rake
         
     | 
| 
       33 
33 
     | 
    
         
             
            has_rdoc: false
         
     | 
| 
       34 
34 
     | 
    
         
             
            homepage: http://github.com/citrusbyte/schemer
         
     | 
| 
       35 
35 
     | 
    
         
             
            post_install_message: 
         
     |