Skip to content

Commit

Permalink
Merge pull request #40 from doits/add_array_option
Browse files Browse the repository at this point in the history
make sure to create temporal table column with correct array attribute
  • Loading branch information
evman182 committed May 3, 2024
2 parents d502ba4 + 3826f5c commit b23ea57
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/temporal_tables/temporal_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def add_temporal_table(table_name, **options) # rubocop:disable Metrics/MethodLe
t.datetime :eff_to, null: false, limit: 6, default: TemporalTables::END_OF_TIME

columns(table_name).each do |c|
column_options = { limit: c.limit }
column_options = { limit: c.limit, array: c.try(:array) }.compact
column_type = c.type
if column_type == :enum
enum_type = c.sql_type_metadata.sql_type
Expand Down
16 changes: 16 additions & 0 deletions spec/basic_history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@
end
end

if TemporalTables::DatabaseAdapter.adapter_name != 'mysql'
describe 'when changing a creature with an array column' do
let!(:cat) { Cat.create name: 'Mr. Mittens', nicknames: %w[Blacky Kitty] }

before do
cat.update nicknames: %w[Cutie Mizie]
end

it 'show nicknames correctly' do
expect(cat.nicknames).to eq(%w[Cutie Mizie])
expect(cat.history.last.nicknames).to eq(%w[Cutie Mizie])
expect(cat.history.first.nicknames).to eq(%w[Blacky Kitty])
end
end
end

# The following tests PKs with names other than "id"
describe 'when spawning and renaming a creature with PK not named id' do
let!(:dog) { Dog.create name: 'Fido' }
Expand Down
1 change: 1 addition & 0 deletions spec/internal/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
t.string :name
t.string :color
t.column :breed, (postgres ? :cat_breed : :string), null: false, default: 'ragdoll'
t.string :nicknames, array: true if postgres
end

create_table :cat_lives, id: (postgres ? :uuid : :integer), temporal: true do |t|
Expand Down

0 comments on commit b23ea57

Please sign in to comment.