Skip to content

Commit

Permalink
Adding support for citext[] arrays. Fixes #970
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Sep 13, 2023
1 parent 17ccff0 commit aa44539
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions db/migrations/20230912145332_add_array_citext_to_buckets.cr
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions spec/avram/queryable_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions spec/support/models/bucket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aa44539

Please sign in to comment.