Sha256: c6c4f4720d59b303e1638a5d2154d4842c94fefe503f2c06f40268df6dfa816f

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require "cardio/migration"

module Cardio
  class Migration
    # for migrations involving data transformations (but not schema changes)
    class Transform < Migration
      include Card::Model::SaveHelper unless ENV["NO_CARD_LOAD"]

      @migration_type = :transform
      @old_tables = %w[schema_migrations_core_cards schema_migrations_cards]
      @old_deck_table = "schema_migrations_deck_cards"

      private

      def with_migration_table
        self.table_name = "transform_migrations"
        yield
      ensure
        self.table_name = "schema_migrations"
      end

      # Execute this migration in the named direction
      # override ActiveRecord to wrap 'up' in 'contentedly'
      def exec_migration conn, direction
        return super if respond_to? :change

        @connection = conn
        contentedly { send direction }
      ensure
        @connection = nil
      end

      def contentedly
        return yield if ENV["NO_CARD_LOAD"]
        Card::Cache.reset_all
        Card::Auth.as_bot do
          yield
        ensure
          ::Card::Cache.reset_all
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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