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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
df658c7b
Commit
df658c7b
authored
Jan 08, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable STI of ActiveRecord. Refactoring specs.
parent
58d074e0
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
66 deletions
+184
-66
db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb
...grate_kubernetes_service_to_new_clusters_architectures.rb
+20
-2
spec/migrations/migrate_kubernetes_service_to_new_clusters_architectures_spec.rb
..._kubernetes_service_to_new_clusters_architectures_spec.rb
+164
-64
No files found.
db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb
View file @
df658c7b
...
...
@@ -12,6 +12,7 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
has_many
:cluster_projects
,
class_name:
'MigrateKubernetesServiceToNewClustersArchitectures::ClustersProject'
has_many
:clusters
,
through: :cluster_projects
,
class_name:
'MigrateKubernetesServiceToNewClustersArchitectures::Cluster'
has_many
:services
,
class_name:
'MigrateKubernetesServiceToNewClustersArchitectures::Service'
has_one
:kubernetes_service
,
->
{
where
(
category:
'deployment'
,
type:
'KubernetesService'
)
},
class_name:
'MigrateKubernetesServiceToNewClustersArchitectures::Service'
,
inverse_of: :project
,
foreign_key: :project_id
end
class
Cluster
<
ActiveRecord
::
Base
...
...
@@ -55,8 +56,9 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
include
EachBatch
self
.
table_name
=
'services'
self
.
inheritance_column
=
:_type_disabled
# Disable STI, otherwise KubernetesModel will be looked up
belongs_to
:project
,
class_name:
'MigrateKubernetesServiceToNewClustersArchitectures::Project'
belongs_to
:project
,
class_name:
'MigrateKubernetesServiceToNewClustersArchitectures::Project'
,
foreign_key: :project_id
scope
:unmanaged_kubernetes_service
,
->
do
joins
(
'LEFT JOIN projects ON projects.id = services.project_id'
)
...
...
@@ -72,6 +74,22 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
scope
:kubernetes_service_without_template
,
->
do
where
(
category:
'deployment'
,
type:
'KubernetesService'
,
template:
false
)
end
def
api_url
JSON
.
parse
(
self
.
properties
)[
'api_url'
]
end
def
ca_pem
JSON
.
parse
(
self
.
properties
)[
'ca_pem'
]
end
def
namespace
JSON
.
parse
(
self
.
properties
)[
'namespace'
]
end
def
token
JSON
.
parse
(
self
.
properties
)[
'token'
]
end
end
def
find_dedicated_environement_scope
(
project
)
...
...
@@ -101,7 +119,7 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
name:
DEFAULT_KUBERNETES_SERVICE_CLUSTER_NAME
,
provider_type:
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
provider_types
[
:user
],
platform_type:
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
platform_types
[
:kubernetes
],
projects:
[
kubernetes_service
.
project
.
becomes
(
MigrateKubernetesServiceToNewClustersArchitectures
::
Project
)
],
projects:
[
kubernetes_service
.
project
],
environment_scope:
find_dedicated_environement_scope
(
kubernetes_service
.
project
),
platform_kubernetes_attributes:
{
api_url:
kubernetes_service
.
api_url
,
...
...
spec/migrations/migrate_kubernetes_service_to_new_clusters_architectures_spec.rb
View file @
df658c7b
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