Sha256: 83037e015e60ce08cdc0009cd9caa84e68201178a2e3f115343b36d54b7c4be4

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module Storey
  module Migrator

    extend self

    def migrate_all(options={})
      options[:version] = options[:version].to_i if options[:version]
      self.migrate 'public', options
      Dumper.dump
      Storey.schemas(public: false).each do |schema|
        self.migrate schema, options
      end
    end

    def migrate(schema, options={})
      Storey.switch schema do
        puts "= Migrating #{schema}"
        ::ActiveRecord::Migrator.migrate(::ActiveRecord::Migrator.migrations_path,
                                         options[:version])
      end
    end

    def run(direction, schema, version)
      Storey.switch schema do
        ::ActiveRecord::Migrator.run(
          direction,
          ::ActiveRecord::Migrator.migrations_path,
          version
        )
      end
    end

    def rollback_all(step=1)
      Storey.schemas.each do |schema_name|
        self.rollback(schema_name, step)
      end
      Dumper.dump
    end

    def rollback(schema, step=1)
      Storey.switch schema do
        puts "= Rolling back `#{schema}` #{step} steps"
        ::ActiveRecord::Migrator.rollback(
          ::ActiveRecord::Migrator.migrations_path,
          step
        )
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
storey-0.5.1 lib/storey/migrator.rb
storey-0.5.0 lib/storey/migrator.rb
storey-0.4.2 lib/storey/migrator.rb