Module: MigrationComments::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb
Instance Method Summary collapse
- #add_column(table_name, column_name, type, options = {}) ⇒ Object
- #change_column(table_name, column_name, type, options = {}) ⇒ Object
- #change_column_comment(table_name, column_name, comment) ⇒ Object
- #comment_sql(comment_definition) ⇒ Object
- #comments_supported? ⇒ Boolean
- #create_table(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.
Instance Method Details
#add_column(table_name, column_name, type, options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 51 def add_column(table_name, column_name, type, = {}) super(table_name, column_name, type, ) if [:comment] set_column_comment(table_name, column_name, [:comment]) end end |
#change_column(table_name, column_name, type, options = {}) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 58 def change_column(table_name, column_name, type, = {}) super(table_name, column_name, type, ) if .keys.include?(:comment) set_column_comment(table_name, column_name, [:comment]) end end |
#change_column_comment(table_name, column_name, comment) ⇒ Object
23 24 25 26 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 23 def change_column_comment(table_name, column_name, comment) comment_text = comment.respond_to?(:comment_text) ? comment.comment_text : comment super(table_name, column_name, comment_text) end |
#comment_sql(comment_definition) ⇒ Object
65 66 67 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 65 def comment_sql(comment_definition) "COMMENT ON #{comment_target(comment_definition)} IS #{escaped_comment(comment_definition.comment_text)}" end |
#comments_supported? ⇒ Boolean
4 5 6 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 4 def comments_supported? true end |
#create_table(table_name, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 38 def create_table(table_name, = {}) local_table_definition = nil super(table_name, ) do |td| local_table_definition = td 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_sql(comment_definition) end end |
#independent_comments? ⇒ Boolean
8 9 10 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 8 def independent_comments? true end |
#retrieve_column_comments(table_name, *column_names) ⇒ Object
33 34 35 36 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 33 def retrieve_column_comments(table_name, *column_names) result = select_rows(column_comment_sql(table_name, *column_names)) Hash[result.map{|row| [row[0].to_sym, row[1].presence]}] end |
#retrieve_table_comment(table_name) ⇒ Object
29 30 31 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 29 def retrieve_table_comment(table_name) select_value(table_comment_sql(table_name)).presence end |
#set_column_comment(table_name, column_name, comment_text) ⇒ Object
Set a comment on a column
18 19 20 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 18 def set_column_comment(table_name, column_name, comment_text) execute comment_sql(CommentDefinition.new(table_name, column_name, comment_text)) end |
#set_table_comment(table_name, comment_text) ⇒ Object
Set a comment on a table
13 14 15 |
# File 'lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb', line 13 def set_table_comment(table_name, comment_text) execute comment_sql(CommentDefinition.new(table_name, nil, comment_text)) end |