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
b8a275d3
Commit
b8a275d3
authored
Jan 05, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use bulk_insert instead of AR create
parent
c8059881
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
12 deletions
+45
-12
db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb
...grate_kubernetes_service_to_new_clusters_architectures.rb
+45
-12
No files found.
db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb
View file @
b8a275d3
...
@@ -94,24 +94,57 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
...
@@ -94,24 +94,57 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
def
up
def
up
MigrateKubernetesServiceToNewClustersArchitectures
::
Service
MigrateKubernetesServiceToNewClustersArchitectures
::
Service
.
unmanaged_kubernetes_service
.
find_each
(
batch_size:
1
)
do
|
kubernetes_service
|
.
unmanaged_kubernetes_service
.
each_batch
(
of:
100
)
do
|
kubernetes_services
|
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
create
(
rows_for_clusters
=
kubernetes_services
.
map
do
|
kubernetes_service
|
{
enabled:
kubernetes_service
.
active
,
enabled:
kubernetes_service
.
active
,
user_id:
nil
,
# KubernetesService doesn't have
user_id:
nil
,
# KubernetesService doesn't have
name:
DEFAULT_KUBERNETES_SERVICE_CLUSTER_NAME
,
name:
DEFAULT_KUBERNETES_SERVICE_CLUSTER_NAME
,
provider_type:
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
provider_types
[
:user
],
provider_type:
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
provider_types
[
:user
],
platform_type:
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
platform_types
[
:kubernetes
],
platform_type:
MigrateKubernetesServiceToNewClustersArchitectures
::
Cluster
.
platform_types
[
:kubernetes
],
projects:
[
kubernetes_service
.
project
.
becomes
(
MigrateKubernetesServiceToNewClustersArchitectures
::
Project
)],
environment_scope:
find_dedicated_environement_scope
(
kubernetes_service
.
project
),
environment_scope:
find_dedicated_environement_scope
(
kubernetes_service
.
project
),
platform_kubernetes_attributes:
{
created_at:
Gitlab
::
Database
.
sanitize_timestamp
(
kubernetes_service
.
created_at
),
updated_at:
Gitlab
::
Database
.
sanitize_timestamp
(
kubernetes_service
.
updated_at
)
}
end
inserted_cluster_ids
=
Gitlab
::
Database
.
bulk_insert
(
'clusters'
,
rows_for_clusters
,
return_ids:
true
)
rows_for_cluster_platforms_kubernetes
=
kubernetes_services
.
each_with_index
.
map
do
|
kubernetes_service
,
i
|
# Create PlatformsKubernetes instance for generating an encrypted token
platforms_kubernetes
=
MigrateKubernetesServiceToNewClustersArchitectures
::
PlatformsKubernetes
.
new
(
token:
kubernetes_service
.
token
)
{
cluster_id:
inserted_cluster_ids
[
i
],
api_url:
kubernetes_service
.
api_url
,
api_url:
kubernetes_service
.
api_url
,
ca_cert:
kubernetes_service
.
ca_pem
,
ca_cert:
kubernetes_service
.
ca_pem
,
namespace:
kubernetes_service
.
namespace
,
namespace:
kubernetes_service
.
namespace
,
username:
nil
,
# KubernetesService doesn't have
username:
nil
,
# KubernetesService doesn't have
encrypted_password:
nil
,
# KubernetesService doesn't have
encrypted_password:
nil
,
# KubernetesService doesn't have
encrypted_password_iv:
nil
,
# KubernetesService doesn't have
encrypted_password_iv:
nil
,
# KubernetesService doesn't have
token:
kubernetes_service
.
token
# encrypted_token and encrypted_token_iv
encrypted_token:
platforms_kubernetes
.
encrypted_token
,
# encrypted_token and encrypted_token_iv
}
)
encrypted_token_iv:
platforms_kubernetes
.
encrypted_token_iv
,
# encrypted_token and encrypted_token_iv
created_at:
Gitlab
::
Database
.
sanitize_timestamp
(
kubernetes_service
.
created_at
),
updated_at:
Gitlab
::
Database
.
sanitize_timestamp
(
kubernetes_service
.
updated_at
)
}
end
Gitlab
::
Database
.
bulk_insert
(
'cluster_platforms_kubernetes'
,
rows_for_cluster_platforms_kubernetes
)
rows_for_cluster_projects
=
kubernetes_services
.
each_with_index
.
map
do
|
kubernetes_service
,
i
|
{
cluster_id:
inserted_cluster_ids
[
i
],
project_id:
kubernetes_service
.
project_id
,
created_at:
Gitlab
::
Database
.
sanitize_timestamp
(
kubernetes_service
.
created_at
),
updated_at:
Gitlab
::
Database
.
sanitize_timestamp
(
kubernetes_service
.
updated_at
)
}
end
Gitlab
::
Database
.
bulk_insert
(
'cluster_projects'
,
rows_for_cluster_projects
)
end
end
MigrateKubernetesServiceToNewClustersArchitectures
::
Service
.
kubernetes_service_without_template
.
update_all
(
active:
false
)
MigrateKubernetesServiceToNewClustersArchitectures
::
Service
.
kubernetes_service_without_template
.
update_all
(
active:
false
)
...
...
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