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
76db67f5
Commit
76db67f5
authored
Jul 07, 2021
by
Luke Duncalfe
Committed by
Max Woolf
Jul 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename services table to integrations
parent
7bd32bfe
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
561 additions
and
96 deletions
+561
-96
app/models/concerns/has_integrations.rb
app/models/concerns/has_integrations.rb
+1
-1
app/models/group.rb
app/models/group.rb
+1
-1
app/models/integration.rb
app/models/integration.rb
+2
-5
db/migrate/20210621043337_rename_services_to_integrations.rb
db/migrate/20210621043337_rename_services_to_integrations.rb
+150
-0
db/migrate/20210621044000_rename_services_indexes_to_integrations.rb
...20210621044000_rename_services_indexes_to_integrations.rb
+30
-0
db/post_migrate/20210621223000_steal_background_jobs_that_reference_services.rb
...21223000_steal_background_jobs_that_reference_services.rb
+14
-0
db/post_migrate/20210621223242_finalize_rename_services_to_integrations.rb
...0210621223242_finalize_rename_services_to_integrations.rb
+13
-0
db/schema_migrations/20210621043337
db/schema_migrations/20210621043337
+1
-0
db/schema_migrations/20210621044000
db/schema_migrations/20210621044000
+1
-0
db/schema_migrations/20210621223000
db/schema_migrations/20210621223000
+1
-0
db/schema_migrations/20210621223242
db/schema_migrations/20210621223242
+1
-0
db/structure.sql
db/structure.sql
+79
-79
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+6
-2
lib/gitlab/database.rb
lib/gitlab/database.rb
+1
-3
spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
...te_jira_tracker_data_deployment_type_based_on_url_spec.rb
+1
-1
spec/lib/gitlab/integrations/sti_type_spec.rb
spec/lib/gitlab/integrations/sti_type_spec.rb
+4
-4
spec/migrations/rename_services_to_integrations_spec.rb
spec/migrations/rename_services_to_integrations_spec.rb
+255
-0
No files found.
app/models/concerns/has_integrations.rb
View file @
76db67f5
...
...
@@ -19,7 +19,7 @@ module HasIntegrations
def
without_integration
(
integration
)
integrations
=
Integration
.
select
(
'1'
)
.
where
(
'services.project_id = projects.id'
)
.
where
(
"
#{
Integration
.
table_name
}
.project_id = projects.id"
)
.
where
(
type:
integration
.
type
)
Project
...
...
app/models/group.rb
View file @
76db67f5
...
...
@@ -167,7 +167,7 @@ class Group < Namespace
def
without_integration
(
integration
)
integrations
=
Integration
.
select
(
'1'
)
.
where
(
'services.group_id = namespaces.id'
)
.
where
(
"
#{
Integration
.
table_name
}
.group_id = namespaces.id"
)
.
where
(
type:
integration
.
type
)
where
(
'NOT EXISTS (?)'
,
integrations
)
...
...
app/models/integration.rb
View file @
76db67f5
...
...
@@ -10,9 +10,6 @@ class Integration < ApplicationRecord
include
FromUnion
include
EachBatch
# TODO Rename the table: https://gitlab.com/gitlab-org/gitlab/-/issues/201856
self
.
table_name
=
'services'
INTEGRATION_NAMES
=
%w[
asana assembla bamboo bugzilla buildkite campfire confluence custom_issue_tracker datadog discord
drone_ci emails_on_push ewm external_wiki flowdock hangouts_chat irker jira
...
...
@@ -299,7 +296,7 @@ class Integration < ApplicationRecord
array
=
group_ids
.
to_sql
.
present?
?
"array(
#{
group_ids
.
to_sql
}
)"
:
'ARRAY[]'
where
(
type:
type
,
group_id:
group_ids
,
inherit_from_id:
nil
)
.
order
(
Arel
.
sql
(
"array_position(
#{
array
}
::bigint[],
services
.group_id)"
))
.
order
(
Arel
.
sql
(
"array_position(
#{
array
}
::bigint[],
#{
table_name
}
.group_id)"
))
.
first
end
private_class_method
:closest_group_integration
...
...
@@ -317,7 +314,7 @@ class Integration < ApplicationRecord
with_templates
?
active
.
where
(
template:
true
)
:
none
,
active
.
where
(
instance:
true
),
active
.
where
(
group_id:
group_ids
,
inherit_from_id:
nil
)
]).
order
(
Arel
.
sql
(
"type ASC, array_position(
#{
array
}
::bigint[],
services
.group_id), instance DESC"
)).
group_by
(
&
:type
).
each
do
|
type
,
records
|
]).
order
(
Arel
.
sql
(
"type ASC, array_position(
#{
array
}
::bigint[],
#{
table_name
}
.group_id), instance DESC"
)).
group_by
(
&
:type
).
each
do
|
type
,
records
|
build_from_integration
(
records
.
first
,
association
=>
scope
.
id
).
save
end
end
...
...
db/migrate/20210621043337_rename_services_to_integrations.rb
0 → 100644
View file @
76db67f5
# frozen_string_literal: true
class
RenameServicesToIntegrations
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
SchemaHelpers
# Function and trigger names match those migrated in:
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49916
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51852
WIKI_FUNCTION_NAME
=
'set_has_external_wiki'
TRACKER_FUNCTION_NAME
=
'set_has_external_issue_tracker'
WIKI_TRIGGER_ON_INSERT_NAME
=
'trigger_has_external_wiki_on_insert'
WIKI_TRIGGER_ON_UPDATE_NAME
=
'trigger_has_external_wiki_on_update'
WIKI_TRIGGER_ON_DELETE_NAME
=
'trigger_has_external_wiki_on_delete'
TRACKER_TRIGGER_ON_INSERT_NAME
=
'trigger_has_external_issue_tracker_on_insert'
TRACKER_TRIGGER_ON_UPDATE_NAME
=
'trigger_has_external_issue_tracker_on_update'
TRACKER_TRIGGER_ON_DELETE_NAME
=
'trigger_has_external_issue_tracker_on_delete'
ALL_TRIGGERS
=
[
WIKI_TRIGGER_ON_INSERT_NAME
,
WIKI_TRIGGER_ON_UPDATE_NAME
,
WIKI_TRIGGER_ON_DELETE_NAME
,
TRACKER_TRIGGER_ON_INSERT_NAME
,
TRACKER_TRIGGER_ON_UPDATE_NAME
,
TRACKER_TRIGGER_ON_DELETE_NAME
].
freeze
def
up
execute
(
'LOCK services IN ACCESS EXCLUSIVE MODE'
)
drop_all_triggers
(
:services
)
rename_table_safely
(
:services
,
:integrations
)
recreate_all_triggers
(
:integrations
)
end
def
down
execute
(
'LOCK integrations IN ACCESS EXCLUSIVE MODE'
)
drop_all_triggers
(
:integrations
)
undo_rename_table_safely
(
:services
,
:integrations
)
recreate_all_triggers
(
:services
)
end
private
def
drop_all_triggers
(
table_name
)
ALL_TRIGGERS
.
each
do
|
trigger_name
|
drop_trigger
(
table_name
,
trigger_name
)
end
end
def
recreate_all_triggers
(
table_name
)
wiki_create_insert_trigger
(
table_name
)
wiki_create_update_trigger
(
table_name
)
wiki_create_delete_trigger
(
table_name
)
tracker_replace_trigger_function
(
table_name
)
tracker_create_insert_trigger
(
table_name
)
tracker_create_update_trigger
(
table_name
)
tracker_create_delete_trigger
(
table_name
)
end
def
wiki_create_insert_trigger
(
table_name
)
execute
(
<<~
SQL
)
CREATE TRIGGER
#{
WIKI_TRIGGER_ON_INSERT_NAME
}
AFTER INSERT ON
#{
table_name
}
FOR EACH ROW
WHEN (NEW.active = TRUE AND NEW.type = 'ExternalWikiService' AND NEW.project_id IS NOT NULL)
EXECUTE FUNCTION
#{
WIKI_FUNCTION_NAME
}
();
SQL
end
def
wiki_create_update_trigger
(
table_name
)
execute
(
<<~
SQL
)
CREATE TRIGGER
#{
WIKI_TRIGGER_ON_UPDATE_NAME
}
AFTER UPDATE ON
#{
table_name
}
FOR EACH ROW
WHEN (NEW.type = 'ExternalWikiService' AND OLD.active != NEW.active AND NEW.project_id IS NOT NULL)
EXECUTE FUNCTION
#{
WIKI_FUNCTION_NAME
}
();
SQL
end
def
wiki_create_delete_trigger
(
table_name
)
execute
(
<<~
SQL
)
CREATE TRIGGER
#{
WIKI_TRIGGER_ON_DELETE_NAME
}
AFTER DELETE ON
#{
table_name
}
FOR EACH ROW
WHEN (OLD.type = 'ExternalWikiService' AND OLD.project_id IS NOT NULL)
EXECUTE FUNCTION
#{
WIKI_FUNCTION_NAME
}
();
SQL
end
# Using `replace: true` to rewrite the existing function
def
tracker_replace_trigger_function
(
table_name
)
create_trigger_function
(
TRACKER_FUNCTION_NAME
,
replace:
true
)
do
<<~
SQL
UPDATE projects SET has_external_issue_tracker = (
EXISTS
(
SELECT 1
FROM
#{
table_name
}
WHERE project_id = COALESCE(NEW.project_id, OLD.project_id)
AND active = TRUE
AND category = 'issue_tracker'
)
)
WHERE projects.id = COALESCE(NEW.project_id, OLD.project_id);
RETURN NULL;
SQL
end
end
def
tracker_create_insert_trigger
(
table_name
)
execute
(
<<~
SQL
)
CREATE TRIGGER
#{
TRACKER_TRIGGER_ON_INSERT_NAME
}
AFTER INSERT ON
#{
table_name
}
FOR EACH ROW
WHEN (NEW.category = 'issue_tracker' AND NEW.active = TRUE AND NEW.project_id IS NOT NULL)
EXECUTE FUNCTION
#{
TRACKER_FUNCTION_NAME
}
();
SQL
end
def
tracker_create_update_trigger
(
table_name
)
execute
(
<<~
SQL
)
CREATE TRIGGER
#{
TRACKER_TRIGGER_ON_UPDATE_NAME
}
AFTER UPDATE ON
#{
table_name
}
FOR EACH ROW
WHEN (NEW.category = 'issue_tracker' AND OLD.active != NEW.active AND NEW.project_id IS NOT NULL)
EXECUTE FUNCTION
#{
TRACKER_FUNCTION_NAME
}
();
SQL
end
def
tracker_create_delete_trigger
(
table_name
)
execute
(
<<~
SQL
)
CREATE TRIGGER
#{
TRACKER_TRIGGER_ON_DELETE_NAME
}
AFTER DELETE ON
#{
table_name
}
FOR EACH ROW
WHEN (OLD.category = 'issue_tracker' AND OLD.active = TRUE AND OLD.project_id IS NOT NULL)
EXECUTE FUNCTION
#{
TRACKER_FUNCTION_NAME
}
();
SQL
end
end
db/migrate/20210621044000_rename_services_indexes_to_integrations.rb
0 → 100644
View file @
76db67f5
# frozen_string_literal: true
class
RenameServicesIndexesToIntegrations
<
ActiveRecord
::
Migration
[
6.1
]
INDEXES
=
%w(
project_and_type_where_inherit_null
project_id_and_type_unique
template
type
type_and_instance_partial
type_and_template_partial
type_id_when_active_and_project_id_not_null
unique_group_id_and_type
)
.
freeze
def
up
INDEXES
.
each
do
|
index
|
execute
(
<<~
SQL
)
ALTER INDEX IF EXISTS "index_services_on_
#{
index
}
" RENAME TO "index_integrations_on_
#{
index
}
"
SQL
end
end
def
down
INDEXES
.
each
do
|
index
|
execute
(
<<~
SQL
)
ALTER INDEX IF EXISTS "index_integrations_on_
#{
index
}
" RENAME TO "index_services_on_
#{
index
}
"
SQL
end
end
end
db/post_migrate/20210621223000_steal_background_jobs_that_reference_services.rb
0 → 100644
View file @
76db67f5
# frozen_string_literal: true
class
StealBackgroundJobsThatReferenceServices
<
ActiveRecord
::
Migration
[
6.1
]
def
up
Gitlab
::
BackgroundMigration
.
steal
(
'BackfillJiraTrackerDeploymentType2'
)
Gitlab
::
BackgroundMigration
.
steal
(
'FixProjectsWithoutPrometheusService'
)
Gitlab
::
BackgroundMigration
.
steal
(
'MigrateIssueTrackersSensitiveData'
)
Gitlab
::
BackgroundMigration
.
steal
(
'RemoveDuplicateServices'
)
end
def
down
# no-op
end
end
db/post_migrate/20210621223242_finalize_rename_services_to_integrations.rb
0 → 100644
View file @
76db67f5
# frozen_string_literal: true
class
FinalizeRenameServicesToIntegrations
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
def
up
finalize_table_rename
(
:services
,
:integrations
)
end
def
down
undo_finalize_table_rename
(
:services
,
:integrations
)
end
end
db/schema_migrations/20210621043337
0 → 100644
View file @
76db67f5
cfe35a1297c4a92c4b5e62757ed74c11ffd6f207777291c11b05a4e3cee91618
\ No newline at end of file
db/schema_migrations/20210621044000
0 → 100644
View file @
76db67f5
64babbed04b9e3bf59bb723b43e3c30730527f0e0e09906073b5bd9379067ab6
\ No newline at end of file
db/schema_migrations/20210621223000
0 → 100644
View file @
76db67f5
07d0de05b6a59ba0d1f464ae488f5ead812bc643984ac3dc662c78a02a978f7f
\ No newline at end of file
db/schema_migrations/20210621223242
0 → 100644
View file @
76db67f5
eeee178019c259a6fff85219490abf62f2694227cc2facf454d93e57c373833b
\ No newline at end of file
db/structure.sql
View file @
76db67f5
This diff is collapsed.
Click to expand it.
ee/app/models/ee/project.rb
View file @
76db67f5
...
...
@@ -292,8 +292,12 @@ module EE
end
def
with_slack_application_disabled
joins
(
'LEFT JOIN services ON services.project_id = projects.id AND services.type = \'GitlabSlackApplicationService\' AND services.active IS true'
)
.
where
(
services:
{
id:
nil
})
joins
(
<<~
SQL
)
LEFT JOIN
#{
::
Integration
.
table_name
}
ON
#{
::
Integration
.
table_name
}
.project_id = projects.id
AND
#{
::
Integration
.
table_name
}
.type = 'GitlabSlackApplicationService'
AND
#{
::
Integration
.
table_name
}
.active IS true
SQL
.
where
(
integrations:
{
id:
nil
})
end
override
:with_web_entity_associations
...
...
lib/gitlab/database.rb
View file @
76db67f5
...
...
@@ -10,9 +10,7 @@ module Gitlab
# TABLES_TO_BE_RENAMED = {
# 'old_name' => 'new_name'
# }.freeze
TABLES_TO_BE_RENAMED
=
{
'services'
=>
'integrations'
}.
freeze
TABLES_TO_BE_RENAMED
=
{}.
freeze
# Minimum PostgreSQL version requirement per documentation:
# https://docs.gitlab.com/ee/install/requirements.html#postgresql-requirements
...
...
spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
View file @
76db67f5
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
UpdateJiraTrackerDataDeploymentTypeBasedOnUrl
do
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
UpdateJiraTrackerDataDeploymentTypeBasedOnUrl
,
schema:
20210421163509
do
let
(
:services_table
)
{
table
(
:services
)
}
let
(
:service_jira_cloud
)
{
services_table
.
create!
(
id:
1
,
type:
'JiraService'
)
}
let
(
:service_jira_server
)
{
services_table
.
create!
(
id:
2
,
type:
'JiraService'
)
}
...
...
spec/lib/gitlab/integrations/sti_type_spec.rb
View file @
76db67f5
...
...
@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context
'SQL SELECT'
do
let
(
:expected_sql
)
do
<<~
SQL
.
strip
SELECT "
services".* FROM "services" WHERE "service
s"."type" = 'AsanaService'
SELECT "
integrations".* FROM "integrations" WHERE "integration
s"."type" = 'AsanaService'
SQL
end
...
...
@@ -25,7 +25,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context
'SQL CREATE'
do
let
(
:expected_sql
)
do
<<~
SQL
.
strip
INSERT INTO "
service
s" ("type") VALUES ('AsanaService')
INSERT INTO "
integration
s" ("type") VALUES ('AsanaService')
SQL
end
...
...
@@ -42,7 +42,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context
'SQL UPDATE'
do
let
(
:expected_sql
)
do
<<~
SQL
.
strip
UPDATE "
service
s" SET "type" = 'AsanaService'
UPDATE "
integration
s" SET "type" = 'AsanaService'
SQL
end
...
...
@@ -61,7 +61,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context
'SQL DELETE'
do
let
(
:expected_sql
)
do
<<~
SQL
.
strip
DELETE FROM "
services" WHERE "service
s"."type" = 'AsanaService'
DELETE FROM "
integrations" WHERE "integration
s"."type" = 'AsanaService'
SQL
end
...
...
spec/migrations/rename_services_to_integrations_spec.rb
0 → 100644
View file @
76db67f5
This diff is collapsed.
Click to expand it.
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