Ticket #5470: activerecord_ddl_transactions.diff
| File activerecord_ddl_transactions.diff, 2.8 kB (added by adamwiggins, 2 years ago) |
|---|
-
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
old new 48 48 true 49 49 end 50 50 51 # Does this adapter support DDL rollbacks in transactions? That is, would 52 # CREATE TABLE or ALTER TABLE get rolled back by a transaction? PostgreSQL, 53 # SQL Server, and others support this. MySQL and others do not. 54 def supports_ddl_transactions? 55 false 56 end 57 51 58 # Should primary key values be selected from their corresponding 52 59 # sequence before the insert statement? If true, next_sequence_value 53 60 # is called before each insert to set the record's primary key. -
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
old new 107 107 true 108 108 end 109 109 110 def supports_ddl_transactions? 111 true 112 end 113 110 114 def table_alias_length 111 115 63 112 116 end -
activerecord/lib/active_record/migration.rb
old new 331 331 next if irrelevant_migration?(version) 332 332 333 333 Base.logger.info "Migrating to #{migration_class} (#{version})" 334 migration_class.migrate(@direction) 335 set_schema_version(version) 334 335 begin 336 ddl_transaction do 337 migration_class.migrate(@direction) 338 set_schema_version(version) 339 end 340 rescue => e 341 canceled_msg = Base.connection.supports_ddl_transactions? ? "this and " : "" 342 raise("An error has occurred, #{canceled_msg}all later migrations canceled:\n\n#{e}") 343 break unless @direction == :down 344 end 336 345 end 337 346 end 338 347 … … 347 356 348 357 down? ? migrations.sort.reverse : migrations.sort 349 358 end 359 360 # Wrap the migration in a transaction only if supported by the adapter. 361 def ddl_transaction(&block) 362 if Base.connection.supports_ddl_transactions? 363 Base.transaction { block.call } 364 else 365 block.call 366 end 367 end 350 368 351 369 def assert_unique_migration_version(migrations, version) 352 370 if !migrations.empty? && migrations.transpose.first.include?(version)