Commit f2b51a25 authored by Thong Kuah's avatar Thong Kuah
Browse files

Null out version values we cannot know if it matches the actual helm chart...

Null out version values we cannot know if it matches the actual helm chart version installed on the actual environment

Alter schema for each `Clusters::Applications` so that the version
column can be nil.
parent 50352503
---
title: Remove incorrect version values in the database for cluster applications
merge_request: 20826
author:
type: fixed
# 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
# 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
# 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
# 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
# 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
......@@ -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
......
# 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
# 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
# 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
# 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment