From 3f62e0b2a483025d041c90d76b16f3f8e009553a Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre <dbalexandre@gmail.com> Date: Wed, 29 Apr 2020 15:20:16 -0300 Subject: [PATCH] Add default values for file store columns The lfs_objects, ci_job_artifacts, and uploads table does not have a default value for the file store columns. To avoid the madness of three-state booleans where it can be true, false, or NULL we are setting a default value for these records. --- ...ult_value_for_file_store_to_lfs_objects.rb | 19 +++++++++++++++++++ ...alue_for_file_store_to_ci_job_artifacts.rb | 19 +++++++++++++++++++ ..._add_default_value_for_store_to_uploads.rb | 19 +++++++++++++++++++ db/structure.sql | 9 ++++++--- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20200429181335_add_default_value_for_file_store_to_lfs_objects.rb create mode 100644 db/migrate/20200429181955_add_default_value_for_file_store_to_ci_job_artifacts.rb create mode 100644 db/migrate/20200429182245_add_default_value_for_store_to_uploads.rb diff --git a/db/migrate/20200429181335_add_default_value_for_file_store_to_lfs_objects.rb b/db/migrate/20200429181335_add_default_value_for_file_store_to_lfs_objects.rb new file mode 100644 index 0000000000000..f316a092bfca3 --- /dev/null +++ b/db/migrate/20200429181335_add_default_value_for_file_store_to_lfs_objects.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDefaultValueForFileStoreToLfsObjects < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + change_column_default :lfs_objects, :file_store, 1 + end + end + + def down + with_lock_retries do + change_column_default :lfs_objects, :file_store, nil + end + end +end diff --git a/db/migrate/20200429181955_add_default_value_for_file_store_to_ci_job_artifacts.rb b/db/migrate/20200429181955_add_default_value_for_file_store_to_ci_job_artifacts.rb new file mode 100644 index 0000000000000..ac3d5e41e3ebe --- /dev/null +++ b/db/migrate/20200429181955_add_default_value_for_file_store_to_ci_job_artifacts.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDefaultValueForFileStoreToCiJobArtifacts < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + change_column_default :ci_job_artifacts, :file_store, 1 + end + end + + def down + with_lock_retries do + change_column_default :ci_job_artifacts, :file_store, nil + end + end +end diff --git a/db/migrate/20200429182245_add_default_value_for_store_to_uploads.rb b/db/migrate/20200429182245_add_default_value_for_store_to_uploads.rb new file mode 100644 index 0000000000000..f28fcce8f2f34 --- /dev/null +++ b/db/migrate/20200429182245_add_default_value_for_store_to_uploads.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class AddDefaultValueForStoreToUploads < ActiveRecord::Migration[6.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + with_lock_retries do + change_column_default :uploads, :store, 1 + end + end + + def down + with_lock_retries do + change_column_default :uploads, :store, nil + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 73edcc371ce60..e450a99eace6e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1120,7 +1120,7 @@ CREATE TABLE public.ci_job_artifacts ( updated_at timestamp with time zone NOT NULL, expire_at timestamp with time zone, file character varying, - file_store integer, + file_store integer DEFAULT 1, file_sha256 bytea, file_format smallint, file_location smallint, @@ -3644,7 +3644,7 @@ CREATE TABLE public.lfs_objects ( created_at timestamp without time zone, updated_at timestamp without time zone, file character varying, - file_store integer + file_store integer DEFAULT 1 ); CREATE SEQUENCE public.lfs_objects_id_seq @@ -6487,7 +6487,7 @@ CREATE TABLE public.uploads ( model_type character varying, uploader character varying NOT NULL, created_at timestamp without time zone NOT NULL, - store integer, + store integer DEFAULT 1, mount_point character varying, secret character varying ); @@ -13706,5 +13706,8 @@ COPY "schema_migrations" (version) FROM STDIN; 20200424101920 20200427064130 20200429015603 +20200429181335 +20200429181955 +20200429182245 \. -- GitLab