Skip to content

Commit a7e1d18

Browse files
authored
Merge pull request #2417 from michael-smith-nz/add_timestamps_fix
Update add_timestamps to support 7.1
2 parents c21146a + a3db6a3 commit a7e1d18

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,13 @@ def create_alter_table(name)
622622
OracleEnhanced::AlterTable.new create_table_definition(name)
623623
end
624624

625+
def add_timestamps(table_name, **options)
626+
fragments = add_timestamps_for_alter(table_name, **options)
627+
fragments.each do |fragment|
628+
execute "ALTER TABLE #{quote_table_name(table_name)} #{fragment}"
629+
end
630+
end
631+
625632
def update_table_definition(table_name, base)
626633
OracleEnhanced::Table.new(table_name, base)
627634
end

spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,34 @@ class ::TestEmployee < ActiveRecord::Base; end
387387
end
388388
end
389389

390+
describe "add timestamps" do
391+
before(:each) do
392+
@conn = ActiveRecord::Base.connection
393+
schema_define do
394+
create_table :test_employees, force: true
395+
end
396+
class ::TestEmployee < ActiveRecord::Base; end
397+
end
398+
399+
after(:each) do
400+
schema_define do
401+
drop_table :test_employees, if_exists: true
402+
end
403+
Object.send(:remove_const, "TestEmployee")
404+
ActiveRecord::Base.clear_cache!
405+
end
406+
407+
it "should add created_at and updated_at" do
408+
expect do
409+
@conn.add_timestamps("test_employees")
410+
end.not_to raise_error
411+
412+
TestEmployee.reset_column_information
413+
expect(TestEmployee.columns_hash["created_at"]).not_to be_nil
414+
expect(TestEmployee.columns_hash["updated_at"]).not_to be_nil
415+
end
416+
end
417+
390418
describe "ignore options for LOB columns" do
391419
after(:each) do
392420
schema_define do

0 commit comments

Comments
 (0)