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
eefea6d2
Commit
eefea6d2
authored
May 21, 2018
by
Jacob Schatz
Committed by
Micaël Bergeron
Jun 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix review
parent
43d0e5e4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
lib/pseudonymity/table.rb
lib/pseudonymity/table.rb
+21
-14
No files found.
lib/pseudonymity/table.rb
View file @
eefea6d2
...
@@ -38,12 +38,11 @@ module Pseudonymity
...
@@ -38,12 +38,11 @@ module Pseudonymity
def
tables_to_csv
def
tables_to_csv
tables
=
config
[
"tables"
]
tables
=
config
[
"tables"
]
@csv_output
=
config
[
"output"
][
"csv"
].
chomp
(
"
\g
/"
)
@csv_output
=
config
[
"output"
][
"csv"
]
if
not
File
.
directory?
(
@csv_output
)
if
!
File
.
directory?
(
@csv_output
)
puts
"No such directory
#{
@csv_output
}
"
raise
"No such directory
#{
@csv_output
}
"
return
end
end
tables
.
map
do
|
k
,
v
|
tables
.
each
do
|
k
,
v
|
@schema
[
k
]
=
{}
@schema
[
k
]
=
{}
table_to_csv
(
k
,
v
[
"whitelist"
],
v
[
"pseudo"
])
table_to_csv
(
k
,
v
[
"whitelist"
],
v
[
"pseudo"
])
end
end
...
@@ -55,7 +54,7 @@ module Pseudonymity
...
@@ -55,7 +54,7 @@ module Pseudonymity
file_timestamp
=
filename
||
"
#{
prefix
}
_
#{
Time
.
now
.
to_i
}
"
file_timestamp
=
filename
||
"
#{
prefix
}
_
#{
Time
.
now
.
to_i
}
"
file_timestamp
=
"
#{
file_timestamp
}
.
#{
ext
}
"
file_timestamp
=
"
#{
file_timestamp
}
.
#{
ext
}
"
@output_files
<<
file_timestamp
@output_files
<<
file_timestamp
"
#{
@csv_output
}
/
#{
file_timestamp
}
"
File
.
join
(
@csv_output
,
file_timestamp
)
end
end
def
schema_to_yml
def
schema_to_yml
...
@@ -70,9 +69,21 @@ module Pseudonymity
...
@@ -70,9 +69,21 @@ module Pseudonymity
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}';"
results
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
sql
)
results
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
sql
)
type_results
=
ActiveRecord
::
Base
.
connection
.
exec_query
(
type_sql
)
# type_results = ActiveRecord::Base.connection.exec_query(type_sql)
type_results
=
ActiveRecord
::
Base
.
connection
.
columns
(
table
)
type_results
=
type_results
.
select
do
|
c
|
@config
[
"tables"
][
table
][
"whitelist"
].
include?
(
c
.
name
)
end
type_results
=
type_results
.
map
do
|
c
|
data_type
=
c
.
sql_type
if
@config
[
"tables"
][
table
][
"pseudo"
].
include?
(
c
.
name
)
data_type
=
"character varying"
end
{
name:
c
.
name
,
data_type:
data_type
}
end
set_schema_column_types
(
table
,
type_results
)
set_schema_column_types
(
table
,
type_results
)
return
if
results
.
empty?
return
if
results
.
empty?
...
@@ -82,18 +93,14 @@ module Pseudonymity
...
@@ -82,18 +93,14 @@ module Pseudonymity
def
set_schema_column_types
(
table
,
type_results
)
def
set_schema_column_types
(
table
,
type_results
)
type_results
.
each
do
|
type_result
|
type_results
.
each
do
|
type_result
|
data_type
=
type_result
[
"data_type"
]
@schema
[
table
][
type_result
[
:name
]]
=
type_result
[
:data_type
]
if
@config
[
"tables"
][
table
][
"pseudo"
].
include?
(
type_result
[
"column_name"
])
data_type
=
"character varying"
end
@schema
[
table
][
type_result
[
"column_name"
]]
=
data_type
end
end
# hard coded because all mapping keys in GL are id
# hard coded because all mapping keys in GL are id
@schema
[
table
][
"gl_mapping_key"
]
=
"id"
@schema
[
table
][
"gl_mapping_key"
]
=
"id"
end
end
def
parse_config
def
parse_config
@config
=
YAML
.
load_file
(
'./lib/assets/pseudonymity_dump.yml'
)
@config
=
YAML
.
load_file
(
Rails
.
root
.
join
(
'lib/assets/pseudonymity_dump.yml'
)
)
end
end
def
write_to_csv_file
(
title
,
contents
)
def
write_to_csv_file
(
title
,
contents
)
...
...
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