| | 365 | if current_adapter?(:MysqlAdapter) |
|---|
| | 366 | def test_rename_column_preserve_auto_increment |
|---|
| | 367 | begin |
|---|
| | 368 | ActiveRecord::Base.connection.create_table(:legacy) {} # We just need the id column |
|---|
| | 369 | legacy = Class.new(ActiveRecord::Base) |
|---|
| | 370 | legacy.send(:define_attr_method, :table_name, "legacy") |
|---|
| | 371 | options = legacy.connection.select_one("SHOW COLUMNS FROM legacy LIKE 'id'") |
|---|
| | 372 | assert_equal 'auto_increment', options['Extra'] |
|---|
| | 373 | |
|---|
| | 374 | legacy.connection.rename_column("legacy", "id", "orig_id") |
|---|
| | 375 | options = legacy.connection.select_one("SHOW COLUMNS FROM legacy LIKE 'orig_id'") |
|---|
| | 376 | assert_equal 'auto_increment', options['Extra'] |
|---|
| | 377 | ensure |
|---|
| | 378 | ActiveRecord::Base.connection.drop_table :legacy rescue nil |
|---|
| | 379 | end |
|---|
| | 380 | end |
|---|
| | 381 | end |
|---|
| | 382 | |
|---|
| | 383 | def test_rename_column_preserve_default |
|---|
| | 384 | begin |
|---|
| | 385 | Person.connection.add_column "people", "contibutions", :integer, :default => 10, :null => false |
|---|
| | 386 | Person.reset_column_information |
|---|
| | 387 | columns = Person.connection.columns(:people) |
|---|
| | 388 | column = columns.detect { |c| c.name == "contibutions" } |
|---|
| | 389 | assert_equal 10, column.default |
|---|
| | 390 | assert !column.null |
|---|
| | 391 | |
|---|
| | 392 | Person.connection.rename_column("people", "contibutions", "contributions") |
|---|
| | 393 | Person.reset_column_information |
|---|
| | 394 | columns = Person.connection.columns(:people) |
|---|
| | 395 | column = columns.detect { |c| c.name == "contributions" } |
|---|
| | 396 | assert_equal 10, column.default |
|---|
| | 397 | assert !column.null |
|---|
| | 398 | ensure |
|---|
| | 399 | Person.connection.remove_column("people", "contibutions") rescue ActiveRecord::StatementInvalid |
|---|
| | 400 | Person.connection.remove_column("people", "contributions") rescue ActiveRecord::StatementInvalid |
|---|
| | 401 | end |
|---|
| | 402 | end |
|---|
| | 403 | |
|---|