Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure to create temporal table column with correct array attribute #40

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading