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
Boxiang Sun
gitlab-ce
Commits
c41df676
Commit
c41df676
authored
Apr 10, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removes redundant code from database.rb
parent
069c54a7
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
75 additions
and
20 deletions
+75
-20
changelogs/unreleased/29056-backport-ee-cleanup-database-file.yml
...gs/unreleased/29056-backport-ee-cleanup-database-file.yml
+4
-0
db/migrate/20130218141258_convert_closed_to_state_in_issue.rb
...igrate/20130218141258_convert_closed_to_state_in_issue.rb
+1
-1
db/migrate/20130218141327_convert_closed_to_state_in_merge_request.rb
...0130218141327_convert_closed_to_state_in_merge_request.rb
+1
-1
db/migrate/20130218141344_convert_closed_to_state_in_milestone.rb
...te/20130218141344_convert_closed_to_state_in_milestone.rb
+1
-1
db/migrate/20130315124931_user_color_scheme.rb
db/migrate/20130315124931_user_color_scheme.rb
+1
-1
db/migrate/20131112220935_add_visibility_level_to_projects.rb
...igrate/20131112220935_add_visibility_level_to_projects.rb
+1
-1
db/migrate/20140313092127_migrate_already_imported_projects.rb
...grate/20140313092127_migrate_already_imported_projects.rb
+1
-1
db/migrate/20141007100818_add_visibility_level_to_snippet.rb
db/migrate/20141007100818_add_visibility_level_to_snippet.rb
+1
-1
db/migrate/20151209144329_migrate_ci_web_hooks.rb
db/migrate/20151209144329_migrate_ci_web_hooks.rb
+1
-1
db/migrate/20151209145909_migrate_ci_emails.rb
db/migrate/20151209145909_migrate_ci_emails.rb
+1
-1
db/migrate/20151210125232_migrate_ci_slack_service.rb
db/migrate/20151210125232_migrate_ci_slack_service.rb
+1
-1
db/migrate/20151210125927_migrate_ci_hip_chat_service.rb
db/migrate/20151210125927_migrate_ci_hip_chat_service.rb
+1
-1
db/post_migrate/20170301205640_migrate_build_events_to_pipeline_events.rb
...20170301205640_migrate_build_events_to_pipeline_events.rb
+0
-1
lib/gitlab/database.rb
lib/gitlab/database.rb
+4
-4
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+8
-0
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+44
-0
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+4
-4
No files found.
changelogs/unreleased/29056-backport-ee-cleanup-database-file.yml
0 → 100644
View file @
c41df676
---
title
:
Turns
true
value and
false
value database methods from instance to class methods
merge_request
:
10583
author
:
db/migrate/20130218141258_convert_closed_to_state_in_issue.rb
View file @
c41df676
# rubocop:disable all
class
ConvertClosedToStateInIssue
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
"
...
...
db/migrate/20130218141327_convert_closed_to_state_in_merge_request.rb
View file @
c41df676
# rubocop:disable all
class
ConvertClosedToStateInMergeRequest
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
execute
"UPDATE
#{
table_name
}
SET state = 'merged' WHERE closed =
#{
true_value
}
AND merged =
#{
true_value
}
"
...
...
db/migrate/20130218141344_convert_closed_to_state_in_milestone.rb
View file @
c41df676
# rubocop:disable all
class
ConvertClosedToStateInMilestone
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
execute
"UPDATE
#{
table_name
}
SET state = 'closed' WHERE closed =
#{
true_value
}
"
...
...
db/migrate/20130315124931_user_color_scheme.rb
View file @
c41df676
# rubocop:disable all
class
UserColorScheme
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
add_column
:users
,
:color_scheme_id
,
:integer
,
null:
false
,
default:
1
...
...
db/migrate/20131112220935_add_visibility_level_to_projects.rb
View file @
c41df676
# rubocop:disable all
class
AddVisibilityLevelToProjects
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
self
.
up
add_column
:projects
,
:visibility_level
,
:integer
,
:default
=>
0
,
:null
=>
false
...
...
db/migrate/20140313092127_migrate_already_imported_projects.rb
View file @
c41df676
# rubocop:disable all
class
MigrateAlreadyImportedProjects
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
execute
(
"UPDATE projects SET import_status = 'finished' WHERE imported =
#{
true_value
}
"
)
...
...
db/migrate/20141007100818_add_visibility_level_to_snippet.rb
View file @
c41df676
# rubocop:disable all
class
AddVisibilityLevelToSnippet
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
add_column
:snippets
,
:visibility_level
,
:integer
,
:default
=>
0
,
:null
=>
false
...
...
db/migrate/20151209144329_migrate_ci_web_hooks.rb
View file @
c41df676
# rubocop:disable all
class
MigrateCiWebHooks
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
execute
(
...
...
db/migrate/20151209145909_migrate_ci_emails.rb
View file @
c41df676
# rubocop:disable all
class
MigrateCiEmails
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
# This inserts a new service: BuildsEmailService
...
...
db/migrate/20151210125232_migrate_ci_slack_service.rb
View file @
c41df676
# rubocop:disable all
class
MigrateCiSlackService
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
properties_query
=
'SELECT properties FROM ci_services '
\
...
...
db/migrate/20151210125927_migrate_ci_hip_chat_service.rb
View file @
c41df676
# rubocop:disable all
class
MigrateCiHipChatService
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
include
Gitlab
::
Database
::
MigrationHelpers
def
up
# From properties strip `hipchat_` key
...
...
db/post_migrate/20170301205640_migrate_build_events_to_pipeline_events.rb
View file @
c41df676
class
MigrateBuildEventsToPipelineEvents
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
DOWNTIME
=
false
...
...
lib/gitlab/database.rb
View file @
c41df676
...
...
@@ -57,16 +57,16 @@ module Gitlab
postgresql?
?
"RANDOM()"
:
"RAND()"
end
def
true_value
if
Gitlab
::
Database
.
postgresql?
def
self
.
true_value
if
postgresql?
"'t'"
else
1
end
end
def
false_value
if
Gitlab
::
Database
.
postgresql?
def
self
.
false_value
if
postgresql?
"'f'"
else
0
...
...
lib/gitlab/database/migration_helpers.rb
View file @
c41df676
...
...
@@ -114,6 +114,14 @@ module Gitlab
execute
(
'SET statement_timeout TO 0'
)
if
Database
.
postgresql?
end
def
true_value
Database
.
true_value
end
def
false_value
Database
.
false_value
end
# Updates the value of a column in batches.
#
# This method updates the table in batches of 5% of the total row count.
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
c41df676
...
...
@@ -175,6 +175,50 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
end
end
describe
'#true_value'
do
context
'using PostgreSQL'
do
before
do
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
end
it
'returns the appropriate value'
do
expect
(
model
.
true_value
).
to
eq
(
"'t'"
)
end
end
context
'using MySQL'
do
before
do
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
end
it
'returns the appropriate value'
do
expect
(
model
.
true_value
).
to
eq
(
1
)
end
end
end
describe
'#false_value'
do
context
'using PostgreSQL'
do
before
do
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
end
it
'returns the appropriate value'
do
expect
(
model
.
false_value
).
to
eq
(
"'f'"
)
end
end
context
'using MySQL'
do
before
do
expect
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
end
it
'returns the appropriate value'
do
expect
(
model
.
false_value
).
to
eq
(
0
)
end
end
end
describe
'#update_column_in_batches'
do
before
do
create_list
(
:empty_project
,
5
)
...
...
spec/lib/gitlab/database_spec.rb
View file @
c41df676
...
...
@@ -150,13 +150,13 @@ describe Gitlab::Database, lib: true do
it
'returns correct value for PostgreSQL'
do
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
MigrationTest
.
new
.
true_value
).
to
eq
"'t'"
expect
(
described_class
.
true_value
).
to
eq
"'t'"
end
it
'returns correct value for MySQL'
do
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
MigrationTest
.
new
.
true_value
).
to
eq
1
expect
(
described_class
.
true_value
).
to
eq
1
end
end
...
...
@@ -164,13 +164,13 @@ describe Gitlab::Database, lib: true do
it
'returns correct value for PostgreSQL'
do
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
MigrationTest
.
new
.
false_value
).
to
eq
"'f'"
expect
(
described_class
.
false_value
).
to
eq
"'f'"
end
it
'returns correct value for MySQL'
do
expect
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
MigrationTest
.
new
.
false_value
).
to
eq
0
expect
(
described_class
.
false_value
).
to
eq
0
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