From aa445390bb8cd9b42475b04bcdd1bda96c488baf Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Tue, 12 Sep 2023 17:32:45 -0700 Subject: [PATCH] Adding support for citext[] arrays. Fixes #970 --- .../20230912145332_add_array_citext_to_buckets.cr | 13 +++++++++++++ spec/avram/queryable_spec.cr | 8 ++++++++ spec/support/models/bucket.cr | 3 +++ 3 files changed, 24 insertions(+) create mode 100644 db/migrations/20230912145332_add_array_citext_to_buckets.cr diff --git a/db/migrations/20230912145332_add_array_citext_to_buckets.cr b/db/migrations/20230912145332_add_array_citext_to_buckets.cr new file mode 100644 index 000000000..ee5d1664c --- /dev/null +++ b/db/migrations/20230912145332_add_array_citext_to_buckets.cr @@ -0,0 +1,13 @@ +class AddArrayCitextToBuckets::V20230912145332 < Avram::Migrator::Migration::V1 + def migrate + alter table_for(Bucket) do + add tags : Array(String), default: [] of String, case_sensitive: false + end + end + + def rollback + alter table_for(Bucket) do + remove :tags + end + end +end diff --git a/spec/avram/queryable_spec.cr b/spec/avram/queryable_spec.cr index e2e278344..81e09370d 100644 --- a/spec/avram/queryable_spec.cr +++ b/spec/avram/queryable_spec.cr @@ -1203,6 +1203,14 @@ describe Avram::Queryable do query.select_count.should eq(1) query.first.id.should eq(bucket2.id) end + + it "queries with citext strings" do + BucketFactory.create &.tags(["ONE", "two", "tHrEe"]) + + BucketQuery.new.tags.includes("one").select_count.should eq(1) + BucketQuery.new.tags.includes("tWo").select_count.should eq(1) + BucketQuery.new.tags.includes("THRee").select_count.should eq(1) + end end end diff --git a/spec/support/models/bucket.cr b/spec/support/models/bucket.cr index 480c4d659..1cd39f802 100644 --- a/spec/support/models/bucket.cr +++ b/spec/support/models/bucket.cr @@ -8,5 +8,8 @@ class Bucket < BaseModel column names : Array(String) = [] of String column floaty_numbers : Array(Float64) = [] of Float64 column oody_things : Array(UUID) = [] of UUID + + # These are citext strings + column tags : Array(String) = [] of String end end