diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-01-05 19:43:03 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-01-08 16:22:18 +0900 |
commit | 8bc3221f2fe096e6c1f2070a2fcdb18903c2c599 (patch) | |
tree | 738a9bac42b9c3eaf8510f48f235d6d16cdd20c1 /db | |
parent | acfb8464bef7b43b730ddf433a8223fc240d968a (diff) | |
download | gitlab-ce-8bc3221f2fe096e6c1f2070a2fcdb18903c2c599.tar.gz |
Fix query to look for proper unmanaged kubernetes service
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb b/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb index 5ea115cea90..aff934c2ab4 100644 --- a/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb +++ b/db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb @@ -55,24 +55,16 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati belongs_to :project, class_name: 'MigrateKubernetesServiceToNewClustersArchitectures::Project' scope :unmanaged_kubernetes_service, -> do - where(category: 'deployment') + joins('LEFT JOIN projects ON projects.id = services.project_id') + .joins('LEFT JOIN cluster_projects ON cluster_projects.project_id = projects.id') + .joins('LEFT JOIN cluster_platforms_kubernetes ON cluster_platforms_kubernetes.cluster_id = cluster_projects.cluster_id') + .where(category: 'deployment') .where(type: 'KubernetesService') .where(template: false) - .where("NOT EXISTS (?)", - MigrateKubernetesServiceToNewClustersArchitectures::PlatformsKubernetes - .joins('INNER JOIN projects ON projects.id = services.project_id') - .joins('INNER JOIN cluster_projects ON cluster_projects.project_id = projects.id') - .where('cluster_projects.cluster_id = cluster_platforms_kubernetes.cluster_id') - .where("services.properties LIKE CONCAT('%', cluster_platforms_kubernetes.api_url, '%')") - .select('1') ) - .order(project_id: :asc) - end - - scope :kubernetes_service_without_template, -> do - where(category: 'deployment') - .where(type: 'KubernetesService') - .where(template: false) - .order(project_id: :asc) + .where("services.properties LIKE '%api_url%'") + .where("(services.properties NOT LIKE CONCAT('%', cluster_platforms_kubernetes.api_url, '%')) OR cluster_platforms_kubernetes.api_url IS NULL") + .group(:id) + .order(id: :asc) end end @@ -148,7 +140,10 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati Gitlab::Database.bulk_insert('cluster_projects', rows_for_cluster_projects) end - MigrateKubernetesServiceToNewClustersArchitectures::Service.kubernetes_service_without_template.update_all(active: false) + connection.execute <<~SQL + UPDATE services SET active = false + WHERE category = 'deployment' AND type = 'KubernetesService' AND template = false + SQL end def down |