Skip to content

Instantly share code, notes, and snippets.

View dsalahutdinov's full-sized avatar

Dmitry Salahutdinov dsalahutdinov

View GitHub Profile
module PostgresEnum
extend ActiveSupport::Concern
class_methods do
def postgres_enum_for(column, type_name:)
enums = ActiveRecord::Base.connection.exec_query <<-SQL
SELECT pg_enum.enumlabel AS enumlabel
FROM pg_type
JOIN pg_enum
ON pg_enum.enumtypid = pg_type.oid