diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-11-24 03:05:56 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-11-24 03:05:56 +0900 |
commit | 8ca6336155067b4c7cd11e4f36d5415a6414a145 (patch) | |
tree | b4141f652d12aae712cf9b12fe2fd00482f6b78b | |
parent | 7caa62e050049f774b3e282376b00cd438994e58 (diff) | |
download | gitlab-ce-fix/sm/40478-gcp_clusters_migration_culprit-1.tar.gz |
-rw-r--r-- | db/migrate/20171123104051_fix_cluster_platforms_kubernetes_association_mismatch.rb | 6 | ||||
-rw-r--r-- | spec/migrations/fix_cluster_platforms_kubernetes_association_mismatch_spec.rb | 27 |
2 files changed, 17 insertions, 16 deletions
diff --git a/db/migrate/20171123104051_fix_cluster_platforms_kubernetes_association_mismatch.rb b/db/migrate/20171123104051_fix_cluster_platforms_kubernetes_association_mismatch.rb index 01bafaa4539..ce893426211 100644 --- a/db/migrate/20171123104051_fix_cluster_platforms_kubernetes_association_mismatch.rb +++ b/db/migrate/20171123104051_fix_cluster_platforms_kubernetes_association_mismatch.rb @@ -16,12 +16,16 @@ class FixClusterPlatformsKubernetesAssociationMismatch < ActiveRecord::Migration class ProvidersGcp < ActiveRecord::Base self.table_name = 'cluster_providers_gcp' + + belongs_to :cluster, inverse_of: :provider_gcp, class_name: 'Cluster' end class PlatformsKubernetes < ActiveRecord::Base include EachBatch self.table_name = 'cluster_platforms_kubernetes' + + belongs_to :cluster, inverse_of: :platform_kubernetes, class_name: 'Cluster' end def up @@ -29,7 +33,7 @@ class FixClusterPlatformsKubernetesAssociationMismatch < ActiveRecord::Migration # This is the culprit. See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/15566 gcp_cluster = GcpCluster.find_by_id(platforms_kubernetes.cluster_id) - provider_gcp = ProvidersGcp.join(:clusters) + provider_gcp = ProvidersGcp.joins(:cluster) .where(gcp_project_id: gcp_cluster.gcp_project_id, zone: gcp_cluster.gcp_cluster_zone, num_nodes: gcp_cluster.gcp_cluster_size, diff --git a/spec/migrations/fix_cluster_platforms_kubernetes_association_mismatch_spec.rb b/spec/migrations/fix_cluster_platforms_kubernetes_association_mismatch_spec.rb index 15a9a8e2591..b1a3eea8e7e 100644 --- a/spec/migrations/fix_cluster_platforms_kubernetes_association_mismatch_spec.rb +++ b/spec/migrations/fix_cluster_platforms_kubernetes_association_mismatch_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb') require Rails.root.join('db', 'migrate', '20171123104051_fix_cluster_platforms_kubernetes_association_mismatch.rb') ## @@ -10,9 +11,10 @@ describe FixClusterPlatformsKubernetesAssociationMismatch, :migration do shared_examples 'expected behavior' do it 'has correct association' do + puts "described_class.name: #{described_class.name}" migrate! - Cluster.all.each do |cluster| + Clusters::Cluster.all.each do |cluster| expect(cluster.platform_kubernetes.api_url).to eq(api_url(cluster.provider_gcp.endpoint)) end end @@ -37,13 +39,8 @@ describe FixClusterPlatformsKubernetesAssociationMismatch, :migration do def prepare create_test_data - migrate_gcp_clusters_to_new_clusters_architectures! - end - def migrate_gcp_clusters_to_new_clusters_architectures! - ActiveRecord::Migrator.up(migrations_paths) do |migration| - migration.name == 'MigrateGcpClustersToNewClustersArchitectures' - end + MigrateGcpClustersToNewClustersArchitectures.new.up end def create_test_data @@ -65,18 +62,18 @@ describe FixClusterPlatformsKubernetesAssociationMismatch, :migration do project_namespace = "'sample-app-#{i}'" endpoint = "'111.111.111.#{i}'" ca_cert = "'ca_cert-#{i}'" - encrypted_kubernetes_token = "'NULL'" - encrypted_kubernetes_token_iv = "'NULL'" + encrypted_kubernetes_token = "'kubernetes_token-#{i}'" + encrypted_kubernetes_token_iv = "'kubernetes_token_iv-#{i}'" username = "'username-#{i}'" - encrypted_password = "'encrypted_password-#{i}'" - encrypted_password_iv = "'encrypted_password_iv-#{i}'" + encrypted_password = "'password_#{i}'" + encrypted_password_iv = "'password_iv_#{i}'" gcp_project_id = "'gcp_project_id-#{i}'" gcp_cluster_zone = "'gcp_cluster_zone-#{i}'" gcp_cluster_name = "'gcp_cluster_name-#{i}'" gcp_machine_type = "'gcp_machine_type-#{i}'" gcp_operation_id = "'gcp_operation_id-#{i}'" - encrypted_gcp_token = "'encrypted_gcp_token-#{i}'" - encrypted_gcp_token_iv = "'encrypted_gcp_token_iv-#{i}'" + encrypted_gcp_token = "'gcp_token_#{i}'" + encrypted_gcp_token_iv = "'gcp_token_iv_#{i}'" ActiveRecord::Base.connection.execute <<-SQL INSERT INTO gcp_clusters (project_id, user_id, service_id, status, gcp_cluster_size, created_at, updated_at, enabled, status_reason, project_namespace, endpoint, ca_cert, encrypted_kubernetes_token, encrypted_kubernetes_token_iv, username, encrypted_password, encrypted_password_iv, gcp_project_id, gcp_cluster_zone, gcp_cluster_name, gcp_machine_type, gcp_operation_id, encrypted_gcp_token, encrypted_gcp_token_iv) @@ -87,8 +84,8 @@ describe FixClusterPlatformsKubernetesAssociationMismatch, :migration do def culprit (1..5).each do |i| - cluster = Cluster.find_by_id(i) - cluster.platform_kubernetes.update!(cluster_id: (i % 5) + 1) + cluster = Clusters::Cluster.find_by_id(i) + cluster.platform_kubernetes.update_attribute(:cluster_id, (i % 5) + 1) end end |