Sha256: 4c4059fa0c2fa248a02320329a8da990bb5b48ed869531f3be268ac5626a9c31

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module MigrationDSLExtension
  def transaction_options(opts)
    migration.transaction_opts = opts
  end
end

module SimpleMigrationExtension
  attr_accessor :transaction_opts
end

module MigratorExtension
  def checked_transaction(migration, &block)
    if _use_transaction?(migration)
      _transaction(migration, &block)
    else
      yield
    end
  end

  private

  def _use_transaction?(migration)
    # NOTE: original code
    if @use_transactions.nil?
      if migration.use_transactions.nil?
        @db.supports_transactional_ddl?
      else
        # :nocov:
        migration.use_transactions
        # :nocov:
      end
    else
      # :nocov:
      @use_transactions
      # :nocov:
    end
  end

  def _transaction(migration, &block)
    if migration.transaction_opts.nil?
      db.transaction(&block)
    else
      db.transaction(migration.transaction_opts, &block)
    end
  end
end

Sequel::MigrationDSL.include(MigrationDSLExtension)
Sequel::SimpleMigration.include(SimpleMigrationExtension)
Sequel::Migrator.prepend(MigratorExtension)

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.17.0 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.1 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0.239 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0.238 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0.235 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0.234 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0.233 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.16.0.211 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.15.0.198 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.14.0.192 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.14.0.189 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.14.0.188 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.14.0.187 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.14.0 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.13.0.185 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.13.0.172 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.13.0 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.12.0.169 lib/sequel/extensions/migration_transaction_options.rb
umbrellio-sequel-plugins-0.12.0 lib/sequel/extensions/migration_transaction_options.rb