partitioned 1.3.3 → 1.3.4
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.
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            module Partitioned
         | 
| 2 | 
            +
              #
         | 
| 3 | 
            +
              # Partition tables by a time field grouping them by day, with
         | 
| 4 | 
            +
              # a day defined as 24 hours.
         | 
| 5 | 
            +
              #
         | 
| 6 | 
            +
              class ByDailyTimeField < ByTimeField
         | 
| 7 | 
            +
                self.abstract_class = true
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                #
         | 
| 10 | 
            +
                # Normalize a partition key value by day.
         | 
| 11 | 
            +
                #
         | 
| 12 | 
            +
                # @param [Time] time_value the time value to normalize
         | 
| 13 | 
            +
                # @return [Time] the value normalized
         | 
| 14 | 
            +
                def self.partition_normalize_key_value(time_value)
         | 
| 15 | 
            +
                  return time_value.at_beginning_of_day
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                #
         | 
| 19 | 
            +
                # The size of the partition table, 1 day (24 hours)
         | 
| 20 | 
            +
                # 
         | 
| 21 | 
            +
                # @return [Integer] the size of this partition
         | 
| 22 | 
            +
                def self.partition_table_size
         | 
| 23 | 
            +
                  return 1.day
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                partitioned do |partition|
         | 
| 27 | 
            +
                  partition.base_name lambda { |model, time_field|
         | 
| 28 | 
            +
                    return model.partition_normalize_key_value(time_field).strftime('%Y%m%d')
         | 
| 29 | 
            +
                  }
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
            end
         | 
| @@ -30,6 +30,7 @@ module Partitioned | |
| 30 30 | 
             
                    if is_leaf_partition?(*partition_key_values)
         | 
| 31 31 | 
             
                      add_partition_table_index(*partition_key_values)  
         | 
| 32 32 | 
             
                      add_references_to_partition_table(*partition_key_values)
         | 
| 33 | 
            +
                      configurator.run_after_partition_table_create_hooks(*partition_key_values)
         | 
| 33 34 | 
             
                    else
         | 
| 34 35 | 
             
                      add_parent_table_rules(*partition_key_values)
         | 
| 35 36 | 
             
                    end
         | 
    
        data/lib/partitioned/version.rb
    CHANGED
    
    
    
        data/partitioned.gemspec
    CHANGED
    
    | @@ -7,7 +7,7 @@ Gem::Specification.new do |s| | |
| 7 7 | 
             
              s.name           = 'partitioned'
         | 
| 8 8 | 
             
              s.version        = Partitioned::VERSION
         | 
| 9 9 | 
             
              s.license        = 'New BSD License'
         | 
| 10 | 
            -
              s.date           = '2013- | 
| 10 | 
            +
              s.date           = '2013-12-13'
         | 
| 11 11 | 
             
              s.summary        = "Postgres table partitioning support for ActiveRecord."
         | 
| 12 12 | 
             
              s.description    = "A gem providing support for table partitioning in ActiveRecord. Support is available for postgres and AWS RedShift databases. Other features include child table management (creation and deletion) and bulk data creating and updating."
         | 
| 13 13 | 
             
              s.authors        = ["Keith Gabryelski", "Aleksandr Dembskiy", "Edward Slavich"]
         | 
| @@ -0,0 +1,100 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            require "#{File.dirname(__FILE__)}/../support/tables_spec_helper"
         | 
| 3 | 
            +
            require "#{File.dirname(__FILE__)}/../support/shared_example_spec_helper_for_time_key"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Partitioned
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              describe ByDailyTimeField do
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                include TablesSpecHelper
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                module DailyTimeField
         | 
| 12 | 
            +
                  class Employee < ByDailyTimeField
         | 
| 13 | 
            +
                    belongs_to :company, :class_name => 'Company'
         | 
| 14 | 
            +
                    attr_accessible :name, :company_id, :created_at
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    def self.partition_time_field
         | 
| 17 | 
            +
                      return :created_at
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    partitioned do |partition|
         | 
| 21 | 
            +
                      partition.index :id, :unique => true
         | 
| 22 | 
            +
                      partition.foreign_key :company_id
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end # Employee
         | 
| 25 | 
            +
                end # DailyTimeField
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                before(:all) do
         | 
| 28 | 
            +
                  @employee = DailyTimeField::Employee
         | 
| 29 | 
            +
                  create_tables
         | 
| 30 | 
            +
                  dates = @employee.partition_generate_range(DATE_NOW,
         | 
| 31 | 
            +
                                                             DATE_NOW + 1.days)
         | 
| 32 | 
            +
                  @employee.create_new_partition_tables(dates)
         | 
| 33 | 
            +
                  ActiveRecord::Base.connection.execute <<-SQL
         | 
| 34 | 
            +
                    insert into employees_partitions.
         | 
| 35 | 
            +
                      p#{DATE_NOW.at_beginning_of_day.strftime('%Y%m%d')}
         | 
| 36 | 
            +
                      (company_id,name) values (1,'Keith');
         | 
| 37 | 
            +
                  SQL
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                after(:all) do
         | 
| 41 | 
            +
                  drop_tables
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                let(:class_by_daily_time_field) { ::Partitioned::ByDailyTimeField }
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                describe "model is abstract class" do
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  it "returns true" do
         | 
| 49 | 
            +
                    class_by_daily_time_field.abstract_class.should be_true
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                end # model is abstract class
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                describe "#partition_normalize_key_value" do
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  it "returns the beginning of the day" do
         | 
| 57 | 
            +
                    class_by_daily_time_field.
         | 
| 58 | 
            +
                        partition_normalize_key_value(Date.parse('2011-01-05')).
         | 
| 59 | 
            +
                        should == Date.parse('2011-01-03')
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                end # #partition_normalize_key_value
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                describe "#partition_table_size" do
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                  it "returns 1.day" do
         | 
| 67 | 
            +
                    class_by_daily_time_field.partition_table_size.should == 1.day
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                end # #partition_table_size
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                describe "partitioned block" do
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                  let(:data) do
         | 
| 75 | 
            +
                    class_by_daily_time_field.configurator_dsl.data
         | 
| 76 | 
            +
                  end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                  context "checks data in the base_name is Proc" do
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                    it "returns Proc" do
         | 
| 81 | 
            +
                      data.base_name.should be_is_a Proc
         | 
| 82 | 
            +
                    end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                  end # checks data in the base_name is Proc
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  context "checks data in the base_name" do
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                    it "returns base_name" do
         | 
| 89 | 
            +
                      data.base_name.call(@employee, Date.parse('2011-01-05')).should == "20110103"
         | 
| 90 | 
            +
                    end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                  end # checks data in the base_name
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                end # partitioned block
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                it_should_behave_like "check that basic operations with postgres works correctly for time key", DailyTimeField::Employee
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              end # ByDailyTimeField
         | 
| 99 | 
            +
             | 
| 100 | 
            +
            end # Partitioned
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: partitioned
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.3. | 
| 4 | 
            +
              version: 1.3.4
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -11,7 +11,7 @@ authors: | |
| 11 11 | 
             
            autorequire: 
         | 
| 12 12 | 
             
            bindir: bin
         | 
| 13 13 | 
             
            cert_chain: []
         | 
| 14 | 
            -
            date: 2013- | 
| 14 | 
            +
            date: 2013-12-13 00:00:00.000000000 Z
         | 
| 15 15 | 
             
            dependencies:
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 17 17 | 
             
              name: jquery-rails
         | 
| @@ -143,6 +143,7 @@ files: | |
| 143 143 | 
             
            - lib/partitioned.rb
         | 
| 144 144 | 
             
            - lib/partitioned/active_record_overrides.rb
         | 
| 145 145 | 
             
            - lib/partitioned/by_created_at.rb
         | 
| 146 | 
            +
            - lib/partitioned/by_daily_time_field.rb
         | 
| 146 147 | 
             
            - lib/partitioned/by_foreign_key.rb
         | 
| 147 148 | 
             
            - lib/partitioned/by_id.rb
         | 
| 148 149 | 
             
            - lib/partitioned/by_integer_field.rb
         | 
| @@ -198,6 +199,7 @@ files: | |
| 198 199 | 
             
            - spec/dummy/spec/spec_helper.rb
         | 
| 199 200 | 
             
            - spec/monkey_patch_posgres_spec.rb
         | 
| 200 201 | 
             
            - spec/partitioned/by_created_at_spec.rb
         | 
| 202 | 
            +
            - spec/partitioned/by_daily_time_field_spec.rb
         | 
| 201 203 | 
             
            - spec/partitioned/by_foreign_key_spec.rb
         | 
| 202 204 | 
             
            - spec/partitioned/by_id_spec.rb
         | 
| 203 205 | 
             
            - spec/partitioned/by_integer_field_spec.rb
         | 
| @@ -273,6 +275,7 @@ test_files: | |
| 273 275 | 
             
            - spec/dummy/spec/spec_helper.rb
         | 
| 274 276 | 
             
            - spec/monkey_patch_posgres_spec.rb
         | 
| 275 277 | 
             
            - spec/partitioned/by_created_at_spec.rb
         | 
| 278 | 
            +
            - spec/partitioned/by_daily_time_field_spec.rb
         | 
| 276 279 | 
             
            - spec/partitioned/by_foreign_key_spec.rb
         | 
| 277 280 | 
             
            - spec/partitioned/by_id_spec.rb
         | 
| 278 281 | 
             
            - spec/partitioned/by_integer_field_spec.rb
         | 
| @@ -290,4 +293,3 @@ test_files: | |
| 290 293 | 
             
            - spec/support/shared_example_spec_helper_for_integer_key.rb
         | 
| 291 294 | 
             
            - spec/support/shared_example_spec_helper_for_time_key.rb
         | 
| 292 295 | 
             
            - spec/support/tables_spec_helper.rb
         | 
| 293 | 
            -
            has_rdoc: 
         |