Module: DynamicMigrations::ActiveRecord::Migrators::Enum
- Included in:
- DynamicMigrations::ActiveRecord::Migrators
- Defined in:
- lib/dynamic_migrations/active_record/migrators/enum.rb
Instance Method Summary collapse
-
#add_enum_values(enum_name, values) ⇒ Object
add vaues to a given enum.
-
#create_enum(enum_name, values) ⇒ Object
create a postgres enum.
-
#drop_enum(enum_name) ⇒ Object
remove a enum from the schema.
-
#remove_enum_comment(enum_name) ⇒ Object
remove the comment from a enum.
-
#set_enum_comment(enum_name, comment) ⇒ Object
add a comment to a enum.
Instance Method Details
#add_enum_values(enum_name, values) ⇒ Object
add vaues to a given enum
14 15 16 17 18 19 |
# File 'lib/dynamic_migrations/active_record/migrators/enum.rb', line 14 def add_enum_values enum_name, values sqls = values.map do |value| "ALTER TYPE #{schema_name}.#{enum_name} ADD ATTRIBUTE '#{value}';" end execute sqls.join("\n") end |
#create_enum(enum_name, values) ⇒ Object
create a postgres enum
6 7 8 9 10 11 |
# File 'lib/dynamic_migrations/active_record/migrators/enum.rb', line 6 def create_enum enum_name, values # schema_name was not provided to this method, it comes from the migration class execute " CREATE TYPE \#{schema_name}.\#{enum_name} as ENUM ('\#{values.join(\"','\")}');\n SQL\nend\n" |
#drop_enum(enum_name) ⇒ Object
remove a enum from the schema
22 23 24 25 26 |
# File 'lib/dynamic_migrations/active_record/migrators/enum.rb', line 22 def drop_enum enum_name execute " DROP TYPE \#{schema_name}.\#{enum_name};\n SQL\nend\n" |
#remove_enum_comment(enum_name) ⇒ Object
remove the comment from a enum
36 37 38 39 40 |
# File 'lib/dynamic_migrations/active_record/migrators/enum.rb', line 36 def remove_enum_comment enum_name execute " COMMENT ON TYPE \#{schema_name}.\#{enum_name} IS null;\n SQL\nend\n" |
#set_enum_comment(enum_name, comment) ⇒ Object
add a comment to a enum
29 30 31 32 33 |
# File 'lib/dynamic_migrations/active_record/migrators/enum.rb', line 29 def set_enum_comment enum_name, comment execute " COMMENT ON TYPE \#{schema_name}.\#{enum_name} IS \#{quote comment};\n SQL\nend\n" |