From 0bb49b14dbac61d2148b7246c914d157ba75f14d Mon Sep 17 00:00:00 2001
From: Furkan Ayhan <furkanayhn@gmail.com>
Date: Fri, 23 Sep 2022 08:36:54 +0000
Subject: [PATCH] Remove and add raw of ci-variables tables with new default

We added raw attributes to all ci-variables tables with default true.
However, it has to be false because currently when you add a
project/group variable or a YAML variable,
their default raw value is false.

Changelog: other
---
 ...d_ci_pipeline_variables_raw_with_new_default.rb | 10 ++++++++++
 ..._add_ci_group_variables_raw_with_new_default.rb | 10 ++++++++++
 ...d_ci_instance_variables_raw_with_new_default.rb | 10 ++++++++++
 ...nd_add_ci_job_variables_raw_with_new_default.rb | 10 ++++++++++
 ...line_schedule_variables_raw_with_new_default.rb | 10 ++++++++++
 ...ve_and_add_ci_variables_raw_with_new_default.rb | 10 ++++++++++
 db/schema_migrations/20220921111823                |  1 +
 db/schema_migrations/20220921111831                |  1 +
 db/schema_migrations/20220921111840                |  1 +
 db/schema_migrations/20220921111849                |  1 +
 db/schema_migrations/20220921111857                |  1 +
 db/schema_migrations/20220921111907                |  1 +
 db/structure.sql                                   | 14 +++++++-------
 13 files changed, 73 insertions(+), 7 deletions(-)
 create mode 100644 db/post_migrate/20220921111823_remove_and_add_ci_pipeline_variables_raw_with_new_default.rb
 create mode 100644 db/post_migrate/20220921111831_remove_and_add_ci_group_variables_raw_with_new_default.rb
 create mode 100644 db/post_migrate/20220921111840_remove_and_add_ci_instance_variables_raw_with_new_default.rb
 create mode 100644 db/post_migrate/20220921111849_remove_and_add_ci_job_variables_raw_with_new_default.rb
 create mode 100644 db/post_migrate/20220921111857_remove_and_add_ci_pipeline_schedule_variables_raw_with_new_default.rb
 create mode 100644 db/post_migrate/20220921111907_remove_and_add_ci_variables_raw_with_new_default.rb
 create mode 100644 db/schema_migrations/20220921111823
 create mode 100644 db/schema_migrations/20220921111831
 create mode 100644 db/schema_migrations/20220921111840
 create mode 100644 db/schema_migrations/20220921111849
 create mode 100644 db/schema_migrations/20220921111857
 create mode 100644 db/schema_migrations/20220921111907

diff --git a/db/post_migrate/20220921111823_remove_and_add_ci_pipeline_variables_raw_with_new_default.rb b/db/post_migrate/20220921111823_remove_and_add_ci_pipeline_variables_raw_with_new_default.rb
new file mode 100644
index 000000000000..fd56a8f320af
--- /dev/null
+++ b/db/post_migrate/20220921111823_remove_and_add_ci_pipeline_variables_raw_with_new_default.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveAndAddCiPipelineVariablesRawWithNewDefault < Gitlab::Database::Migration[2.0]
+  enable_lock_retries!
+
+  def change
+    remove_column :ci_pipeline_variables, :raw, :boolean, null: false, default: true
+    add_column :ci_pipeline_variables, :raw, :boolean, null: false, default: false
+  end
+end
diff --git a/db/post_migrate/20220921111831_remove_and_add_ci_group_variables_raw_with_new_default.rb b/db/post_migrate/20220921111831_remove_and_add_ci_group_variables_raw_with_new_default.rb
new file mode 100644
index 000000000000..f4b7de3faf41
--- /dev/null
+++ b/db/post_migrate/20220921111831_remove_and_add_ci_group_variables_raw_with_new_default.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveAndAddCiGroupVariablesRawWithNewDefault < Gitlab::Database::Migration[2.0]
+  enable_lock_retries!
+
+  def change
+    remove_column :ci_group_variables, :raw, :boolean, null: false, default: true
+    add_column :ci_group_variables, :raw, :boolean, null: false, default: false
+  end
+end
diff --git a/db/post_migrate/20220921111840_remove_and_add_ci_instance_variables_raw_with_new_default.rb b/db/post_migrate/20220921111840_remove_and_add_ci_instance_variables_raw_with_new_default.rb
new file mode 100644
index 000000000000..019db1bbaa35
--- /dev/null
+++ b/db/post_migrate/20220921111840_remove_and_add_ci_instance_variables_raw_with_new_default.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveAndAddCiInstanceVariablesRawWithNewDefault < Gitlab::Database::Migration[2.0]
+  enable_lock_retries!
+
+  def change
+    remove_column :ci_instance_variables, :raw, :boolean, null: false, default: true
+    add_column :ci_instance_variables, :raw, :boolean, null: false, default: false
+  end
+end
diff --git a/db/post_migrate/20220921111849_remove_and_add_ci_job_variables_raw_with_new_default.rb b/db/post_migrate/20220921111849_remove_and_add_ci_job_variables_raw_with_new_default.rb
new file mode 100644
index 000000000000..736cd46382d9
--- /dev/null
+++ b/db/post_migrate/20220921111849_remove_and_add_ci_job_variables_raw_with_new_default.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveAndAddCiJobVariablesRawWithNewDefault < Gitlab::Database::Migration[2.0]
+  enable_lock_retries!
+
+  def change
+    remove_column :ci_job_variables, :raw, :boolean, null: false, default: true
+    add_column :ci_job_variables, :raw, :boolean, null: false, default: false
+  end
+end
diff --git a/db/post_migrate/20220921111857_remove_and_add_ci_pipeline_schedule_variables_raw_with_new_default.rb b/db/post_migrate/20220921111857_remove_and_add_ci_pipeline_schedule_variables_raw_with_new_default.rb
new file mode 100644
index 000000000000..159b0303d715
--- /dev/null
+++ b/db/post_migrate/20220921111857_remove_and_add_ci_pipeline_schedule_variables_raw_with_new_default.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveAndAddCiPipelineScheduleVariablesRawWithNewDefault < Gitlab::Database::Migration[2.0]
+  enable_lock_retries!
+
+  def change
+    remove_column :ci_pipeline_schedule_variables, :raw, :boolean, null: false, default: true
+    add_column :ci_pipeline_schedule_variables, :raw, :boolean, null: false, default: false
+  end
+end
diff --git a/db/post_migrate/20220921111907_remove_and_add_ci_variables_raw_with_new_default.rb b/db/post_migrate/20220921111907_remove_and_add_ci_variables_raw_with_new_default.rb
new file mode 100644
index 000000000000..129e5b1f0209
--- /dev/null
+++ b/db/post_migrate/20220921111907_remove_and_add_ci_variables_raw_with_new_default.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+class RemoveAndAddCiVariablesRawWithNewDefault < Gitlab::Database::Migration[2.0]
+  enable_lock_retries!
+
+  def change
+    remove_column :ci_variables, :raw, :boolean, null: false, default: true
+    add_column :ci_variables, :raw, :boolean, null: false, default: false
+  end
+end
diff --git a/db/schema_migrations/20220921111823 b/db/schema_migrations/20220921111823
new file mode 100644
index 000000000000..eeca2c10dada
--- /dev/null
+++ b/db/schema_migrations/20220921111823
@@ -0,0 +1 @@
+f06d7555d3541abbb9fd671df3718645203aef111674b91ad386dac434c4ede2
\ No newline at end of file
diff --git a/db/schema_migrations/20220921111831 b/db/schema_migrations/20220921111831
new file mode 100644
index 000000000000..a03ad3f67dd4
--- /dev/null
+++ b/db/schema_migrations/20220921111831
@@ -0,0 +1 @@
+a515d3e34f4b467c5e6fbd9b55135a676277ff6388eb1e3fc14df4b11d8eb3c0
\ No newline at end of file
diff --git a/db/schema_migrations/20220921111840 b/db/schema_migrations/20220921111840
new file mode 100644
index 000000000000..7e84d96f124e
--- /dev/null
+++ b/db/schema_migrations/20220921111840
@@ -0,0 +1 @@
+0fdbb888bdbd4f68619466a8f4384e44062b0cf854790c648a6a060ab1e71806
\ No newline at end of file
diff --git a/db/schema_migrations/20220921111849 b/db/schema_migrations/20220921111849
new file mode 100644
index 000000000000..3989dd78aeb5
--- /dev/null
+++ b/db/schema_migrations/20220921111849
@@ -0,0 +1 @@
+2041cb81c534be0cc45b1cc77fa7fd2e31615129e1ba60a146cca88d58b77605
\ No newline at end of file
diff --git a/db/schema_migrations/20220921111857 b/db/schema_migrations/20220921111857
new file mode 100644
index 000000000000..578b2c853f46
--- /dev/null
+++ b/db/schema_migrations/20220921111857
@@ -0,0 +1 @@
+cbef1d036abb0035d710cf912e554e32fa88df3abaed17cb938e0b18032c7448
\ No newline at end of file
diff --git a/db/schema_migrations/20220921111907 b/db/schema_migrations/20220921111907
new file mode 100644
index 000000000000..013f79024c90
--- /dev/null
+++ b/db/schema_migrations/20220921111907
@@ -0,0 +1 @@
+fbc4c12aedd9d0f183e9444f2cb42c11a2b894c11684e80a5dbe847c7bccb21f
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 7cbe648f4f02..0f6ff043d6e6 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -12772,7 +12772,7 @@ CREATE TABLE ci_group_variables (
     masked boolean DEFAULT false NOT NULL,
     variable_type smallint DEFAULT 1 NOT NULL,
     environment_scope text DEFAULT '*'::text NOT NULL,
-    raw boolean DEFAULT true NOT NULL,
+    raw boolean DEFAULT false NOT NULL,
     CONSTRAINT check_dfe009485a CHECK ((char_length(environment_scope) <= 255))
 );
 
@@ -12793,7 +12793,7 @@ CREATE TABLE ci_instance_variables (
     key text NOT NULL,
     encrypted_value text,
     encrypted_value_iv text,
-    raw boolean DEFAULT true NOT NULL,
+    raw boolean DEFAULT false NOT NULL,
     CONSTRAINT check_07a45a5bcb CHECK ((char_length(encrypted_value_iv) <= 255)),
     CONSTRAINT check_5aede12208 CHECK ((char_length(key) <= 255)),
     CONSTRAINT check_956afd70f1 CHECK ((char_length(encrypted_value) <= 13579))
@@ -12875,7 +12875,7 @@ CREATE TABLE ci_job_variables (
     job_id bigint NOT NULL,
     variable_type smallint DEFAULT 1 NOT NULL,
     source smallint DEFAULT 0 NOT NULL,
-    raw boolean DEFAULT true NOT NULL
+    raw boolean DEFAULT false NOT NULL
 );
 
 CREATE SEQUENCE ci_job_variables_id_seq
@@ -13057,7 +13057,7 @@ CREATE TABLE ci_pipeline_schedule_variables (
     created_at timestamp with time zone,
     updated_at timestamp with time zone,
     variable_type smallint DEFAULT 1 NOT NULL,
-    raw boolean DEFAULT true NOT NULL
+    raw boolean DEFAULT false NOT NULL
 );
 
 CREATE SEQUENCE ci_pipeline_schedule_variables_id_seq
@@ -13101,8 +13101,8 @@ CREATE TABLE ci_pipeline_variables (
     encrypted_value_iv character varying,
     pipeline_id integer NOT NULL,
     variable_type smallint DEFAULT 1 NOT NULL,
-    raw boolean DEFAULT true NOT NULL,
-    partition_id bigint DEFAULT 100 NOT NULL
+    partition_id bigint DEFAULT 100 NOT NULL,
+    raw boolean DEFAULT false NOT NULL
 );
 
 CREATE SEQUENCE ci_pipeline_variables_id_seq
@@ -13564,7 +13564,7 @@ CREATE TABLE ci_variables (
     environment_scope character varying DEFAULT '*'::character varying NOT NULL,
     masked boolean DEFAULT false NOT NULL,
     variable_type smallint DEFAULT 1 NOT NULL,
-    raw boolean DEFAULT true NOT NULL
+    raw boolean DEFAULT false NOT NULL
 );
 
 CREATE SEQUENCE ci_variables_id_seq
-- 
GitLab