Skip to content

Add config option to ignore_inherited_tables #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions lib/activerecord-clean-db-structure/clean_dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,23 @@ def run
dump.gsub!(/^-- .*_id_seq; Type: SEQUENCE.*/, '')
dump.gsub!(/^-- Name: (\w+\s+)?\w+_pkey; Type: CONSTRAINT$/, '')
end

# Remove inherited tables
inherited_tables_regexp = /-- Name: ([\w_\.]+); Type: TABLE\n\n[^;]+?INHERITS \([\w_\.]+\);/m
inherited_tables = dump.scan(inherited_tables_regexp).map(&:first)
dump.gsub!(inherited_tables_regexp, '')
inherited_tables.each do |inherited_table|
dump.gsub!(/ALTER TABLE ONLY ([\w_]+\.)?#{inherited_table}[^;]+;/, '')

index_regexp = /CREATE INDEX ([\w_]+) ON ([\w_]+\.)?#{inherited_table}[^;]+;/m
dump.scan(index_regexp).map(&:first).each do |inherited_table_index|
dump.gsub!("-- Name: #{inherited_table_index}; Type: INDEX", '')

unless options[:ignore_inherited_tables] == true
# Remove inherited tables
inherited_tables_regexp = /-- Name: ([\w_\.]+); Type: TABLE\n\n[^;]+?INHERITS \([\w_\.]+\);/m
inherited_tables = dump.scan(inherited_tables_regexp).map(&:first)
dump.gsub!(inherited_tables_regexp, '')
inherited_tables.each do |inherited_table|
dump.gsub!(/ALTER TABLE ONLY ([\w_]+\.)?#{inherited_table}[^;]+;/, '')

index_regexp = /CREATE INDEX ([\w_]+) ON ([\w_]+\.)?#{inherited_table}[^;]+;/m
dump.scan(index_regexp).map(&:first).each do |inherited_table_index|
dump.gsub!("-- Name: #{inherited_table_index}; Type: INDEX", '')
end
dump.gsub!(index_regexp, '')
end
dump.gsub!(index_regexp, '')
end

# Remove partitioned tables
partitioned_tables = []

Expand Down