Module: PgPower::SchemaDumper::CommentMethods

Included in:
PgPower::SchemaDumper
Defined in:
lib/pg_power/schema_dumper/comment_methods.rb

Overview

Extends ActiveRecord::SchemaDumper class to dump comments on tables and columns.

Instance Method Summary collapse

Instance Method Details

#tables_with_comments(stream) ⇒ Object

Hook ActiveRecord::SchemaDumper#table method to dump comments on table and columns.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pg_power/schema_dumper/comment_methods.rb', line 5

def tables_with_comments(stream)
  tables_without_comments(stream)

  table_names = @connection.tables.sort
  table_names += get_non_public_schema_table_names.sort

  # Dump table and column comments
  table_names.each do |table_name|
    dump_comments(table_name, stream)
  end

  # Now dump index comments
  unless (index_comments = @connection.index_comments).empty?
    index_comments.each do |row|
      schema_name = row[0]
      index_name = schema_name == 'public' ? "'#{row[1]}'" : "'#{schema_name}.#{row[1]}'"
      comment = format_comment(row[2])
      stream.puts "  set_index_comment #{index_name}, '#{comment}'"
    end
    stream.puts
  end
end