Class: CommentMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/comment_migration.rb

Instance Method Summary collapse

Instance Method Details

#comments_downObject



26
27
28
# File 'lib/comment_migration.rb', line 26

def comments_down
  {}
end

#comments_upObject



4
5
6
# File 'lib/comment_migration.rb', line 4

def comments_up
  raise "Not implemented"
end

#downObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/comment_migration.rb', line 30

def down
  replace_nils(comments_up)
    .deep_merge(comments_down)
    .each do |table|
      table[1].each do |column|
        table_name = table[0]
        column_name = column[0]
        comment = column[1]

        if column_name == :_table
          DB.exec "COMMENT ON TABLE #{table_name} IS ?", comment
          puts "  COMMENT ON TABLE #{table_name}"
        else
          DB.exec "COMMENT ON COLUMN #{table_name}.#{column_name} IS ?", comment
          puts "  COMMENT ON COLUMN #{table_name}.#{column_name}"
        end
      end
    end
end

#upObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/comment_migration.rb', line 8

def up
  comments_up.each do |table|
    table[1].each do |column|
      table_name = table[0]
      column_name = column[0]
      comment = column[1]

      if column_name == :_table
        DB.exec "COMMENT ON TABLE #{table_name} IS ?", comment
        puts "  COMMENT ON TABLE #{table_name}"
      else
        DB.exec "COMMENT ON COLUMN #{table_name}.#{column_name} IS ?", comment
        puts "  COMMENT ON COLUMN #{table_name}.#{column_name}"
      end
    end
  end
end