Cross Reference: 20160614065105_add_association_from_commit_to_user.rb
xref
: /
ontohub
/
db
/
migrate
/
20160614065105_add_association_from_commit_to_user.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
20160614065105_add_association_from_commit_to_user.rb revision 81da36894af70bbb8d8e24b004026ad4c5c1bc99
1516
N/A
class
AddAssociationFromCommitToUser
<
MigrationWithData
581
N/A
def
up
581
N/A
rename_column
:
commits
, :
author
, :
author_name
581
N/A
rename_column
:
commits
, :
committer
, :
committer_name
581
N/A
581
N/A
add_column
:
commits
, :
author_email
, :
string
581
N/A
add_column
:
commits
, :
committer_email
, :
string
581
N/A
581
N/A
add_column
:
commits
, :
pusher_name
, :
string
581
N/A
581
N/A
# We emphasize "null: true" because there may be no user
581
N/A
add_column
:
commits
, :
author_id
, :
integer
,
null
:
true
581
N/A
add_column
:
commits
, :
committer_id
, :
integer
,
null
:
true
581
N/A
add_column
:
commits
, :
pusher_id
, :
integer
,
null
:
true
581
N/A
581
N/A
add_index
:
commits
, :
author_id
581
N/A
add_index
:
commits
, :
committer_id
581
N/A
add_index
:
commits
, :
pusher_id
581
N/A
581
N/A
up_data
581
N/A
581
N/A
remove_column
:
ontology_versions
, :
user_id
926
N/A
end
3158
N/A
926
N/A
def
down
581
N/A
add_column
:
ontology_versions
, :
user_id
, :
integer
581
N/A
581
N/A
down_data
581
N/A
1715
N/A
remove_index
:
commits
, :
author_id
581
N/A
remove_index
:
commits
, :
committer_id
1895
N/A
remove_index
:
commits
, :
pusher_id
581
N/A
1895
N/A
remove_column
:
commits
, :
author_id
581
N/A
remove_column
:
commits
, :
committer_id
2055
N/A
remove_column
:
commits
, :
pusher_id
581
N/A
1715
N/A
remove_column
:
commits
, :
pusher_name
581
N/A
581
N/A
remove_column
:
commits
, :
author_email
792
N/A
remove_column
:
commits
, :
committer_email
581
N/A
1895
N/A
rename_column
:
commits
, :
author_name
581
N/A
rename_column
:
commits
, :
committer_name
581
N/A
end
581
N/A
581
N/A
protected
581
N/A
581
N/A
def
up_data
581
N/A
up_ontology_version
581
N/A
up_split_name_and_email
611
N/A
end
611
N/A
611
N/A
def
down_data
611
N/A
Commit.find
_each
do
|
commit
|
581
N/A
attrs
=
select_attributes
(
commit
,
581
N/A
:
pusher_id
, :
commit_oid
,
581
N/A
:
author_name
, :
author_email
,
581
N/A
:
committer_name
, :
committer_email
)
581
N/A
down_ontology_version
(
attrs
)
581
N/A
down_commit
(
attrs
)
581
N/A
end
581
N/A
end
2026
N/A
2097
N/A
def
up_ontology_version
2026
N/A
OntologyVersion.find
_each
do
|
ontology_version
|
2026
N/A
attrs
=
select_attributes
(
ontology_version
, :
user_id
, :
commit_oid
)
2026
N/A
user_name
=
select_attributes_class
(
User
,
attrs
[:
id
], :
name
)
[:
name
]
2026
N/A
commit
=
Commit.where
(
commit_oid
:
attrs
[:
commit_oid
])
.
first
2026
N/A
update_columns
(
commit
,
2026
N/A
pusher_id
:
attrs
[:
user_id
],
pusher_name
:
user_name
)
2026
N/A
end
2026
N/A
end
2026
N/A
2026
N/A
def
up_split_name_and_email
2026
N/A
Commit.find
_each
do
|
commit
|
2026
N/A
attrs
=
select_attributes
(
commit
, :
author_name
, :
committer_name
)
2026
N/A
author_info
=
2026
N/A
attrs
[:
author_name
].
match
(/\A
(?<
name
>.*)
<
(?<
email
>[^\>]*)
>\z/)
2026
N/A
committer_info
=
2026
N/A
attrs
[:
committer_name
].
match
(/\A
(?<
name
>.*)
<
(?<
email
>[^\>]*)
>\z/)
2026
N/A
update_columns
(
commit
, **
data
(
author_info
,
committer_info
)
)
3158
N/A
end
3158
N/A
end
2026
N/A
2055
N/A
def
data
(
author_info
,
committer_info
)
2055
N/A
data
= {
author_name
:
author_info
[:
name
],
2055
N/A
author_email
:
author_info
[:
email
],
2055
N/A
committer_name
:
committer_info
[:
name
],
2055
N/A
committer_email
:
committer_info
[:
email
]}
2055
N/A
data
[:
author_id
] =
2258
N/A
User.where
(
email
:
data
[:
author_email
])
.
select
(:
id
)
.first.try
(:
id
)
709
N/A
data
[:
committer_id
] =
1895
N/A
User.where
(
email
:
data
[:
committer_email
])
.
select
(:
id
)
.first.try
(:
id
)
1895
N/A
data
709
N/A
end
709
N/A
1895
N/A
def
down_ontology_version
(
attrs
)
1895
N/A
ontology_version
=
709
N/A
OntologyVersion.where
(
commit_oid
:
attrs
[:
commit_oid
])
.
first
1895
N/A
update_columns
(
ontology_version
,
user_id
:
attrs
[:
pusher_id
])
1895
N/A
end
709
N/A
709
N/A
def
down_commit
(
attrs
)
1895
N/A
author_info
=
"#{attrs[:author_name]} <#{attrs[:author_email]}>"
581
N/A
committer_info
=
"#{attrs[:committer_name]} <#{attrs[:committer_email]}>"
581
N/A
update_columns
(
commit
,
author_name
:
author_info
,
committer_name
:
committer_info
)
end
end