Module: DynamicMigrations::Postgres::Generator::Function
- Included in:
- DynamicMigrations::Postgres::Generator
- Defined in:
- lib/dynamic_migrations/postgres/generator/function.rb
Instance Method Summary collapse
- #create_function(function, code_comment = nil) ⇒ Object
- #drop_function(function, code_comment = nil) ⇒ Object
-
#remove_function_comment(function, code_comment = nil) ⇒ Object
remove the comment from a function.
-
#set_function_comment(function, code_comment = nil) ⇒ Object
add a comment to a function.
- #update_function(function, code_comment = nil) ⇒ Object
Instance Method Details
#create_function(function, code_comment = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dynamic_migrations/postgres/generator/function.rb', line 5 def create_function function, code_comment = nil = {} if function.description.nil? comment_sql = "" else comment_sql = <<~RUBY #{function.name}_comment = <<~COMMENT #{indent function.description || ""} COMMENT RUBY [:comment] = "#{function.name}_comment" end = .map { |k, v| "#{k}: #{v}" }.join(", ") = ( == "") ? "" : ", #{}" fn_sql = function.definition.strip # we only provide a table if the function has a single trigger and they # are in the same schema, otherwise we can't reliable handle dependencies # so the function will be created in the schema's migration function_table = nil if function.triggers.count == 1 && function.schema == function.triggers.first&.table&.schema function_table = function.triggers.first&.table end add_fragment schema: function.schema, table: function_table, migration_method: :create_function, object: function, code_comment: code_comment, migration: comment_sql + <<~RUBY create_function :#{function.name}#{} do <<~SQL #{indent fn_sql, 2} SQL end RUBY end |
#drop_function(function, code_comment = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dynamic_migrations/postgres/generator/function.rb', line 63 def drop_function function, code_comment = nil add_fragment schema: function.schema, table: function.triggers.first&.table, migration_method: :drop_function, object: function, code_comment: code_comment, migration: <<~RUBY drop_function :#{function.name} RUBY end |
#remove_function_comment(function, code_comment = nil) ⇒ Object
remove the comment from a function
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dynamic_migrations/postgres/generator/function.rb', line 89 def remove_function_comment function, code_comment = nil add_fragment schema: function.schema, table: function.triggers.first&.table, migration_method: :remove_function_comment, object: function, code_comment: code_comment, migration: <<~RUBY remove_function_comment :#{function.name} RUBY end |
#set_function_comment(function, code_comment = nil) ⇒ Object
add a comment to a function
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dynamic_migrations/postgres/generator/function.rb', line 75 def set_function_comment function, code_comment = nil add_fragment schema: function.schema, table: function.triggers.first&.table, migration_method: :set_function_comment, object: function, code_comment: code_comment, migration: <<~RUBY set_function_comment :#{function.name}, <<~COMMENT #{indent function.description || ""} COMMENT RUBY end |
#update_function(function, code_comment = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dynamic_migrations/postgres/generator/function.rb', line 46 def update_function function, code_comment = nil fn_sql = function.definition.strip add_fragment schema: function.schema, table: function.triggers.first&.table, migration_method: :update_function, object: function, code_comment: code_comment, migration: <<~RUBY update_function :#{function.name} do <<~SQL #{indent fn_sql, 2} SQL end RUBY end |