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
656ab734
Commit
656ab734
authored
Feb 21, 2020
by
Kirstie Cook
Committed by
Imre Farkas
Feb 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration self monitoring environment
parent
aba9de55
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
0 deletions
+101
-0
changelogs/unreleased/204858-update-self-monitor-environments.yml
...gs/unreleased/204858-update-self-monitor-environments.yml
+5
-0
db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb
...4214934_create_environment_for_self_monitoring_project.rb
+28
-0
spec/migrations/create_environment_for_self_monitoring_project_spec.rb
...ns/create_environment_for_self_monitoring_project_spec.rb
+68
-0
No files found.
changelogs/unreleased/204858-update-self-monitor-environments.yml
0 → 100644
View file @
656ab734
---
title
:
Add migration to create self monitoring project environment
merge_request
:
25289
author
:
type
:
added
db/post_migrate/20200214214934_create_environment_for_self_monitoring_project.rb
0 → 100644
View file @
656ab734
# 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
spec/migrations/create_environment_for_self_monitoring_project_spec.rb
0 → 100644
View file @
656ab734
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200214214934_create_environment_for_self_monitoring_project'
)
describe
CreateEnvironmentForSelfMonitoringProject
,
:migration
do
let
(
:application_settings_table
)
{
table
(
:application_settings
)
}
let
(
:environments
)
{
table
(
:environments
)
}
let
(
:instance_administrators_group
)
do
table
(
:namespaces
).
create!
(
id:
1
,
name:
'GitLab Instance Administrators'
,
path:
'gitlab-instance-administrators-random'
,
type:
'Group'
)
end
let
(
:self_monitoring_project
)
do
table
(
:projects
).
create!
(
id:
2
,
name:
'Self Monitoring'
,
path:
'self_monitoring'
,
namespace_id:
instance_administrators_group
.
id
)
end
context
'when the self monitoring project ID is not set'
do
it
'does not make changes'
do
expect
(
environments
.
find_by
(
project_id:
self_monitoring_project
.
id
)).
to
be_nil
migrate!
expect
(
environments
.
find_by
(
project_id:
self_monitoring_project
.
id
)).
to
be_nil
end
end
context
'when the self monitoring project ID is set'
do
before
do
application_settings_table
.
create!
(
instance_administration_project_id:
self_monitoring_project
.
id
)
end
context
'when the environment already exists'
do
let!
(
:environment
)
do
environments
.
create!
(
project_id:
self_monitoring_project
.
id
,
name:
'production'
,
slug:
'production'
)
end
it
'does not make changes'
do
expect
(
environments
.
find_by
(
project_id:
self_monitoring_project
.
id
)).
to
eq
(
environment
)
migrate!
expect
(
environments
.
find_by
(
project_id:
self_monitoring_project
.
id
)).
to
eq
(
environment
)
end
end
context
'when the environment does not exist'
do
it
'creates the environment'
do
expect
(
environments
.
find_by
(
project_id:
self_monitoring_project
.
id
)).
to
be_nil
migrate!
expect
(
environments
.
find_by
(
project_id:
self_monitoring_project
.
id
)).
to
be
end
end
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