lib/ar/enum/adapter.rb in ar-enum-0.2.2 vs lib/ar/enum/adapter.rb in ar-enum-0.2.3
- old
+ new
@@ -28,19 +28,25 @@
typname
SQL
end
def create_enum(name, values)
+ return if enum_exists?(name)
+
values = values.map do |value|
quote(value.to_s)
end
sql = <<-SQL
CREATE TYPE #{name}
AS ENUM (#{values.join(', ')})
SQL
execute(sql)
+ end
+
+ def enum_exists?(name)
+ enum_types.any? {|type| type["name"] == name.to_s }
end
def add_enum_label(name, value, options = {})
sql = "ALTER TYPE #{name} ADD VALUE #{quote(value.to_s)}"