Sha256: 7e7f38020921ea9538eef27436cb3c77974cce91147195c0e1f87d0415c6ea56

Contents?: true

Size: 974 Bytes

Versions: 8

Compression:

Stored size: 974 Bytes

Contents

module CassandraObject
  module Migrations
    extend ActiveSupport::Concern
    extend ActiveSupport::Autoload

    included do
      class_inheritable_array :migrations
      class_inheritable_accessor :current_schema_version
      self.current_schema_version = 0
    end

    autoload :Migration
    
    class MigrationNotFoundError < StandardError
      def initialize(record_version, migrations)
        super("Cannot migrate a record from #{record_version.inspect}.  Migrations exist for #{migrations.map(&:version)}")
      end
    end
    
    module InstanceMethods
      def schema_version
        Integer(@schema_version || self.class.current_schema_version)
      end
    end
    
    module ClassMethods
      def migrate(version, &blk)
        write_inheritable_array(:migrations, [Migration.new(version, blk)])
        
        if version > self.current_schema_version 
          self.current_schema_version = version
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.7.3 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.7.2 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.7.1 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.7.0 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.6.4 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.6.3 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.6.2 lib/cassandra_object/migrations.rb
gotime-cassandra_object-2.6.1 lib/cassandra_object/migrations.rb