Skip to content

Commit 4ad3632

Browse files
authored
Merge pull request #43 from ghiculescu/do_not_remove_extensions
Add an option to not remove extensions
2 parents b3b7d10 + d361b9b commit 4ad3632

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ INSERT INTO "schema_migrations" (version) VALUES
8787
;
8888
```
8989

90+
By default the gem will remove [some extensions](https://github.com/ghiculescu/activerecord-clean-db-structure/blob/c9551391476a5e7a08ff314501af89baddcf669a/lib/activerecord-clean-db-structure/clean_dump.rb#L24) that typically aren't needed in structure dumps. You can choose to keep all, or just some, of those extensions:
91+
92+
```ruby
93+
Rails.application.configure do
94+
config.activerecord_clean_db_structure.keep_extensions = :all
95+
96+
# This does the same thing as :all. You can choose which optional extensions to keep.
97+
config.activerecord_clean_db_structure.keep_extensions = ["pg_stat_statements", "pg_buffercache"]
98+
end
99+
```
100+
90101
## Authors
91102

92103
* [Lukas Fittl](https://github.com/lfittl)

lib/activerecord-clean-db-structure/clean_dump.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ def run
2121
dump.gsub!(/^SET xmloption = content;\n/m, '') # 12
2222
dump.gsub!(/^SET default_table_access_method = heap;\n/m, '') # 12
2323

24-
# Remove pg_stat_statements extension (its not relevant to the code)
25-
dump.gsub!(/^CREATE EXTENSION IF NOT EXISTS pg_stat_statements.*/, '')
26-
dump.gsub!(/^-- Name: (EXTENSION )?pg_stat_statements;.*/, '')
27-
28-
# Remove pg_buffercache extension (its not relevant to the code)
29-
dump.gsub!(/^CREATE EXTENSION IF NOT EXISTS pg_buffercache.*/, '')
30-
dump.gsub!(/^-- Name: (EXTENSION )?pg_buffercache;.*/, '')
24+
extensions_to_remove = ["pg_stat_statements", "pg_buffercache"]
25+
if options[:keep_extensions] == :all
26+
extensions_to_remove = []
27+
elsif options[:keep_extensions]
28+
extensions_to_remove -= Array(options[:keep_extensions])
29+
end
30+
extensions_to_remove.each do |ext|
31+
dump.gsub!(/^CREATE EXTENSION IF NOT EXISTS #{ext}.*/, '')
32+
dump.gsub!(/^-- Name: (EXTENSION )?#{ext};.*/, '')
33+
end
3134

3235
# Remove comments on extensions, they create problems if the extension is owned by another user
3336
dump.gsub!(/^COMMENT ON EXTENSION .*/, '')

0 commit comments

Comments
 (0)