class PGTrunk::Operations::Enums::CreateEnum
@private
Public Instance Methods
invert()
click to toggle source
# File lib/pg_trunk/operations/enums/create_enum.rb, line 54 def invert DropEnum.new(**to_h) end
to_sql(_version)
click to toggle source
# File lib/pg_trunk/operations/enums/create_enum.rb, line 50 def to_sql(_version) [create_enum, *create_comment, register_enum].join(" ") end
Private Instance Methods
create_comment()
click to toggle source
# File lib/pg_trunk/operations/enums/create_enum.rb, line 68 def create_comment return if comment.blank? "COMMENT ON TYPE #{name.to_sql} IS $comment$#{comment}$comment$;" end
create_enum()
click to toggle source
# File lib/pg_trunk/operations/enums/create_enum.rb, line 60 def create_enum <<~SQL.squish CREATE TYPE #{name.to_sql} AS ENUM ( #{values.map { |value| "'#{value}'" }.join(', ')} ); SQL end
register_enum()
click to toggle source
# File lib/pg_trunk/operations/enums/create_enum.rb, line 74 def register_enum <<~SQL.squish INSERT INTO pg_trunk (oid, classid) SELECT oid, 'pg_type'::regclass FROM pg_type WHERE typname = #{name.quoted} AND typnamespace = #{name.namespace} AND typtype = 'e' ON CONFLICT DO NOTHING; SQL end