Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
17ddbcbb
Commit
17ddbcbb
authored
May 08, 2018
by
Jacob Schatz
Committed by
Micaël Bergeron
Jun 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds schema file to the output files
parent
833480da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
lib/pseudonymity/table.rb
lib/pseudonymity/table.rb
+18
-1
No files found.
lib/pseudonymity/table.rb
View file @
17ddbcbb
...
...
@@ -30,6 +30,7 @@ module Pseudonymity
@config
=
{}
@csv_output
=
""
parse_config
@schema
=
{}
end
def
tables_to_csv
...
...
@@ -40,19 +41,35 @@ module Pseudonymity
return
end
tables
.
map
do
|
k
,
v
|
@schema
[
k
]
=
{}
table_to_csv
(
k
,
v
[
"whitelist"
],
v
[
"pseudo"
])
end
schema_to_yml
end
def
schema_to_yml
file_path
=
"
#{
@csv_output
}
/schema_
#{
Time
.
now
.
to_i
}
.yml"
File
.
open
(
file_path
,
'w'
)
{
|
file
|
file
.
write
(
@schema
.
to_yaml
)
}
end
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
}
';"
results
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
sql
)
type_results
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
type_sql
)
set_schema_column_types
(
table
,
type_results
)
return
if
results
.
empty?
anon
=
Anon
.
new
(
pseudonymity_columns
)
write_to_csv_file
(
table
,
anon
.
anonymize
(
results
))
end
def
set_schema_column_types
(
table
,
type_results
)
type_results
.
each
do
|
type_result
|
@schema
[
table
][
type_result
[
"column_name"
]]
=
type_result
[
"data_type"
]
end
end
def
parse_config
@config
=
YAML
.
load_file
(
'./lib/assets/pseudonymity_dump.yml'
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment