Sha256: 1068570eb40908fb6c144c9e3b76edd23bd74dde3c34562bd02e8ee02173450c

Contents?: true

Size: 1.35 KB

Versions: 24

Compression:

Stored size: 1.35 KB

Contents

# Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
# Schmidt

require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'

require 'lhm/table'
require 'lhm/migration'
require 'lhm/locked_switcher'

describe Lhm::LockedSwitcher do
  include UnitHelper

  before(:each) do
    @start       = Time.now
    @origin      = Lhm::Table.new('origin')
    @destination = Lhm::Table.new('destination')
    @migration   = Lhm::Migration.new(@origin, @destination, @start)
    @switcher    = Lhm::LockedSwitcher.new(@migration, nil)
  end

  describe 'uncommitted' do
    it 'should disable autocommit first' do
      value(@switcher.statements[0..1]).must_equal([
        'set @lhm_auto_commit = @@session.autocommit',
        'set session autocommit = 0'
      ])
    end

    it 'should reapply original autocommit settings at the end' do
      value(@switcher.statements[-1])
        .must_equal('set session autocommit = @lhm_auto_commit')
    end
  end

  describe 'switch' do
    it 'should lock origin and destination table, switch, commit and unlock' do
      value(@switcher.switch).must_equal([
        'lock table `origin` write, `destination` write',
        "alter table `origin` rename `#{ @migration.archive_name }`",
        'alter table `destination` rename `origin`',
        'commit',
        'unlock tables'
      ])
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
lhm-shopify-3.5.0 spec/unit/locked_switcher_spec.rb
lhm-shopify-3.5.1 spec/unit/locked_switcher_spec.rb
lhm-shopify-3.4.2 spec/unit/locked_switcher_spec.rb
lhm-shopify-3.4.1 spec/unit/locked_switcher_spec.rb