Skip to content

Commit

Permalink
Use sql kind in enum table definition in migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
syabruk committed Jul 30, 2024
1 parent 5ed019c commit 41696e6
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ def enum(*args, **options)
raise ArgumentError, "Column #{args.first}: option 'value' must be Hash, got: #{options[:value].class}"
end

options[:value] = options[:value].each_with_object([]) { |(k, v), arr| arr.push("'#{k}' = #{v}") }.join(', ')

if options[:limit]
kind = :enum8 if options[:limit] == 1
kind = :enum16 if options[:limit] == 2
end

args.each { |name| column(name, kind, **options.except(:limit)) }
sql_value = options[:value].each_with_object([]) { |(k, v), arr| arr.push("'#{k}' = #{v}") }.join(', ')
sql_kind = "#{kind.to_s.capitalize}(#{sql_value})"

args.each { |name| column(name, sql_kind, **options.except(:limit, :value)) }
end

def map(*args, **options)
Expand Down

0 comments on commit 41696e6

Please sign in to comment.