summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThong Kuah <tkuah@gitlab.com>2018-07-25 12:25:45 +1200
committerThong Kuah <tkuah@gitlab.com>2018-07-26 13:29:37 +1200
commitf2b51a25d90350c365160c453b209313722bde2b (patch)
treec46876564552338f6174bb50e4a9cd45ecdb1506
parent5035250337427baa1f6462ee4b1c004f529d765c (diff)
downloadgitlab-ce-49580-nullify-bad-clusters-applications-version-values.tar.gz
Null out version values we cannot know if it matches the actual helm chart version installed on the actual environment49580-nullify-bad-clusters-applications-version-values
Alter schema for each `Clusters::Applications` so that the version column can be nil.
-rw-r--r--changelogs/unreleased/49580-nullify-bad-clusters-applications-version-values.yml5
-rw-r--r--db/migrate/20180724235301_nullify_clusters_applications.rb15
-rw-r--r--db/migrate/20180725004652_null_out_clusters_application_ingress_version.rb18
-rw-r--r--db/migrate/20180725005445_null_out_clusters_applications_jupyter_version.rb18
-rw-r--r--db/migrate/20180725010623_null_out_clusters_applications_runners_version.rb18
-rw-r--r--db/migrate/20180725011345_null_out_clusters_applications_prometheus_version.rb20
-rw-r--r--db/schema.rb10
-rw-r--r--spec/migrations/null_out_clusters_application_ingress_version_spec.rb20
-rw-r--r--spec/migrations/null_out_clusters_applications_jupyter_version_spec.rb20
-rw-r--r--spec/migrations/null_out_clusters_applications_prometheus_version_spec.rb23
-rw-r--r--spec/migrations/null_out_clusters_applications_runners_version_spec.rb20
11 files changed, 182 insertions, 5 deletions
diff --git a/changelogs/unreleased/49580-nullify-bad-clusters-applications-version-values.yml b/changelogs/unreleased/49580-nullify-bad-clusters-applications-version-values.yml
new file mode 100644
index 00000000000..a3ec0f1d9ee
--- /dev/null
+++ b/changelogs/unreleased/49580-nullify-bad-clusters-applications-version-values.yml
@@ -0,0 +1,5 @@
+---
+title: Remove incorrect version values in the database for cluster applications
+merge_request: 20826
+author:
+type: fixed
diff --git a/db/migrate/20180724235301_nullify_clusters_applications.rb b/db/migrate/20180724235301_nullify_clusters_applications.rb
new file mode 100644
index 00000000000..b482b1087db
--- /dev/null
+++ b/db/migrate/20180724235301_nullify_clusters_applications.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+class NullifyClustersApplications < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ def change
+ change_column_null :clusters_applications_ingress, :version, true
+ change_column_null :clusters_applications_jupyter, :version, true
+ change_column_null :clusters_applications_prometheus, :version, true
+ change_column_null :clusters_applications_runners, :version, true
+ end
+end
diff --git a/db/migrate/20180725004652_null_out_clusters_application_ingress_version.rb b/db/migrate/20180725004652_null_out_clusters_application_ingress_version.rb
new file mode 100644
index 00000000000..fdcf44a942d
--- /dev/null
+++ b/db/migrate/20180725004652_null_out_clusters_application_ingress_version.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class NullOutClustersApplicationIngressVersion < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ update_column_in_batches(:clusters_applications_ingress, :version, nil)
+ end
+
+ def down
+ # we cannot know the previous value for sure
+ end
+end
diff --git a/db/migrate/20180725005445_null_out_clusters_applications_jupyter_version.rb b/db/migrate/20180725005445_null_out_clusters_applications_jupyter_version.rb
new file mode 100644
index 00000000000..06b16a3580a
--- /dev/null
+++ b/db/migrate/20180725005445_null_out_clusters_applications_jupyter_version.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class NullOutClustersApplicationsJupyterVersion < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ update_column_in_batches(:clusters_applications_jupyter, :version, nil)
+ end
+
+ def down
+ # we cannot know the previous value for sure
+ end
+end
diff --git a/db/migrate/20180725010623_null_out_clusters_applications_runners_version.rb b/db/migrate/20180725010623_null_out_clusters_applications_runners_version.rb
new file mode 100644
index 00000000000..a41535fa7b1
--- /dev/null
+++ b/db/migrate/20180725010623_null_out_clusters_applications_runners_version.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class NullOutClustersApplicationsRunnersVersion < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ update_column_in_batches(:clusters_applications_runners, :version, nil)
+ end
+
+ def down
+ # we cannot know the previous value for sure
+ end
+end
diff --git a/db/migrate/20180725011345_null_out_clusters_applications_prometheus_version.rb b/db/migrate/20180725011345_null_out_clusters_applications_prometheus_version.rb
new file mode 100644
index 00000000000..8b93e0bbb0a
--- /dev/null
+++ b/db/migrate/20180725011345_null_out_clusters_applications_prometheus_version.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class NullOutClustersApplicationsPrometheusVersion < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ update_column_in_batches(:clusters_applications_prometheus, :version, nil) do |table, query|
+ query.where(table[:version].not_eq('6.7.3'))
+ end
+ end
+
+ def down
+ # we cannot know the previous value for sure
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8ae0197d1b4..848910a8625 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20180722103201) do
+ActiveRecord::Schema.define(version: 20180725011345) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -643,7 +643,7 @@ ActiveRecord::Schema.define(version: 20180722103201) do
t.datetime_with_timezone "updated_at", null: false
t.integer "status", null: false
t.integer "ingress_type", null: false
- t.string "version", null: false
+ t.string "version"
t.string "cluster_ip"
t.text "status_reason"
t.string "external_ip"
@@ -653,7 +653,7 @@ ActiveRecord::Schema.define(version: 20180722103201) do
t.integer "cluster_id", null: false
t.integer "oauth_application_id"
t.integer "status", null: false
- t.string "version", null: false
+ t.string "version"
t.string "hostname"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
@@ -663,7 +663,7 @@ ActiveRecord::Schema.define(version: 20180722103201) do
create_table "clusters_applications_prometheus", force: :cascade do |t|
t.integer "cluster_id", null: false
t.integer "status", null: false
- t.string "version", null: false
+ t.string "version"
t.text "status_reason"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
@@ -675,7 +675,7 @@ ActiveRecord::Schema.define(version: 20180722103201) do
t.integer "status", null: false
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
- t.string "version", null: false
+ t.string "version"
t.text "status_reason"
t.boolean "privileged", default: true, null: false
end
diff --git a/spec/migrations/null_out_clusters_application_ingress_version_spec.rb b/spec/migrations/null_out_clusters_application_ingress_version_spec.rb
new file mode 100644
index 00000000000..00f9e9c48e7
--- /dev/null
+++ b/spec/migrations/null_out_clusters_application_ingress_version_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20180725004652_null_out_clusters_application_ingress_version.rb')
+
+describe NullOutClustersApplicationIngressVersion, :migration do
+ let(:applications) { table(:clusters_applications_ingress) }
+ let(:clusters) { table(:clusters) }
+
+ before do
+ cluster = clusters.create!(id: 123, name: 'hello')
+ applications.create!(id: 123, status: 'installed', ingress_type: 1, version: 'nginx', cluster_id: cluster.id)
+ end
+
+ it 'nulls out the version column' do
+ migrate!
+
+ expect(applications.first.version).to be_nil
+ end
+end
diff --git a/spec/migrations/null_out_clusters_applications_jupyter_version_spec.rb b/spec/migrations/null_out_clusters_applications_jupyter_version_spec.rb
new file mode 100644
index 00000000000..7572e419fed
--- /dev/null
+++ b/spec/migrations/null_out_clusters_applications_jupyter_version_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20180725005445_null_out_clusters_applications_jupyter_version.rb')
+
+describe NullOutClustersApplicationsJupyterVersion, :migration do
+ let(:applications) { table(:clusters_applications_jupyter) }
+ let(:clusters) { table(:clusters) }
+
+ before do
+ cluster = clusters.create!(id: 123, name: 'hello')
+ applications.create!(id: 123, status: 'installed', version: '0.0.1', cluster_id: cluster.id)
+ end
+
+ it 'nulls out the version column' do
+ migrate!
+
+ expect(applications.first.version).to be_nil
+ end
+end
diff --git a/spec/migrations/null_out_clusters_applications_prometheus_version_spec.rb b/spec/migrations/null_out_clusters_applications_prometheus_version_spec.rb
new file mode 100644
index 00000000000..98964c3a05d
--- /dev/null
+++ b/spec/migrations/null_out_clusters_applications_prometheus_version_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20180725011345_null_out_clusters_applications_prometheus_version.rb')
+
+describe NullOutClustersApplicationsPrometheusVersion, :migration do
+ let(:applications) { table(:clusters_applications_prometheus) }
+ let(:clusters) { table(:clusters) }
+
+ before do
+ cluster = clusters.create!(id: 123, name: 'hello')
+ applications.create!(id: 123, status: 'installed', version: '2.0.0', cluster_id: cluster.id)
+ applications.create!(id: 124, status: 'installed', version: '6.7.3', cluster_id: cluster.id)
+ end
+
+ it 'nulls out the version column' do
+ expect(applications.count).to eq 2
+
+ migrate!
+
+ expect(applications.pluck(:version)).to match_array [nil, '6.7.3']
+ end
+end
diff --git a/spec/migrations/null_out_clusters_applications_runners_version_spec.rb b/spec/migrations/null_out_clusters_applications_runners_version_spec.rb
new file mode 100644
index 00000000000..0e26a9368b8
--- /dev/null
+++ b/spec/migrations/null_out_clusters_applications_runners_version_spec.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'migrate', '20180725010623_null_out_clusters_applications_runners_version.rb')
+
+describe NullOutClustersApplicationsRunnersVersion, :migration do
+ let(:applications) { table(:clusters_applications_runners) }
+ let(:clusters) { table(:clusters) }
+
+ before do
+ cluster = clusters.create!(id: 123, name: 'hello')
+ applications.create!(id: 123, status: 'installed', version: '0.1.13', cluster_id: cluster.id)
+ end
+
+ it 'nulls out the version column' do
+ migrate!
+
+ expect(applications.first.version).to be_nil
+ end
+end