Last active
January 27, 2023 13:43
-
-
Save criess/974ceb29e893f7a6f0a192ec923bf2e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# - all user* | |
# - all contract* | |
# - all discounts | |
# - all credit_memos | |
# - all product* | |
# - all subscriptions | |
# - all invoice* | |
# - all agent* | |
# - without any agent_result* | |
# - all social_media_trackers | |
# - all reader* | |
# - all account_manager_records | |
# - all payment_methods | |
# - all countries | |
# - without any reader*_log | |
# - reader_archive* | |
# - reader_results | |
# - reader_categor* | |
# | |
# first positional parameter passed is file of psql dumped schema | |
# script searches for "CREATE TABLE xxxx" lines | |
# rules are defined as local variables (_positive|_negative) | |
# output are tablenames evaluated against positive & negative rules … | |
rules_positive = [ | |
'user.*', | |
'contract.*', | |
'discounts', | |
'credit_memos', | |
'product.*', | |
'features', | |
'subscriptions', | |
'invoice.*', | |
'agent.*', | |
'social_media_trackers', | |
'reader.*', | |
'account_manager_records', | |
'payment_methods', | |
'countries' | |
] | |
rules_negative = [ | |
'agent_result.*', | |
'reader.*_log', | |
'reader_archive.*', | |
'reader_results', | |
'reader_categor.*' | |
] | |
File.read(ARGV[0]).each_line do |i| | |
next unless i.match?(/CREATE TABLE public\./) | |
fq_table = i.scan(/public\.[^ ]+/)[0] | |
table = fq_table.split('.')[1] | |
if rules_positive.any? { |r| table.match?(/^#{r}$/) } && rules_negative.all? { |r| !table.match?(/^#{r}$/) } | |
puts fq_table | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby contract_info_table_name_extractor.rb schema.sql |\ | |
awk '{print "--table=" $0}' |\ | |
xargs pg_dump -a -h db.host.tld -U db_user 2>pg_error.log |\ | |
gzip -9 > dumped_tables.sql.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment