Use dynamic mapping in trigger to sync `integrations.type_new`
What does this MR do?
In !66541 (merged) we ended
up going with a static mapping for this trigger, and figured any new
integrations could just start using the correct class name in type
directly.
But our plan is to drop the type
column at some point and replace it
with type_new
, so we still need to sync the class name to type_new
for new integrations as well.
So the trigger is changed to transform all *Service
values into
Integrations::*
, and copy any other values unmodified.
Follow-up to #333506 (closed) / !66541 (merged), in response to !67941 (comment 653170448) where we add a new integration.
Migration output
$ rails db:migrate:up VERSION=20210818175949
== 20210818175949 UpdateIntegrationsTriggerTypeNewOnInsert: migrating =========
-- execute("CREATE OR REPLACE FUNCTION integrations_set_type_new()\nRETURNS TRIGGER AS\n$$\nBEGIN\nUPDATE integrations SET type_new = regexp_replace(NEW.type, '\\A(.+)Service\\Z', 'Integrations::\\1')\nWHERE integrations.id = NEW.id;\nRETURN NULL;\n\nEND\n$$ LANGUAGE PLPGSQL\n")
-> 0.0033s
== 20210818175949 UpdateIntegrationsTriggerTypeNewOnInsert: migrated (0.0034s)
$ rails db:migrate:down VERSION=20210818175949
== 20210818175949 UpdateIntegrationsTriggerTypeNewOnInsert: reverting =========
-- execute("CREATE OR REPLACE FUNCTION integrations_set_type_new()\nRETURNS TRIGGER AS\n$$\nBEGIN\nWITH mapping(old_type, new_type) AS (VALUES\n ('AsanaService', 'Integrations::Asana'),\n ('AssemblaService', 'Integrations::Assembla'),\n ('BambooService', 'Integrations::Bamboo'),\n ('BugzillaService', 'Integrations::Bugzilla'),\n ('BuildkiteService', 'Integrations::Buildkite'),\n ('CampfireService', 'Integrations::Campfire'),\n ('ConfluenceService', 'Integrations::Confluence'),\n ('CustomIssueTrackerService', 'Integrations::CustomIssueTracker'),\n ('DatadogService', 'Integrations::Datadog'),\n ('DiscordService', 'Integrations::Discord'),\n ('DroneCiService', 'Integrations::DroneCi'),\n ('EmailsOnPushService', 'Integrations::EmailsOnPush'),\n ('EwmService', 'Integrations::Ewm'),\n ('ExternalWikiService', 'Integrations::ExternalWiki'),\n ('FlowdockService', 'Integrations::Flowdock'),\n ('HangoutsChatService', 'Integrations::HangoutsChat'),\n ('IrkerService', 'Integrations::Irker'),\n ('JenkinsService', 'Integrations::Jenkins'),\n ('JiraService', 'Integrations::Jira'),\n ('MattermostService', 'Integrations::Mattermost'),\n ('MattermostSlashCommandsService', 'Integrations::MattermostSlashCommands'),\n ('MicrosoftTeamsService', 'Integrations::MicrosoftTeams'),\n ('MockCiService', 'Integrations::MockCi'),\n ('MockMonitoringService', 'Integrations::MockMonitoring'),\n ('PackagistService', 'Integrations::Packagist'),\n ('PipelinesEmailService', 'Integrations::PipelinesEmail'),\n ('PivotaltrackerService', 'Integrations::Pivotaltracker'),\n ('PrometheusService', 'Integrations::Prometheus'),\n ('PushoverService', 'Integrations::Pushover'),\n ('RedmineService', 'Integrations::Redmine'),\n ('SlackService', 'Integrations::Slack'),\n ('SlackSlashCommandsService', 'Integrations::SlackSlashCommands'),\n ('TeamcityService', 'Integrations::Teamcity'),\n ('UnifyCircuitService', 'Integrations::UnifyCircuit'),\n ('YoutrackService', 'Integrations::Youtrack'),\n ('WebexTeamsService', 'Integrations::WebexTeams'),\n\n -- EE-only integrations\n ('GithubService', 'Integrations::Github'),\n ('GitlabSlackApplicationService', 'Integrations::GitlabSlackApplication')\n)\n\nUPDATE integrations SET type_new = mapping.new_type\nFROM mapping\nWHERE integrations.id = NEW.id\n AND mapping.old_type = NEW.type;\nRETURN NULL;\n\nEND\n$$ LANGUAGE PLPGSQL\n")
-> 0.0025s
== 20210818175949 UpdateIntegrationsTriggerTypeNewOnInsert: reverted (0.0026s)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) - [-] I have added/updated documentation, or it's not needed. (Is documentation required?)
- [-] I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?)
-
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) - [-] I have tested this MR in all supported browsers, or it's not needed.
- [-] I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Related to #333506 (closed)
Edited by Markus Koller