Skip to content

Add integrations.type_new column and sync with type

What does this MR do?

This is part of renaming the integration models from FooService to Integrations::Foo, and prepares the new class name in a new type_new column which is synced from the legacy class name in type on INSERTs and UPDATEs.

Issue: #333506 (closed)

Existing records will be backfilled in a future MR: #333507 (closed), !66928 (merged)

Migration output

Up

$ rake db:migrate:up VERSION=20210721134706
== 20210721134706 AddTypeNewToIntegrations: migrating =========================
-- add_column(:integrations, :type_new, :text)
   -> 0.0032s
== 20210721134706 AddTypeNewToIntegrations: migrated (0.0033s) ================

$ rake db:migrate:up VERSION=20210721134707
== 20210721134707 AddTextLimitToIntegrationsTypeNew: migrating ================
-- transaction_open?()
   -> 0.0000s
-- current_schema()
   -> 0.0004s
-- execute("ALTER TABLE integrations\nADD CONSTRAINT check_a948a0aa7e\nCHECK ( char_length(type_new) <= 255 )\nNOT VALID;\n")
   -> 0.0011s
-- current_schema()
   -> 0.0003s
-- execute("SET statement_timeout TO 0")
   -> 0.0009s
-- execute("ALTER TABLE integrations VALIDATE CONSTRAINT check_a948a0aa7e;")
   -> 0.0017s
-- execute("RESET ALL")
   -> 0.0007s
== 20210721134707 AddTextLimitToIntegrationsTypeNew: migrated (0.0141s) =======

$ rake db:migrate:up VERSION=20210721135638
== 20210721135638 AddTriggersToIntegrationsTypeNew: migrating =================
-- 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.0028s
-- execute("CREATE TRIGGER trigger_type_new_on_insert\nAFTER INSERT ON integrations\nFOR EACH ROW\nEXECUTE FUNCTION integrations_set_type_new();\n")
   -> 0.0012s
== 20210721135638 AddTriggersToIntegrationsTypeNew: migrated (0.0042s) ========

Down

$ rake db:migrate:down VERSION=20210721135638
== 20210721135638 AddTriggersToIntegrationsTypeNew: reverting =================
-- execute("DROP TRIGGER IF EXISTS trigger_type_new_on_insert ON integrations")
   -> 0.0024s
-- execute("DROP FUNCTION IF EXISTS integrations_set_type_new()")
   -> 0.0008s
== 20210721135638 AddTriggersToIntegrationsTypeNew: reverted (0.0034s) ========

$ rake db:migrate:down VERSION=20210721134707
== 20210721134707 AddTextLimitToIntegrationsTypeNew: reverting ================
-- execute("ALTER TABLE integrations\nDROP CONSTRAINT IF EXISTS check_a948a0aa7e\n")
   -> 0.0011s
== 20210721134707 AddTextLimitToIntegrationsTypeNew: reverted (0.0071s) =======

$ rake db:migrate:down VERSION=20210721134706
== 20210721134706 AddTypeNewToIntegrations: reverting =========================
-- remove_column(:integrations, :type_new, :text)
   -> 0.0042s
== 20210721134706 AddTypeNewToIntegrations: reverted (0.0078s) ================

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Related to #333506 (closed)

Edited by Markus Koller

Merge request reports

Loading