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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
47a539df
Commit
47a539df
authored
Mar 28, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use raw SQL instead of Rails models in migrations where appropriate
Closes #14694.
parent
d73e1288
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
34 deletions
+54
-34
db/migrate/20130218141258_convert_closed_to_state_in_issue.rb
...igrate/20130218141258_convert_closed_to_state_in_issue.rb
+11
-7
db/migrate/20130218141327_convert_closed_to_state_in_merge_request.rb
...0130218141327_convert_closed_to_state_in_merge_request.rb
+13
-9
db/migrate/20130218141344_convert_closed_to_state_in_milestone.rb
...te/20130218141344_convert_closed_to_state_in_milestone.rb
+11
-7
db/migrate/20130220125544_convert_merge_status_in_merge_request.rb
...e/20130220125544_convert_merge_status_in_merge_request.rb
+12
-10
db/migrate/20130419190306_allow_merges_for_forks.rb
db/migrate/20130419190306_allow_merges_for_forks.rb
+7
-1
No files found.
db/migrate/20130218141258_convert_closed_to_state_in_issue.rb
View file @
47a539df
class
ConvertClosedToStateInIssue
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
def
up
Issue
.
transaction
do
Issue
.
where
(
closed:
true
).
update_all
(
state: :closed
)
Issue
.
where
(
closed:
false
).
update_all
(
state: :opened
)
end
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
"
execute
"UPDATE
#{
table_name
}
SET state = 'opened' WHERE closed =
#{
false_value
}
"
end
def
down
Issue
.
transaction
do
Issue
.
where
(
state: :closed
).
update_all
(
closed:
true
)
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
WHERE state = 'closed'"
end
private
def
table_name
Issue
.
table_name
end
end
db/migrate/20130218141327_convert_closed_to_state_in_merge_request.rb
View file @
47a539df
class
ConvertClosedToStateInMergeRequest
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
def
up
MergeRequest
.
transaction
do
MergeRequest
.
where
(
closed:
true
,
merged:
true
).
update_all
(
state: :merged
)
MergeRequest
.
where
(
closed:
true
,
merged:
false
).
update_all
(
state: :closed
)
MergeRequest
.
where
(
closed:
false
).
update_all
(
state: :opened
)
end
execute
"UPDATE
#{
table_name
}
SET state = 'merged' WHERE closed =
#{
true_value
}
AND merged =
#{
true_value
}
"
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
AND merged =
#{
false_value
}
"
execute
"UPDATE
#{
table_name
}
SET state = 'opened' WHERE closed =
#{
false_value
}
"
end
def
down
MergeRequest
.
transaction
do
MergeRequest
.
where
(
state: :closed
).
update_all
(
closed:
true
)
MergeRequest
.
where
(
state: :merged
).
update_all
(
closed:
true
,
merged:
true
)
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
WHERE state = 'closed'"
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
, merged =
#{
true_value
}
WHERE state = 'merged'"
end
private
def
table_name
MergeRequest
.
table_name
end
end
db/migrate/20130218141344_convert_closed_to_state_in_milestone.rb
View file @
47a539df
class
ConvertClosedToStateInMilestone
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
def
up
Milestone
.
transaction
do
Milestone
.
where
(
closed:
true
).
update_all
(
state: :closed
)
Milestone
.
where
(
closed:
false
).
update_all
(
state: :active
)
end
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
"
execute
"UPDATE
#{
table_name
}
SET state = 'active' WHERE closed =
#{
false_value
}
"
end
def
down
Milestone
.
transaction
do
Milestone
.
where
(
state: :closed
).
update_all
(
closed:
true
)
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
WHERE state = 'cloesd'"
end
private
def
table_name
Milestone
.
table_name
end
end
db/migrate/20130220125544_convert_merge_status_in_merge_request.rb
View file @
47a539df
class
ConvertMergeStatusInMergeRequest
<
ActiveRecord
::
Migration
def
up
MergeRequest
.
transaction
do
MergeRequest
.
where
(
merge_status:
1
).
update_all
(
"new_merge_status = 'unchecked'"
)
MergeRequest
.
where
(
merge_status:
2
).
update_all
(
"new_merge_status = 'can_be_merged'"
)
MergeRequest
.
where
(
merge_status:
3
).
update_all
(
"new_merge_status = 'cannot_be_merged'"
)
end
execute
"UPDATE
#{
table_name
}
SET new_merge_status = 'unchecked' WHERE merge_status = 1"
execute
"UPDATE
#{
table_name
}
SET new_merge_status = 'can_be_merged' WHERE merge_status = 2"
execute
"UPDATE
#{
table_name
}
SET new_merge_status = 'cannot_be_merged' WHERE merge_status = 3"
end
def
down
MergeRequest
.
transaction
do
MergeRequest
.
where
(
new_merge_status: :unchecked
).
update_all
(
"merge_status = 1"
)
MergeRequest
.
where
(
new_merge_status: :can_be_merged
).
update_all
(
"merge_status = 2"
)
MergeRequest
.
where
(
new_merge_status: :cannot_be_merged
).
update_all
(
"merge_status = 3"
)
execute
"UPDATE
#{
table_name
}
SET merge_status = 1 WHERE new_merge_status = 'unchecked'"
execute
"UPDATE
#{
table_name
}
SET merge_status = 2 WHERE new_merge_status = 'can_be_merged'"
execute
"UPDATE
#{
table_name
}
SET merge_status = 3 WHERE new_merge_status = 'cannot_be_merged'"
end
private
def
table_name
MergeRequest
.
table_name
end
end
db/migrate/20130419190306_allow_merges_for_forks.rb
View file @
47a539df
class
AllowMergesForForks
<
ActiveRecord
::
Migration
def
self
.
up
add_column
:merge_requests
,
:target_project_id
,
:integer
,
:null
=>
true
MergeRequest
.
update_all
(
"target_project_id = project_id"
)
execute
"UPDATE
#{
table_name
}
SET target_project_id = project_id"
change_column
:merge_requests
,
:target_project_id
,
:integer
,
:null
=>
false
rename_column
:merge_requests
,
:project_id
,
:source_project_id
end
...
...
@@ -10,4 +10,10 @@ class AllowMergesForForks < ActiveRecord::Migration
remove_column
:merge_requests
,
:target_project_id
rename_column
:merge_requests
,
:source_project_id
,
:project_id
end
private
def
table_name
MergeRequest
.
table_name
end
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