diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-16 20:46:37 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-16 20:46:37 +0900 |
commit | b40fbb5f9520ea2280a1deceaea8980fc620ac46 (patch) | |
tree | 669385db5044271937b42c26d8bc9ccd7c5715a6 /activerecord/lib | |
parent | 3ef3a921797c514ac48a019bfb229de200f1ba77 (diff) | |
parent | 33ce73edf1d1b02f4f50fc5d7565590468167d76 (diff) | |
download | rails-b40fbb5f9520ea2280a1deceaea8980fc620ac46.tar.gz rails-b40fbb5f9520ea2280a1deceaea8980fc620ac46.tar.bz2 rails-b40fbb5f9520ea2280a1deceaea8980fc620ac46.zip |
Merge pull request #33585 from yahonda/diag33520
SQLite3 adapter `alter_table` method restores foreign keys
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index bee74dc33d..38b1c31376 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -409,13 +409,14 @@ module ActiveRecord def alter_table(table_name, options = {}) altered_table_name = "a#{table_name}" + options_to_restore = { foreign_keys: foreign_keys(table_name) } caller = lambda { |definition| yield definition if block_given? } transaction do disable_referential_integrity do move_table(table_name, altered_table_name, options.merge(temporary: true)) - move_table(altered_table_name, table_name, &caller) + move_table(altered_table_name, table_name, options_to_restore, &caller) end end end @@ -446,6 +447,13 @@ module ActiveRecord primary_key: column_name == from_primary_key ) end + + if options[:foreign_keys] + options[:foreign_keys].each do |fk| + @definition.foreign_key(fk.to_table, fk.options) + end + end + yield @definition if block_given? end copy_table_indexes(from, to, options[:rename] || {}) |