Sha256: 93c13d7069d00f88213f2b6373192daa706d6c5159d8b15150c3be8440500e64

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

# -*- encoding : utf-8 -*-

module Cardio
  class Migration < ActiveRecord::Migration[6.1]
    include Assumption
    include Stamp
    extend Port

    class << self
      attr_reader :migration_type, :old_tables, :old_deck_table

      def migration_class type
        type == :schema ? Migration::Schema : Migration::Transform
      end

      def new_for type
        migration_class(type).new
      end

      private

      def table
        "#{migration_type}_migrations"
      end
    end

    def migration_type
      self.class.migration_type || :schema
    end

    def run version=nil, verbose=true
      context do |mc|
        ActiveRecord::Migration.verbose = verbose
        mc.migrate version
      end
    end

    def version
      path = stamp_path
      File.exist?(path) ? File.read(path).strip : nil
    end

    def migration_paths
      Cardio.paths["data/#{migration_type}"].existent.to_a
    end

    def context
      mode do |paths|
        migrations = ActiveRecord::SchemaMigration.new ActiveRecord::Base.connection_pool
        yield ActiveRecord::MigrationContext.new(paths, migrations)
      end
    end

    def mode
      with_migration_table { yield migration_paths }
    end

    def down
      raise ActiveRecord::IrreversibleMigration
    end

    private

    def with_migration_table
      yield
    end

    def table_name= table_name
      ActiveRecord::Base.schema_migrations_table_name = table_name
      # ActiveRecord::SchemaMigration.table_name = table_name
      # ActiveRecord::SchemaMigration.reset_column_information
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
card-1.108.1 lib/cardio/migration.rb
card-1.108.0 lib/cardio/migration.rb