Module: MigrationComments::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_column_with_migration_comments(table_name, column_name, type, options = {}) ⇒ Object
- #change_column_with_migration_comments(table_name, column_name, type, options = {}) ⇒ Object
- #comment_sql(comment_definition) ⇒ Object
- #comments_supported? ⇒ Boolean
- #create_table_with_migration_comments(table_name, options = {}) ⇒ Object
- #independent_comments? ⇒ Boolean
- #retrieve_column_comments(table_name, *column_names) ⇒ Object
- #retrieve_table_comment(table_name) ⇒ Object
-
#set_column_comment(table_name, column_name, comment_text) ⇒ Object
Set a comment on a column.
-
#set_table_comment(table_name, comment_text) ⇒ Object
Set a comment on a table.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 3 def self.included(base) base.class_eval do alias_method_chain :create_table, :migration_comments alias_method_chain :add_column, :migration_comments alias_method_chain :change_column, :migration_comments end end |
Instance Method Details
#add_column_with_migration_comments(table_name, column_name, type, options = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 54 def add_column_with_migration_comments(table_name, column_name, type, = {}) add_column_without_migration_comments(table_name, column_name, type, ) if [:comment] set_column_comment(table_name, column_name, [:comment]) end end |
#change_column_with_migration_comments(table_name, column_name, type, options = {}) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 61 def change_column_with_migration_comments(table_name, column_name, type, = {}) change_column_without_migration_comments(table_name, column_name, type, ) if .keys.include?(:comment) set_column_comment(table_name, column_name, [:comment]) end end |
#comment_sql(comment_definition) ⇒ Object
68 69 70 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 68 def comment_sql(comment_definition) "COMMENT ON #{comment_target(comment_definition)} IS #{escaped_comment(comment_definition.comment_text)}" end |
#comments_supported? ⇒ Boolean
11 12 13 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 11 def comments_supported? true end |
#create_table_with_migration_comments(table_name, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 40 def create_table_with_migration_comments(table_name, = {}) local_table_definition = nil create_table_without_migration_comments(table_name, ) do |td| local_table_definition = td local_table_definition.base = self local_table_definition.comment [:comment] if .has_key?(:comment) yield td if block_given? end comments = local_table_definition.collect_comments(table_name) comments.each do |comment_definition| execute comment_definition.to_sql end end |
#independent_comments? ⇒ Boolean
15 16 17 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 15 def independent_comments? true end |
#retrieve_column_comments(table_name, *column_names) ⇒ Object
34 35 36 37 38 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 34 def retrieve_column_comments(table_name, *column_names) result = select_rows(column_comment_sql(table_name, *column_names)) return {} if result.nil? return result.inject({}){|m, row| m[row[0].to_sym] = row[1]; m} end |
#retrieve_table_comment(table_name) ⇒ Object
29 30 31 32 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 29 def retrieve_table_comment(table_name) result = select_rows(table_comment_sql(table_name)) result[0].nil? ? nil : result[0][0] end |
#set_column_comment(table_name, column_name, comment_text) ⇒ Object
Set a comment on a column
25 26 27 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 25 def set_column_comment(table_name, column_name, comment_text) execute CommentDefinition.new(self, table_name, column_name, comment_text).to_sql end |
#set_table_comment(table_name, comment_text) ⇒ Object
Set a comment on a table
20 21 22 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 20 def set_table_comment(table_name, comment_text) execute CommentDefinition.new(self, table_name, nil, comment_text).to_sql end |