diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-22 00:08:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-22 00:08:57 +0300 |
commit | a6c2be7cd20a9515b347e72d63c5b47bb9b79457 (patch) | |
tree | 568212b4debeb2a35bb1133209b98e1468d9ee85 /db/post_migrate | |
parent | 74a2d57b337034cfdcd719615e4da06643b69114 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb b/db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb new file mode 100644 index 00000000000..a44efa3c460 --- /dev/null +++ b/db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +class CreateEnvironmentForSelfMonitoringProject < ActiveRecord::Migration[6.0] + DOWNTIME = false + + def up + execute <<~SQL + INSERT INTO environments (project_id, name, slug, created_at, updated_at) + SELECT instance_administration_project_id, 'production', 'production', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + FROM application_settings + WHERE instance_administration_project_id IS NOT NULL + AND NOT EXISTS ( + SELECT 1 + FROM environments + INNER JOIN application_settings + ON application_settings.instance_administration_project_id = environments.project_id + ) + SQL + end + + def down + # no-op + + # This migration cannot be reversed because it cannot be ensured that the environment for the Self Monitoring Project + # did not already exist before the migration ran - in that case, the migration does nothing, and it would be unexpected + # behavior for that environment to be deleted by reversing this migration. + end +end |