Sha256: 0378afddc6dc63a5b5e350675d7f7064b8e01ec24e7be992ecf076ee6b595db0

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# We can't use Volt::Model until after the reconcile step has happened, so
# these methods work directly with the database.

module Volt
  class MigrationRunner
    alias_method :__run__, :run

    def run(direction=:up, until_version=nil)
      # reconcile after run in production
      # if Volt.env.production?
      #   Volt.current_app.database.reconcile!
      # end

      __run__(direction, until_version)
    end

    def raw_db
      @raw_db ||= Volt.current_app.database.raw_db
    end

    def ensure_migration_versions_table
      if !raw_db.tables || !raw_db.tables.include?(:migration_versions)
        raw_db.create_table(:migration_versions) do
          primary_key :id
          Fixnum :version, unique: true
        end
      end
    end

    def add_version(version)
      raw_db[:migration_versions].insert(version: version)
    end

    def has_version?(version)
      raw_db.from(:migration_versions).where(version: version).count > 0
    end

    def remove_version(version)
      raw_db.from(:migration_versions).where(version: version).delete
    end

    def all_versions
      raw_db.from(:migration_versions).all.map {|v| v[:version] }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
volt-sql-0.0.7 app/sql/lib/migration_runner.rb
volt-sql-0.0.6 app/sql/lib/migration_runner.rb
volt-sql-0.0.5 app/sql/lib/migration_runner.rb
volt-sql-0.0.4 app/sql/lib/migration_runner.rb