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
62929b36
Commit
62929b36
authored
Jul 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
4ef91e42
f7641d84
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
94 additions
and
319 deletions
+94
-319
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+0
-1
app/finders/members_finder.rb
app/finders/members_finder.rb
+11
-30
app/models/merge_request.rb
app/models/merge_request.rb
+1
-8
app/models/milestone.rb
app/models/milestone.rb
+4
-23
app/models/redirect_route.rb
app/models/redirect_route.rb
+1
-5
app/services/cohorts_service.rb
app/services/cohorts_service.rb
+1
-5
app/services/projects/base_move_relations_service.rb
app/services/projects/base_move_relations_service.rb
+0
-12
app/services/projects/fetch_statistics_increment_service.rb
app/services/projects/fetch_statistics_increment_service.rb
+1
-6
app/services/projects/move_deploy_keys_projects_service.rb
app/services/projects/move_deploy_keys_projects_service.rb
+1
-2
app/services/projects/move_lfs_objects_projects_service.rb
app/services/projects/move_lfs_objects_projects_service.rb
+1
-2
app/services/projects/move_notification_settings_service.rb
app/services/projects/move_notification_settings_service.rb
+1
-2
app/services/projects/move_project_authorizations_service.rb
app/services/projects/move_project_authorizations_service.rb
+1
-2
app/services/projects/move_project_group_links_service.rb
app/services/projects/move_project_group_links_service.rb
+1
-2
app/services/projects/move_project_members_service.rb
app/services/projects/move_project_members_service.rb
+1
-1
app/workers/background_migration_worker.rb
app/workers/background_migration_worker.rb
+0
-2
lib/gitlab/background_migration/migrate_stage_index.rb
lib/gitlab/background_migration/migrate_stage_index.rb
+15
-27
lib/gitlab/background_migration/prepare_untracked_uploads.rb
lib/gitlab/background_migration/prepare_untracked_uploads.rb
+1
-7
lib/gitlab/background_migration/remove_restricted_todos.rb
lib/gitlab/background_migration/remove_restricted_todos.rb
+2
-15
lib/gitlab/ci/charts.rb
lib/gitlab/ci/charts.rb
+4
-10
lib/gitlab/contributions_calendar.rb
lib/gitlab/contributions_calendar.rb
+1
-5
lib/gitlab/database.rb
lib/gitlab/database.rb
+5
-4
lib/gitlab/database/grant.rb
lib/gitlab/database/grant.rb
+14
-36
lib/gitlab/database/median.rb
lib/gitlab/database/median.rb
+0
-2
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+0
-2
lib/gitlab/database/sha_attribute.rb
lib/gitlab/database/sha_attribute.rb
+3
-8
lib/gitlab/health_checks/db_check.rb
lib/gitlab/health_checks/db_check.rb
+1
-5
lib/gitlab/sherlock/query.rb
lib/gitlab/sherlock/query.rb
+1
-6
lib/tasks/gitlab/setup.rake
lib/tasks/gitlab/setup.rake
+0
-2
spec/features/admin/dashboard_spec.rb
spec/features/admin/dashboard_spec.rb
+2
-4
spec/finders/issues_finder_spec.rb
spec/finders/issues_finder_spec.rb
+0
-13
spec/lib/gitlab/database/sha_attribute_spec.rb
spec/lib/gitlab/database/sha_attribute_spec.rb
+1
-5
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+18
-60
spec/models/project_feature_spec.rb
spec/models/project_feature_spec.rb
+1
-5
No files found.
app/finders/issuable_finder.rb
View file @
62929b36
...
@@ -320,7 +320,6 @@ class IssuableFinder
...
@@ -320,7 +320,6 @@ class IssuableFinder
def
use_cte_for_search?
def
use_cte_for_search?
strong_memoize
(
:use_cte_for_search
)
do
strong_memoize
(
:use_cte_for_search
)
do
next
false
unless
search
next
false
unless
search
next
false
unless
Gitlab
::
Database
.
postgresql?
# Only simple unsorted & simple sorts can use CTE
# Only simple unsorted & simple sorts can use CTE
next
false
if
params
[
:sort
].
present?
&&
!
params
[
:sort
].
in?
(
klass
.
simple_sorts
.
keys
)
next
false
if
params
[
:sort
].
present?
&&
!
params
[
:sort
].
in?
(
klass
.
simple_sorts
.
keys
)
...
...
app/finders/members_finder.rb
View file @
62929b36
...
@@ -59,35 +59,16 @@ class MembersFinder
...
@@ -59,35 +59,16 @@ class MembersFinder
def
distinct_on
(
union
)
def
distinct_on
(
union
)
# We're interested in a list of members without duplicates by user_id.
# We're interested in a list of members without duplicates by user_id.
# We prefer project members over group members, project members should go first.
# We prefer project members over group members, project members should go first.
if
Gitlab
::
Database
.
postgresql?
<<~
SQL
<<~
SQL
SELECT DISTINCT ON (user_id, invite_email) member_union.*
SELECT DISTINCT ON (user_id, invite_email) member_union.*
FROM (
#{
union
.
to_sql
}
) AS member_union
FROM (
#{
union
.
to_sql
}
) AS member_union
ORDER BY user_id,
ORDER BY user_id,
invite_email,
invite_email,
CASE
CASE
WHEN type = 'ProjectMember' THEN 1
WHEN type = 'ProjectMember' THEN 1
WHEN type = 'GroupMember' THEN 2
WHEN type = 'GroupMember' THEN 2
ELSE 3
ELSE 3
END
END
SQL
SQL
else
# Older versions of MySQL do not support window functions (and DISTINCT ON is postgres-specific).
<<~
SQL
SELECT t1.*
FROM (
#{
union
.
to_sql
}
) AS t1
JOIN (
SELECT
COALESCE(user_id, -1) AS user_id,
COALESCE(invite_email, 'NULL') AS invite_email,
MIN(CASE WHEN type = 'ProjectMember' THEN 1 WHEN type = 'GroupMember' THEN 2 ELSE 3 END) AS type_number
FROM
(
#{
union
.
to_sql
}
) AS t3
GROUP BY COALESCE(user_id, -1), COALESCE(invite_email, 'NULL')
) AS t2 ON COALESCE(t1.user_id, -1) = t2.user_id
AND COALESCE(t1.invite_email, 'NULL') = t2.invite_email
AND CASE WHEN t1.type = 'ProjectMember' THEN 1 WHEN t1.type = 'GroupMember' THEN 2 ELSE 3 END = t2.type_number
SQL
end
end
end
end
end
app/models/merge_request.rb
View file @
62929b36
...
@@ -1251,15 +1251,8 @@ class MergeRequest < ApplicationRecord
...
@@ -1251,15 +1251,8 @@ class MergeRequest < ApplicationRecord
end
end
def
all_commits
def
all_commits
# MySQL doesn't support LIMIT in a subquery.
diffs_relation
=
if
Gitlab
::
Database
.
postgresql?
merge_request_diffs
.
recent
else
merge_request_diffs
end
MergeRequestDiffCommit
MergeRequestDiffCommit
.
where
(
merge_request_diff:
diffs_relation
)
.
where
(
merge_request_diff:
merge_request_diffs
.
recent
)
.
limit
(
10_000
)
.
limit
(
10_000
)
end
end
...
...
app/models/milestone.rb
View file @
62929b36
...
@@ -151,29 +151,10 @@ class Milestone < ApplicationRecord
...
@@ -151,29 +151,10 @@ class Milestone < ApplicationRecord
end
end
def
self
.
upcoming_ids
(
projects
,
groups
)
def
self
.
upcoming_ids
(
projects
,
groups
)
rel
=
unscoped
unscoped
.
for_projects_and_groups
(
projects
,
groups
)
.
for_projects_and_groups
(
projects
,
groups
)
.
active
.
where
(
'milestones.due_date > CURRENT_DATE'
)
.
active
.
where
(
'milestones.due_date > CURRENT_DATE'
)
.
order
(
:project_id
,
:group_id
,
:due_date
).
select
(
'DISTINCT ON (project_id, group_id) id'
)
if
Gitlab
::
Database
.
postgresql?
rel
.
order
(
:project_id
,
:group_id
,
:due_date
).
select
(
'DISTINCT ON (project_id, group_id) id'
)
else
# We need to use MySQL's NULL-safe comparison operator `<=>` here
# because one of `project_id` or `group_id` is always NULL
join_clause
=
<<~
HEREDOC
LEFT OUTER JOIN milestones earlier_milestones
ON milestones.project_id <=> earlier_milestones.project_id
AND milestones.group_id <=> earlier_milestones.group_id
AND milestones.due_date > earlier_milestones.due_date
AND earlier_milestones.due_date > CURRENT_DATE
AND earlier_milestones.state = 'active'
HEREDOC
rel
.
joins
(
join_clause
)
.
where
(
'earlier_milestones.id IS NULL'
)
.
select
(
:id
)
end
end
end
def
participants
def
participants
...
...
app/models/redirect_route.rb
View file @
62929b36
...
@@ -11,11 +11,7 @@ class RedirectRoute < ApplicationRecord
...
@@ -11,11 +11,7 @@ class RedirectRoute < ApplicationRecord
uniqueness:
{
case_sensitive:
false
}
uniqueness:
{
case_sensitive:
false
}
scope
:matching_path_and_descendants
,
->
(
path
)
do
scope
:matching_path_and_descendants
,
->
(
path
)
do
wheres
=
if
Gitlab
::
Database
.
postgresql?
wheres
=
'LOWER(redirect_routes.path) = LOWER(?) OR LOWER(redirect_routes.path) LIKE LOWER(?)'
'LOWER(redirect_routes.path) = LOWER(?) OR LOWER(redirect_routes.path) LIKE LOWER(?)'
else
'redirect_routes.path = ? OR redirect_routes.path LIKE ?'
end
where
(
wheres
,
path
,
"
#{
sanitize_sql_like
(
path
)
}
/%"
)
where
(
wheres
,
path
,
"
#{
sanitize_sql_like
(
path
)
}
/%"
)
end
end
...
...
app/services/cohorts_service.rb
View file @
62929b36
...
@@ -95,10 +95,6 @@ class CohortsService
...
@@ -95,10 +95,6 @@ class CohortsService
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
column_to_date
(
column
)
def
column_to_date
(
column
)
if
Gitlab
::
Database
.
postgresql?
"CAST(DATE_TRUNC('month',
#{
column
}
) AS date)"
"CAST(DATE_TRUNC('month',
#{
column
}
) AS date)"
else
"STR_TO_DATE(DATE_FORMAT(
#{
column
}
, '%Y-%m-01'), '%Y-%m-%d')"
end
end
end
end
end
app/services/projects/base_move_relations_service.rb
View file @
62929b36
...
@@ -10,17 +10,5 @@ module Projects
...
@@ -10,17 +10,5 @@ module Projects
true
true
end
end
private
# rubocop: disable CodeReuse/ActiveRecord
def
prepare_relation
(
relation
,
id_param
=
:id
)
if
Gitlab
::
Database
.
postgresql?
relation
else
relation
.
model
.
where
(
"
#{
id_param
}
"
:
relation
.
pluck
(
id_param
))
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end
app/services/projects/fetch_statistics_increment_service.rb
View file @
62929b36
...
@@ -12,14 +12,9 @@ module Projects
...
@@ -12,14 +12,9 @@ module Projects
increment_fetch_count_sql
=
<<~
SQL
increment_fetch_count_sql
=
<<~
SQL
INSERT INTO
#{
table_name
}
(project_id, date, fetch_count)
INSERT INTO
#{
table_name
}
(project_id, date, fetch_count)
VALUES (
#{
project
.
id
}
, '
#{
Date
.
today
}
', 1)
VALUES (
#{
project
.
id
}
, '
#{
Date
.
today
}
', 1)
ON CONFLICT (project_id, date) DO UPDATE SET fetch_count =
#{
table_name
}
.fetch_count + 1
SQL
SQL
increment_fetch_count_sql
+=
if
Gitlab
::
Database
.
postgresql?
"ON CONFLICT (project_id, date) DO UPDATE SET fetch_count =
#{
table_name
}
.fetch_count + 1"
else
"ON DUPLICATE KEY UPDATE fetch_count =
#{
table_name
}
.fetch_count + 1"
end
ActiveRecord
::
Base
.
connection
.
execute
(
increment_fetch_count_sql
)
ActiveRecord
::
Base
.
connection
.
execute
(
increment_fetch_count_sql
)
end
end
...
...
app/services/projects/move_deploy_keys_projects_service.rb
View file @
62929b36
...
@@ -16,8 +16,7 @@ module Projects
...
@@ -16,8 +16,7 @@ module Projects
private
private
def
move_deploy_keys_projects
def
move_deploy_keys_projects
prepare_relation
(
non_existent_deploy_keys_projects
)
non_existent_deploy_keys_projects
.
update_all
(
project_id:
@project
.
id
)
.
update_all
(
project_id:
@project
.
id
)
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
...
...
app/services/projects/move_lfs_objects_projects_service.rb
View file @
62929b36
...
@@ -16,8 +16,7 @@ module Projects
...
@@ -16,8 +16,7 @@ module Projects
private
private
def
move_lfs_objects_projects
def
move_lfs_objects_projects
prepare_relation
(
non_existent_lfs_objects_projects
)
non_existent_lfs_objects_projects
.
update_all
(
project_id:
@project
.
lfs_storage_project
.
id
)
.
update_all
(
project_id:
@project
.
lfs_storage_project
.
id
)
end
end
def
remove_remaining_lfs_objects_project
def
remove_remaining_lfs_objects_project
...
...
app/services/projects/move_notification_settings_service.rb
View file @
62929b36
...
@@ -16,8 +16,7 @@ module Projects
...
@@ -16,8 +16,7 @@ module Projects
private
private
def
move_notification_settings
def
move_notification_settings
prepare_relation
(
non_existent_notifications
)
non_existent_notifications
.
update_all
(
source_id:
@project
.
id
)
.
update_all
(
source_id:
@project
.
id
)
end
end
# Remove remaining notification settings from source_project
# Remove remaining notification settings from source_project
...
...
app/services/projects/move_project_authorizations_service.rb
View file @
62929b36
...
@@ -21,8 +21,7 @@ module Projects
...
@@ -21,8 +21,7 @@ module Projects
private
private
def
move_project_authorizations
def
move_project_authorizations
prepare_relation
(
non_existent_authorization
,
:user_id
)
non_existent_authorization
.
update_all
(
project_id:
@project
.
id
)
.
update_all
(
project_id:
@project
.
id
)
end
end
def
remove_remaining_authorizations
def
remove_remaining_authorizations
...
...
app/services/projects/move_project_group_links_service.rb
View file @
62929b36
...
@@ -20,8 +20,7 @@ module Projects
...
@@ -20,8 +20,7 @@ module Projects
private
private
def
move_group_links
def
move_group_links
prepare_relation
(
non_existent_group_links
)
non_existent_group_links
.
update_all
(
project_id:
@project
.
id
)
.
update_all
(
project_id:
@project
.
id
)
end
end
# Remove remaining project group links from source_project
# Remove remaining project group links from source_project
...
...
app/services/projects/move_project_members_service.rb
View file @
62929b36
...
@@ -20,7 +20,7 @@ module Projects
...
@@ -20,7 +20,7 @@ module Projects
private
private
def
move_project_members
def
move_project_members
prepare_relation
(
non_existent_members
)
.
update_all
(
source_id:
@project
.
id
)
non_existent_members
.
update_all
(
source_id:
@project
.
id
)
end
end
def
remove_remaining_members
def
remove_remaining_members
...
...
app/workers/background_migration_worker.rb
View file @
62929b36
...
@@ -76,8 +76,6 @@ class BackgroundMigrationWorker
...
@@ -76,8 +76,6 @@ class BackgroundMigrationWorker
# class_name - The name of the background migration that we might want to
# class_name - The name of the background migration that we might want to
# run.
# run.
def
healthy_database?
def
healthy_database?
return
true
unless
Gitlab
::
Database
.
postgresql?
!
Postgresql
::
ReplicationSlot
.
lag_too_great?
!
Postgresql
::
ReplicationSlot
.
lag_too_great?
end
end
...
...
lib/gitlab/background_migration/migrate_stage_index.rb
View file @
62929b36
...
@@ -13,34 +13,22 @@ module Gitlab
...
@@ -13,34 +13,22 @@ module Gitlab
private
private
def
migrate_stage_index_sql
(
start_id
,
stop_id
)
def
migrate_stage_index_sql
(
start_id
,
stop_id
)
if
Gitlab
::
Database
.
postgresql?
<<~
SQL
<<~
SQL
WITH freqs AS (
WITH freqs AS (
SELECT stage_id, stage_idx, COUNT(*) AS freq FROM ci_builds
SELECT stage_id, stage_idx, COUNT(*) AS freq FROM ci_builds
WHERE stage_id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
WHERE stage_id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
AND stage_idx IS NOT NULL
AND stage_idx IS NOT NULL
GROUP BY stage_id, stage_idx
GROUP BY stage_id, stage_idx
), indexes AS (
), indexes AS (
SELECT DISTINCT stage_id, first_value(stage_idx)
SELECT DISTINCT stage_id, first_value(stage_idx)
OVER (PARTITION BY stage_id ORDER BY freq DESC) AS index
OVER (PARTITION BY stage_id ORDER BY freq DESC) AS index
FROM freqs
FROM freqs
)
)
UPDATE ci_stages SET position = indexes.index
UPDATE ci_stages SET position = indexes.index
FROM indexes WHERE indexes.stage_id = ci_stages.id
FROM indexes WHERE indexes.stage_id = ci_stages.id
AND ci_stages.position IS NULL;
AND ci_stages.position IS NULL;
SQL
SQL
else
<<~
SQL
UPDATE ci_stages
SET position =
(SELECT stage_idx FROM ci_builds
WHERE ci_builds.stage_id = ci_stages.id
GROUP BY ci_builds.stage_idx ORDER BY COUNT(*) DESC LIMIT 1)
WHERE ci_stages.id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
AND ci_stages.position IS NULL
SQL
end
end
end
end
end
end
end
...
...
lib/gitlab/background_migration/prepare_untracked_uploads.rb
View file @
62929b36
...
@@ -147,19 +147,13 @@ module Gitlab
...
@@ -147,19 +147,13 @@ module Gitlab
"
#{
UntrackedFile
.
table_name
}
(path) VALUES
#{
values
}
"
"
#{
UntrackedFile
.
table_name
}
(path) VALUES
#{
values
}
"
end
end
def
postgresql?
strong_memoize
(
:postgresql
)
do
Gitlab
::
Database
.
postgresql?
end
end
def
can_bulk_insert_and_ignore_duplicates?
def
can_bulk_insert_and_ignore_duplicates?
!
postgresql_pre_9_5?
!
postgresql_pre_9_5?
end
end
def
postgresql_pre_9_5?
def
postgresql_pre_9_5?
strong_memoize
(
:postgresql_pre_9_5
)
do
strong_memoize
(
:postgresql_pre_9_5
)
do
postgresql?
&&
Gitlab
::
Database
.
version
.
to_f
<
9.5
Gitlab
::
Database
.
version
.
to_f
<
9.5
end
end
end
end
...
...
lib/gitlab/background_migration/remove_restricted_todos.rb
View file @
62929b36
...
@@ -50,14 +50,7 @@ module Gitlab
...
@@ -50,14 +50,7 @@ module Gitlab
private
private
def
remove_non_members_todos
(
project_id
)
def
remove_non_members_todos
(
project_id
)
if
Gitlab
::
Database
.
postgresql?
batch_remove_todos_cte
(
project_id
)
batch_remove_todos_cte
(
project_id
)
else
unauthorized_project_todos
(
project_id
)
.
each_batch
(
of:
5000
)
do
|
batch
|
batch
.
delete_all
end
end
end
end
def
remove_confidential_issue_todos
(
project_id
)
def
remove_confidential_issue_todos
(
project_id
)
...
@@ -90,13 +83,7 @@ module Gitlab
...
@@ -90,13 +83,7 @@ module Gitlab
next
if
target_types
.
empty?
next
if
target_types
.
empty?
if
Gitlab
::
Database
.
postgresql?
batch_remove_todos_cte
(
project_id
,
target_types
)
batch_remove_todos_cte
(
project_id
,
target_types
)
else
unauthorized_project_todos
(
project_id
)
.
where
(
target_type:
target_types
)
.
delete_all
end
end
end
end
end
...
...
lib/gitlab/ci/charts.rb
View file @
62929b36
...
@@ -21,16 +21,10 @@ module Gitlab
...
@@ -21,16 +21,10 @@ module Gitlab
module
MonthlyInterval
module
MonthlyInterval
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
grouped_count
(
query
)
def
grouped_count
(
query
)
if
Gitlab
::
Database
.
postgresql?
query
query
.
group
(
"to_char(
#{
::
Ci
::
Pipeline
.
table_name
}
.created_at, '01 Month YYYY')"
)
.
group
(
"to_char(
#{
::
Ci
::
Pipeline
.
table_name
}
.created_at, '01 Month YYYY')"
)
.
count
(
:created_at
)
.
count
(
:created_at
)
.
transform_keys
(
&
:squish
)
.
transform_keys
(
&
:squish
)
else
query
.
group
(
"DATE_FORMAT(
#{
::
Ci
::
Pipeline
.
table_name
}
.created_at, '01 %M %Y')"
)
.
count
(
:created_at
)
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
...
lib/gitlab/contributions_calendar.rb
View file @
62929b36
...
@@ -84,11 +84,7 @@ module Gitlab
...
@@ -84,11 +84,7 @@ module Gitlab
.
and
(
t
[
:created_at
].
lteq
(
Date
.
current
.
end_of_day
))
.
and
(
t
[
:created_at
].
lteq
(
Date
.
current
.
end_of_day
))
.
and
(
t
[
:author_id
].
eq
(
contributor
.
id
))
.
and
(
t
[
:author_id
].
eq
(
contributor
.
id
))
date_interval
=
if
Gitlab
::
Database
.
postgresql?
date_interval
=
"INTERVAL '
#{
Time
.
zone
.
now
.
utc_offset
}
seconds'"
"INTERVAL '
#{
Time
.
zone
.
now
.
utc_offset
}
seconds'"
else
"INTERVAL
#{
Time
.
zone
.
now
.
utc_offset
}
SECOND"
end
Event
.
reorder
(
nil
)
Event
.
reorder
(
nil
)
.
select
(
t
[
:project_id
],
t
[
:target_type
],
t
[
:action
],
"date(created_at +
#{
date_interval
}
) AS date"
,
'count(id) as total_amount'
)
.
select
(
t
[
:project_id
],
t
[
:target_type
],
t
[
:action
],
"date(created_at +
#{
date_interval
}
) AS date"
,
'count(id) as total_amount'
)
...
...
lib/gitlab/database.rb
View file @
62929b36
...
@@ -46,6 +46,7 @@ module Gitlab
...
@@ -46,6 +46,7 @@ module Gitlab
end
end
end
end
# @deprecated
def
self
.
postgresql?
def
self
.
postgresql?
adapter_name
.
casecmp
(
'postgresql'
).
zero?
adapter_name
.
casecmp
(
'postgresql'
).
zero?
end
end
...
@@ -79,19 +80,19 @@ module Gitlab
...
@@ -79,19 +80,19 @@ module Gitlab
end
end
def
self
.
postgresql_9_or_less?
def
self
.
postgresql_9_or_less?
postgresql?
&&
version
.
to_f
<
10
version
.
to_f
<
10
end
end
def
self
.
join_lateral_supported?
def
self
.
join_lateral_supported?
postgresql?
&&
version
.
to_f
>=
9.3
version
.
to_f
>=
9.3
end
end
def
self
.
replication_slots_supported?
def
self
.
replication_slots_supported?
postgresql?
&&
version
.
to_f
>=
9.4
version
.
to_f
>=
9.4
end
end
def
self
.
postgresql_minimum_supported_version?
def
self
.
postgresql_minimum_supported_version?
postgresql?
&&
version
.
to_f
>=
9.6
version
.
to_f
>=
9.6
end
end
# map some of the function names that changed between PostgreSQL 9 and 10
# map some of the function names that changed between PostgreSQL 9 and 10
...
...
lib/gitlab/database/grant.rb
View file @
62929b36
...
@@ -6,47 +6,25 @@ module Gitlab
...
@@ -6,47 +6,25 @@ module Gitlab
class
Grant
<
ActiveRecord
::
Base
class
Grant
<
ActiveRecord
::
Base
include
FromUnion
include
FromUnion
self
.
table_name
=
self
.
table_name
=
'information_schema.role_table_grants'
if
Database
.
postgresql?
'information_schema.role_table_grants'
else
'information_schema.schema_privileges'
end
# Returns true if the current user can create and execute triggers on the
# Returns true if the current user can create and execute triggers on the
# given table.
# given table.
def
self
.
create_and_execute_trigger?
(
table
)
def
self
.
create_and_execute_trigger?
(
table
)
if
Database
.
postgresql?
# We _must not_ use quote_table_name as this will produce double
# We _must not_ use quote_table_name as this will produce double
# quotes on PostgreSQL and for "has_table_privilege" we need single
# quotes on PostgreSQL and for "has_table_privilege" we need single
# quotes.
# quotes.
quoted_table
=
connection
.
quote
(
table
)
quoted_table
=
connection
.
quote
(
table
)
begin
from
(
nil
)
.
pluck
(
Arel
.
sql
(
"has_table_privilege(
#{
quoted_table
}
, 'TRIGGER')"
))
.
first
rescue
ActiveRecord
::
StatementInvalid
# This error is raised when using a non-existing table name. In this
# case we just want to return false as a user technically can't
# create triggers for such a table.
false
end
else
queries
=
[
Grant
.
select
(
1
)
.
from
(
'information_schema.user_privileges'
)
.
where
(
"PRIVILEGE_TYPE = 'SUPER'"
)
.
where
(
"GRANTEE = CONCAT('
\\
'', REPLACE(CURRENT_USER(), '@', '
\\
'@
\\
''), '
\\
'')"
),
Grant
.
select
(
1
)
.
from
(
'information_schema.schema_privileges'
)
.
where
(
"PRIVILEGE_TYPE = 'TRIGGER'"
)
.
where
(
'TABLE_SCHEMA = ?'
,
Gitlab
::
Database
.
database_name
)
.
where
(
"GRANTEE = CONCAT('
\\
'', REPLACE(CURRENT_USER(), '@', '
\\
'@
\\
''), '
\\
'')"
)
]
Grant
.
from_union
(
queries
,
alias_as:
'privs'
).
any?
begin
from
(
nil
)
.
pluck
(
Arel
.
sql
(
"has_table_privilege(
#{
quoted_table
}
, 'TRIGGER')"
))
.
first
rescue
ActiveRecord
::
StatementInvalid
# This error is raised when using a non-existing table name. In this
# case we just want to return false as a user technically can't
# create triggers for such a table.
false
end
end
end
end
end
end
...
...
lib/gitlab/database/median.rb
View file @
62929b36
...
@@ -137,8 +137,6 @@ module Gitlab
...
@@ -137,8 +137,6 @@ module Gitlab
end
end
def
extract_diff_epoch
(
diff
)
def
extract_diff_epoch
(
diff
)
return
diff
unless
Gitlab
::
Database
.
postgresql?
Arel
.
sql
(
%Q{EXTRACT(EPOCH FROM (
#{
diff
.
to_sql
}
))}
)
Arel
.
sql
(
%Q{EXTRACT(EPOCH FROM (
#{
diff
.
to_sql
}
))}
)
end
end
...
...
lib/gitlab/database/migration_helpers.rb
View file @
62929b36
...
@@ -152,8 +152,6 @@ module Gitlab
...
@@ -152,8 +152,6 @@ module Gitlab
# Only available on Postgresql >= 9.2
# Only available on Postgresql >= 9.2
def
supports_drop_index_concurrently?
def
supports_drop_index_concurrently?
return
false
unless
Database
.
postgresql?
version
=
select_one
(
"SELECT current_setting('server_version_num') AS v"
)[
'v'
].
to_i
version
=
select_one
(
"SELECT current_setting('server_version_num') AS v"
)[
'v'
].
to_i
version
>=
90200
version
>=
90200
...
...
lib/gitlab/database/sha_attribute.rb
View file @
62929b36
...
@@ -2,14 +2,9 @@
...
@@ -2,14 +2,9 @@
module
Gitlab
module
Gitlab
module
Database
module
Database
BINARY_TYPE
=
# PostgreSQL defines its own class with slightly different
if
Gitlab
::
Database
.
postgresql?
# behaviour from the default Binary type.
# PostgreSQL defines its own class with slightly different
BINARY_TYPE
=
ActiveRecord
::
ConnectionAdapters
::
PostgreSQL
::
OID
::
Bytea
# behaviour from the default Binary type.
ActiveRecord
::
ConnectionAdapters
::
PostgreSQL
::
OID
::
Bytea
else
ActiveModel
::
Type
::
Binary
end
# Class for casting binary data to hexadecimal SHA1 hashes (and vice-versa).
# Class for casting binary data to hexadecimal SHA1 hashes (and vice-versa).
#
#
...
...
lib/gitlab/health_checks/db_check.rb
View file @
62929b36
...
@@ -18,11 +18,7 @@ module Gitlab
...
@@ -18,11 +18,7 @@ module Gitlab
def
check
def
check
catch_timeout
10
.
seconds
do
catch_timeout
10
.
seconds
do
if
Gitlab
::
Database
.
postgresql?
ActiveRecord
::
Base
.
connection
.
execute
(
'SELECT 1 as ping'
)
&
.
first
&
.
[
](
'ping'
)
&
.
to_s
ActiveRecord
::
Base
.
connection
.
execute
(
'SELECT 1 as ping'
)
&
.
first
&
.
[
](
'ping'
)
&
.
to_s
else
ActiveRecord
::
Base
.
connection
.
execute
(
'SELECT 1 as ping'
)
&
.
first
&
.
first
&
.
to_s
end
end
end
end
end
end
end
...
...
lib/gitlab/sherlock/query.rb
View file @
62929b36
...
@@ -96,12 +96,7 @@ module Gitlab
...
@@ -96,12 +96,7 @@ module Gitlab
private
private
def
raw_explain
(
query
)
def
raw_explain
(
query
)
explain
=
explain
=
"EXPLAIN ANALYZE
#{
query
}
;"
if
Gitlab
::
Database
.
postgresql?
"EXPLAIN ANALYZE
#{
query
}
;"
else
"EXPLAIN
#{
query
}
;"
end
ActiveRecord
::
Base
.
connection
.
execute
(
explain
)
ActiveRecord
::
Base
.
connection
.
execute
(
explain
)
end
end
...
...
lib/tasks/gitlab/setup.rake
View file @
62929b36
...
@@ -45,8 +45,6 @@ namespace :gitlab do
...
@@ -45,8 +45,6 @@ namespace :gitlab do
# method terminates all the connections so that a subsequent DROP
# method terminates all the connections so that a subsequent DROP
# will work.
# will work.
def
self
.
terminate_all_connections
def
self
.
terminate_all_connections
return
false
unless
Gitlab
::
Database
.
postgresql?
cmd
=
<<~
SQL
cmd
=
<<~
SQL
SELECT pg_terminate_backend(pg_stat_activity.pid)
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
FROM pg_stat_activity
...
...
spec/features/admin/dashboard_spec.rb
View file @
62929b36
...
@@ -17,10 +17,8 @@ describe 'admin visits dashboard' do
...
@@ -17,10 +17,8 @@ describe 'admin visits dashboard' do
# Make sure the fork_networks & fork_networks reltuples have been updated
# Make sure the fork_networks & fork_networks reltuples have been updated
# to get a correct count on postgresql
# to get a correct count on postgresql
if
Gitlab
::
Database
.
postgresql?
ActiveRecord
::
Base
.
connection
.
execute
(
'ANALYZE fork_networks'
)
ActiveRecord
::
Base
.
connection
.
execute
(
'ANALYZE fork_networks'
)
ActiveRecord
::
Base
.
connection
.
execute
(
'ANALYZE fork_network_members'
)
ActiveRecord
::
Base
.
connection
.
execute
(
'ANALYZE fork_network_members'
)
end
visit
admin_root_path
visit
admin_root_path
...
...
spec/finders/issues_finder_spec.rb
View file @
62929b36
...
@@ -690,7 +690,6 @@ describe IssuesFinder do
...
@@ -690,7 +690,6 @@ describe IssuesFinder do
let
(
:finder
)
{
described_class
.
new
(
nil
,
params
)
}
let
(
:finder
)
{
described_class
.
new
(
nil
,
params
)
}
before
do
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
true
)
stub_feature_flags
(
attempt_group_search_optimizations:
true
)
stub_feature_flags
(
attempt_group_search_optimizations:
true
)
end
end
...
@@ -702,18 +701,6 @@ describe IssuesFinder do
...
@@ -702,18 +701,6 @@ describe IssuesFinder do
end
end
end
end
context
'when the database is not Postgres'
do
let
(
:params
)
{
{
search:
'foo'
,
attempt_group_search_optimizations:
true
}
}
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:postgresql?
).
and_return
(
false
)
end
it
'returns false'
do
expect
(
finder
.
use_cte_for_search?
).
to
be_falsey
end
end
context
'when the force_cte param is falsey'
do
context
'when the force_cte param is falsey'
do
let
(
:params
)
{
{
search:
'foo'
}
}
let
(
:params
)
{
{
search:
'foo'
}
}
...
...
spec/lib/gitlab/database/sha_attribute_spec.rb
View file @
62929b36
...
@@ -12,11 +12,7 @@ describe Gitlab::Database::ShaAttribute do
...
@@ -12,11 +12,7 @@ describe Gitlab::Database::ShaAttribute do
end
end
let
(
:binary_from_db
)
do
let
(
:binary_from_db
)
do
if
Gitlab
::
Database
.
postgresql?
"
\\
x
#{
sha
}
"
"
\\
x
#{
sha
}
"
else
binary_sha
end
end
end
let
(
:attribute
)
{
described_class
.
new
}
let
(
:attribute
)
{
described_class
.
new
}
...
...
spec/lib/gitlab/database_spec.rb
View file @
62929b36
...
@@ -17,14 +17,6 @@ describe Gitlab::Database do
...
@@ -17,14 +17,6 @@ describe Gitlab::Database do
it
'returns the name of the adapter'
do
it
'returns the name of the adapter'
do
expect
(
described_class
.
adapter_name
).
to
be_an_instance_of
(
String
)
expect
(
described_class
.
adapter_name
).
to
be_an_instance_of
(
String
)
end
end
end
describe
'.human_adapter_name'
do
it
'returns PostgreSQL when using PostgreSQL'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
expect
(
described_class
.
human_adapter_name
).
to
eq
(
'PostgreSQL'
)
end
it
'returns Unknown when using anything else'
do
it
'returns Unknown when using anything else'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
...
@@ -33,6 +25,12 @@ describe Gitlab::Database do
...
@@ -33,6 +25,12 @@ describe Gitlab::Database do
end
end
end
end
describe
'.human_adapter_name'
do
it
'returns PostgreSQL when using PostgreSQL'
do
expect
(
described_class
.
human_adapter_name
).
to
eq
(
'PostgreSQL'
)
end
end
describe
'.postgresql?'
do
describe
'.postgresql?'
do
subject
{
described_class
.
postgresql?
}
subject
{
described_class
.
postgresql?
}
...
@@ -65,21 +63,18 @@ describe Gitlab::Database do
...
@@ -65,21 +63,18 @@ describe Gitlab::Database do
end
end
describe
'.postgresql_9_or_less?'
do
describe
'.postgresql_9_or_less?'
do
it
'returns false when not using postgresql'
do
it
'returns true when using postgresql 8.4'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'8.4'
)
expect
(
described_class
.
postgresql_9_or_less?
).
to
eq
(
true
)
expect
(
described_class
.
postgresql_9_or_less?
).
to
eq
(
false
)
end
end
it
'returns true when using PostgreSQL 9.6'
do
it
'returns true when using PostgreSQL 9.6'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
expect
(
described_class
.
postgresql_9_or_less?
).
to
eq
(
true
)
expect
(
described_class
.
postgresql_9_or_less?
).
to
eq
(
true
)
end
end
it
'returns false when using PostgreSQL 10 or newer'
do
it
'returns false when using PostgreSQL 10 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
expect
(
described_class
.
postgresql_9_or_less?
).
to
eq
(
false
)
expect
(
described_class
.
postgresql_9_or_less?
).
to
eq
(
false
)
...
@@ -87,53 +82,33 @@ describe Gitlab::Database do
...
@@ -87,53 +82,33 @@ describe Gitlab::Database do
end
end
describe
'.postgresql_minimum_supported_version?'
do
describe
'.postgresql_minimum_supported_version?'
do
it
'returns false when
not using PostgreSQL
'
do
it
'returns false when
using PostgreSQL 9.5
'
do
allow
(
described_class
).
to
receive
(
:
postgresql?
).
and_return
(
false
)
allow
(
described_class
).
to
receive
(
:
version
).
and_return
(
'9.5'
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
false
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
false
)
end
end
context
'when using PostgreSQL'
do
it
'returns true when using PostgreSQL 9.6'
do
before
do
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
end
it
'returns false when using PostgreSQL 9.5'
do
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.5'
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
false
)
end
it
'returns true when using PostgreSQL 9.6'
do
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
true
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
true
)
end
end
it
'returns true when using PostgreSQL 10 or newer'
do
it
'returns true when using PostgreSQL 10 or newer'
do
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
true
)
expect
(
described_class
.
postgresql_minimum_supported_version?
).
to
eq
(
true
)
end
end
end
end
end
describe
'.join_lateral_supported?'
do
describe
'.join_lateral_supported?'
do
it
'returns false when not using postgresql'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
join_lateral_supported?
).
to
eq
(
false
)
end
it
'returns false when using PostgreSQL 9.2'
do
it
'returns false when using PostgreSQL 9.2'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.2.1'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.2.1'
)
expect
(
described_class
.
join_lateral_supported?
).
to
eq
(
false
)
expect
(
described_class
.
join_lateral_supported?
).
to
eq
(
false
)
end
end
it
'returns true when using PostgreSQL 9.3.0 or newer'
do
it
'returns true when using PostgreSQL 9.3.0 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.3.0'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.3.0'
)
expect
(
described_class
.
join_lateral_supported?
).
to
eq
(
true
)
expect
(
described_class
.
join_lateral_supported?
).
to
eq
(
true
)
...
@@ -141,21 +116,13 @@ describe Gitlab::Database do
...
@@ -141,21 +116,13 @@ describe Gitlab::Database do
end
end
describe
'.replication_slots_supported?'
do
describe
'.replication_slots_supported?'
do
it
'returns false when not using postgresql'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
false
)
expect
(
described_class
.
replication_slots_supported?
).
to
eq
(
false
)
end
it
'returns false when using PostgreSQL 9.3'
do
it
'returns false when using PostgreSQL 9.3'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.3.1'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.3.1'
)
expect
(
described_class
.
replication_slots_supported?
).
to
eq
(
false
)
expect
(
described_class
.
replication_slots_supported?
).
to
eq
(
false
)
end
end
it
'returns true when using PostgreSQL 9.4.0 or newer'
do
it
'returns true when using PostgreSQL 9.4.0 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.4.0'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.4.0'
)
expect
(
described_class
.
replication_slots_supported?
).
to
eq
(
true
)
expect
(
described_class
.
replication_slots_supported?
).
to
eq
(
true
)
...
@@ -164,14 +131,12 @@ describe Gitlab::Database do
...
@@ -164,14 +131,12 @@ describe Gitlab::Database do
describe
'.pg_wal_lsn_diff'
do
describe
'.pg_wal_lsn_diff'
do
it
'returns old name when using PostgreSQL 9.6'
do
it
'returns old name when using PostgreSQL 9.6'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
expect
(
described_class
.
pg_wal_lsn_diff
).
to
eq
(
'pg_xlog_location_diff'
)
expect
(
described_class
.
pg_wal_lsn_diff
).
to
eq
(
'pg_xlog_location_diff'
)
end
end
it
'returns new name when using PostgreSQL 10 or newer'
do
it
'returns new name when using PostgreSQL 10 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
expect
(
described_class
.
pg_wal_lsn_diff
).
to
eq
(
'pg_wal_lsn_diff'
)
expect
(
described_class
.
pg_wal_lsn_diff
).
to
eq
(
'pg_wal_lsn_diff'
)
...
@@ -180,14 +145,12 @@ describe Gitlab::Database do
...
@@ -180,14 +145,12 @@ describe Gitlab::Database do
describe
'.pg_current_wal_insert_lsn'
do
describe
'.pg_current_wal_insert_lsn'
do
it
'returns old name when using PostgreSQL 9.6'
do
it
'returns old name when using PostgreSQL 9.6'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
expect
(
described_class
.
pg_current_wal_insert_lsn
).
to
eq
(
'pg_current_xlog_insert_location'
)
expect
(
described_class
.
pg_current_wal_insert_lsn
).
to
eq
(
'pg_current_xlog_insert_location'
)
end
end
it
'returns new name when using PostgreSQL 10 or newer'
do
it
'returns new name when using PostgreSQL 10 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
expect
(
described_class
.
pg_current_wal_insert_lsn
).
to
eq
(
'pg_current_wal_insert_lsn'
)
expect
(
described_class
.
pg_current_wal_insert_lsn
).
to
eq
(
'pg_current_wal_insert_lsn'
)
...
@@ -196,14 +159,12 @@ describe Gitlab::Database do
...
@@ -196,14 +159,12 @@ describe Gitlab::Database do
describe
'.pg_last_wal_receive_lsn'
do
describe
'.pg_last_wal_receive_lsn'
do
it
'returns old name when using PostgreSQL 9.6'
do
it
'returns old name when using PostgreSQL 9.6'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
expect
(
described_class
.
pg_last_wal_receive_lsn
).
to
eq
(
'pg_last_xlog_receive_location'
)
expect
(
described_class
.
pg_last_wal_receive_lsn
).
to
eq
(
'pg_last_xlog_receive_location'
)
end
end
it
'returns new name when using PostgreSQL 10 or newer'
do
it
'returns new name when using PostgreSQL 10 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
expect
(
described_class
.
pg_last_wal_receive_lsn
).
to
eq
(
'pg_last_wal_receive_lsn'
)
expect
(
described_class
.
pg_last_wal_receive_lsn
).
to
eq
(
'pg_last_wal_receive_lsn'
)
...
@@ -212,14 +173,12 @@ describe Gitlab::Database do
...
@@ -212,14 +173,12 @@ describe Gitlab::Database do
describe
'.pg_last_wal_replay_lsn'
do
describe
'.pg_last_wal_replay_lsn'
do
it
'returns old name when using PostgreSQL 9.6'
do
it
'returns old name when using PostgreSQL 9.6'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'9.6'
)
expect
(
described_class
.
pg_last_wal_replay_lsn
).
to
eq
(
'pg_last_xlog_replay_location'
)
expect
(
described_class
.
pg_last_wal_replay_lsn
).
to
eq
(
'pg_last_xlog_replay_location'
)
end
end
it
'returns new name when using PostgreSQL 10 or newer'
do
it
'returns new name when using PostgreSQL 10 or newer'
do
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
allow
(
described_class
).
to
receive
(
:version
).
and_return
(
'10'
)
expect
(
described_class
.
pg_last_wal_replay_lsn
).
to
eq
(
'pg_last_wal_replay_lsn'
)
expect
(
described_class
.
pg_last_wal_replay_lsn
).
to
eq
(
'pg_last_wal_replay_lsn'
)
...
@@ -434,7 +393,6 @@ describe Gitlab::Database do
...
@@ -434,7 +393,6 @@ describe Gitlab::Database do
describe
'.db_read_only?'
do
describe
'.db_read_only?'
do
before
do
before
do
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
and_call_original
allow
(
ActiveRecord
::
Base
.
connection
).
to
receive
(
:execute
).
and_call_original
allow
(
described_class
).
to
receive
(
:postgresql?
).
and_return
(
true
)
end
end
it
'detects a read only database'
do
it
'detects a read only database'
do
...
...
spec/models/project_feature_spec.rb
View file @
62929b36
...
@@ -8,11 +8,7 @@ describe ProjectFeature do
...
@@ -8,11 +8,7 @@ describe ProjectFeature do
describe
'.quoted_access_level_column'
do
describe
'.quoted_access_level_column'
do
it
'returns the table name and quoted column name for a feature'
do
it
'returns the table name and quoted column name for a feature'
do
expected
=
if
Gitlab
::
Database
.
postgresql?
expected
=
'"project_features"."issues_access_level"'
'"project_features"."issues_access_level"'
else
'`project_features`.`issues_access_level`'
end
expect
(
described_class
.
quoted_access_level_column
(
:issues
)).
to
eq
(
expected
)
expect
(
described_class
.
quoted_access_level_column
(
:issues
)).
to
eq
(
expected
)
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