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
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
Hide 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
class
ConvertClosedToStateInIssue
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
def
up
def
up
Issue
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
"
Issue
.
where
(
closed:
true
).
update_all
(
state: :closed
)
execute
"UPDATE
#{
table_name
}
SET state = 'opened' WHERE closed =
#{
false_value
}
"
Issue
.
where
(
closed:
false
).
update_all
(
state: :opened
)
end
end
end
def
down
def
down
Issue
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
WHERE state = 'closed'"
Issue
.
where
(
state: :closed
).
update_all
(
closed:
true
)
end
end
private
def
table_name
Issue
.
table_name
end
end
end
end
db/migrate/20130218141327_convert_closed_to_state_in_merge_request.rb
View file @
47a539df
class
ConvertClosedToStateInMergeRequest
<
ActiveRecord
::
Migration
class
ConvertClosedToStateInMergeRequest
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
def
up
def
up
MergeRequest
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET state = 'merged' WHERE closed =
#{
true_value
}
AND merged =
#{
true_value
}
"
MergeRequest
.
where
(
closed:
true
,
merged:
true
).
update_all
(
state: :merged
)
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
AND merged =
#{
false_value
}
"
MergeRequest
.
where
(
closed:
true
,
merged:
false
).
update_all
(
state: :closed
)
execute
"UPDATE
#{
table_name
}
SET state = 'opened' WHERE closed =
#{
false_value
}
"
MergeRequest
.
where
(
closed:
false
).
update_all
(
state: :opened
)
end
end
end
def
down
def
down
MergeRequest
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
WHERE state = 'closed'"
MergeRequest
.
where
(
state: :closed
).
update_all
(
closed:
true
)
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
, merged =
#{
true_value
}
WHERE state = 'merged'"
MergeRequest
.
where
(
state: :merged
).
update_all
(
closed:
true
,
merged:
true
)
end
end
private
def
table_name
MergeRequest
.
table_name
end
end
end
end
db/migrate/20130218141344_convert_closed_to_state_in_milestone.rb
View file @
47a539df
class
ConvertClosedToStateInMilestone
<
ActiveRecord
::
Migration
class
ConvertClosedToStateInMilestone
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
def
up
def
up
Milestone
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
"
Milestone
.
where
(
closed:
true
).
update_all
(
state: :closed
)
execute
"UPDATE
#{
table_name
}
SET state = 'active' WHERE closed =
#{
false_value
}
"
Milestone
.
where
(
closed:
false
).
update_all
(
state: :active
)
end
end
end
def
down
def
down
Milestone
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET closed =
#{
true_value
}
WHERE state = 'cloesd'"
Milestone
.
where
(
state: :closed
).
update_all
(
closed:
true
)
end
end
private
def
table_name
Milestone
.
table_name
end
end
end
end
db/migrate/20130220125544_convert_merge_status_in_merge_request.rb
View file @
47a539df
class
ConvertMergeStatusInMergeRequest
<
ActiveRecord
::
Migration
class
ConvertMergeStatusInMergeRequest
<
ActiveRecord
::
Migration
def
up
def
up
MergeRequest
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET new_merge_status = 'unchecked' WHERE merge_status = 1"
MergeRequest
.
where
(
merge_status:
1
).
update_all
(
"new_merge_status = 'unchecked'"
)
execute
"UPDATE
#{
table_name
}
SET new_merge_status = 'can_be_merged' WHERE merge_status = 2"
MergeRequest
.
where
(
merge_status:
2
).
update_all
(
"new_merge_status = 'can_be_merged'"
)
execute
"UPDATE
#{
table_name
}
SET new_merge_status = 'cannot_be_merged' WHERE merge_status = 3"
MergeRequest
.
where
(
merge_status:
3
).
update_all
(
"new_merge_status = 'cannot_be_merged'"
)
end
end
end
def
down
def
down
MergeRequest
.
transaction
do
execute
"UPDATE
#{
table_name
}
SET merge_status = 1 WHERE new_merge_status = 'unchecked'"
MergeRequest
.
where
(
new_merge_status: :unchecked
).
update_all
(
"merge_status = 1"
)
execute
"UPDATE
#{
table_name
}
SET merge_status = 2 WHERE new_merge_status = 'can_be_merged'"
MergeRequest
.
where
(
new_merge_status: :can_be_merged
).
update_all
(
"merge_status = 2"
)
execute
"UPDATE
#{
table_name
}
SET merge_status = 3 WHERE new_merge_status = 'cannot_be_merged'"
MergeRequest
.
where
(
new_merge_status: :cannot_be_merged
).
update_all
(
"merge_status = 3"
)
end
end
private
def
table_name
MergeRequest
.
table_name
end
end
end
end
db/migrate/20130419190306_allow_merges_for_forks.rb
View file @
47a539df
class
AllowMergesForForks
<
ActiveRecord
::
Migration
class
AllowMergesForForks
<
ActiveRecord
::
Migration
def
self
.
up
def
self
.
up
add_column
:merge_requests
,
:target_project_id
,
:integer
,
:null
=>
true
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
change_column
:merge_requests
,
:target_project_id
,
:integer
,
:null
=>
false
rename_column
:merge_requests
,
:project_id
,
:source_project_id
rename_column
:merge_requests
,
:project_id
,
:source_project_id
end
end
...
@@ -10,4 +10,10 @@ class AllowMergesForForks < ActiveRecord::Migration
...
@@ -10,4 +10,10 @@ class AllowMergesForForks < ActiveRecord::Migration
remove_column
:merge_requests
,
:target_project_id
remove_column
:merge_requests
,
:target_project_id
rename_column
:merge_requests
,
:source_project_id
,
:project_id
rename_column
:merge_requests
,
:source_project_id
,
:project_id
end
end
private
def
table_name
MergeRequest
.
table_name
end
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