Skip to content

Commit

Permalink
Merge pull request #517 from NickLaMuro/handle_custom_metrics_table_b…
Browse files Browse the repository at this point in the history
…ackups_in_dev

[SchemaDumper] Handle edge cases for metric tables
  • Loading branch information
Fryguy authored Sep 29, 2020
2 parents 19d4e84 + b21043b commit 57d10b7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/manageiq/schema/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def table(table, stream)
def add_id_column_comment(table, stream)
pk = @connection.primary_key(table)
pkcol = @connection.columns(table).detect { |c| c.name == pk }
comment = pkcol.comment
comment = pkcol.try(:comment)

return unless comment

Expand Down Expand Up @@ -87,8 +87,8 @@ def triggers(stream)

def track_miq_metric_table_inheritance(table)
return unless table.match?(METRIC_ROLLUP_TABLE_REGEXP)
return unless (inherit_from = determine_table_parent(table))

inherit_from = determine_table_parent(table)
inherited_metrics_tables << [table, inherit_from]
end

Expand All @@ -97,12 +97,16 @@ def inherited_metrics_tables
end

def determine_table_parent(table_name)
@connection.execute(<<-SQL).first["parent_table"]
table = @connection.execute(<<-SQL)
SELECT pg_class.relname AS parent_table
FROM pg_catalog.pg_inherits
JOIN pg_class ON pg_class.oid = pg_inherits.inhparent
WHERE inhrelid = '#{table_name}'::regclass
SQL

return if table.first.nil?

table.first["parent_table"]
end

def column_spec_for_primary_key(column)
Expand Down

0 comments on commit 57d10b7

Please sign in to comment.