Commit f6774011 authored by Jacob Schatz's avatar Jacob Schatz Committed by Micaël Bergeron

Create list of files that are output.

parent ec533816
...@@ -31,11 +31,12 @@ module Pseudonymity ...@@ -31,11 +31,12 @@ module Pseudonymity
@csv_output = "" @csv_output = ""
parse_config parse_config
@schema = {} @schema = {}
@output_files = []
end end
def tables_to_csv def tables_to_csv
tables = config["tables"] tables = config["tables"]
@csv_output = config["output"]["csv"] @csv_output = config["output"]["csv"].chomp("\/")
if not File.directory?(@csv_output) if not File.directory?(@csv_output)
puts "No such directory #{@csv_output}" puts "No such directory #{@csv_output}"
return return
...@@ -45,13 +46,20 @@ module Pseudonymity ...@@ -45,13 +46,20 @@ module Pseudonymity
table_to_csv(k, v["whitelist"], v["pseudo"]) table_to_csv(k, v["whitelist"], v["pseudo"])
end end
schema_to_yml schema_to_yml
file_list_to_json
end end
def schema_to_yml def schema_to_yml
file_path = "#{@csv_output}/schema_#{Time.now.to_i}.yml" file_path = "#{@csv_output}/schema_#{Time.now.to_i}.yml"
@output_files << file_path
File.open(file_path, 'w') { |file| file.write(@schema.to_yaml) } File.open(file_path, 'w') { |file| file.write(@schema.to_yaml) }
end end
def file_list_to_json
file_path = "#{@csv_output}/file_list.json"
File.open(file_path, 'w') { |file| file.write(@output_files.to_json) }
end
def table_to_csv(table, whitelist_columns, pseudonymity_columns) def table_to_csv(table, whitelist_columns, pseudonymity_columns)
sql = "SELECT #{whitelist_columns.join(",")} FROM #{table};" sql = "SELECT #{whitelist_columns.join(",")} FROM #{table};"
type_sql = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '#{table}';" type_sql = "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = '#{table}';"
...@@ -86,6 +94,7 @@ module Pseudonymity ...@@ -86,6 +94,7 @@ module Pseudonymity
end end
end end
File.open(file_path, 'w') { |file| file.write(contents) } File.open(file_path, 'w') { |file| file.write(contents) }
@output_files << file_path
return file_path return file_path
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment