Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/lhm/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def ddl(statement, algorithm: nil)
# @param [String] name Name of the column to add
# @param [String] definition Valid SQL column definition
# @param [String] algorithm Algorithm that will be used in the DDL operation
def add_column(name, definition, algorithm: 'INPLACE')
def add_column(name, definition, algorithm: 'COPY')
ddl('alter table `%s` add column `%s` %s' % [@name, name, definition], algorithm:)
end

Expand Down Expand Up @@ -89,7 +89,7 @@ def change_column(name, definition)
# @param [String] old Name of the column to change
# @param [String] nu New name to use for the column
# @param [String] algorithm Algorithm that will be used in the DDL operation
def rename_column(old, nu, algorithm: 'INPLACE')
def rename_column(old, nu, algorithm: 'COPY')
col = @origin.columns[old.to_s]

definition = col[:type]
Expand All @@ -113,7 +113,7 @@ def rename_column(old, nu, algorithm: 'INPLACE')
#
# @param [String] name Name of the column to delete
# @param [String] algorithm Algorithm that will be used in the DDL operation
def remove_column(name, algorithm: 'INPLACE')
def remove_column(name, algorithm: 'COPY')
ddl('alter table `%s` drop `%s`' % [@name, name], algorithm:)
end

Expand Down
12 changes: 12 additions & 0 deletions spec/integration/lhm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,18 @@
value(engine).must_equal("InnoDB")
end

it "should not fail using the default algorithms when changing tables with fulltext indexes" do
table_create(:users)
execute("DROP INDEX `index_with_a_custom_name` ON `users`")
execute("CREATE FULLTEXT INDEX `index_with_a_custom_name` ON `users` (`username`, `group`)")

Lhm.change_table(:users) do |t|
t.add_column(:email, "VARCHAR(255)")
end

value(table_read(:users).columns).must_include("email")
end

describe 'parallel' do
it 'should perserve inserts during migration' do
50.times { |n| execute("insert into users set reference = '#{ n }'") }
Expand Down
16 changes: 8 additions & 8 deletions spec/unit/migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
@creator.add_column('logins', 'INT(12)')

value(@creator.statements).must_equal([
'alter table `lhmn_alt` add column `logins` INT(12), ALGORITHM=INPLACE'
'alter table `lhmn_alt` add column `logins` INT(12), ALGORITHM=COPY'
])
end

Expand All @@ -113,7 +113,7 @@
@creator.remove_column('logins')

value(@creator.statements).must_equal([
'alter table `lhmn_alt` drop `logins`, ALGORITHM=INPLACE'
'alter table `lhmn_alt` drop `logins`, ALGORITHM=COPY'
])
end

Expand Down Expand Up @@ -167,24 +167,24 @@
value(@creator.statements.length).must_equal(2)

value(@creator.statements[0])
.must_equal('alter table `lhmn_alt` add column `first` VARCHAR(64), ALGORITHM=INPLACE')
.must_equal('alter table `lhmn_alt` add column `first` VARCHAR(64), ALGORITHM=COPY')

value(@creator.statements[1])
.must_equal('alter table `lhmn_alt` add column `last` VARCHAR(64), ALGORITHM=INPLACE')
.must_equal('alter table `lhmn_alt` add column `last` VARCHAR(64), ALGORITHM=COPY')
end
end

describe 'multiple changes using the passed algorithm' do
it 'should add two columns' do
@creator.add_column('first', 'VARCHAR(64)', algorithm: 'COPY')
@creator.add_column('last', 'VARCHAR(64)', algorithm: 'COPY')
@creator.add_column('first', 'VARCHAR(64)', algorithm: 'INPLACE')
@creator.add_column('last', 'VARCHAR(64)', algorithm: 'INPLACE')
value(@creator.statements.length).must_equal(2)

value(@creator.statements[0])
.must_equal('alter table `lhmn_alt` add column `first` VARCHAR(64), ALGORITHM=COPY')
.must_equal('alter table `lhmn_alt` add column `first` VARCHAR(64), ALGORITHM=INPLACE')

value(@creator.statements[1])
.must_equal('alter table `lhmn_alt` add column `last` VARCHAR(64), ALGORITHM=COPY')
.must_equal('alter table `lhmn_alt` add column `last` VARCHAR(64), ALGORITHM=INPLACE')
end
end
end