From e40b018bc73176429ceb1498b7d206c17eeb3e05 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Wed, 4 Oct 2017 12:42:28 +0300 Subject: Add a new migration to make sure that fast forward column exists in projects table --- ...827121444_add_fast_forward_option_to_project.rb | 4 +++- ...4121444_make_sure_fast_forward_option_exists.rb | 25 ++++++++++++++++++++++ db/schema.rb | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20171004121444_make_sure_fast_forward_option_exists.rb (limited to 'db') diff --git a/db/migrate/20150827121444_add_fast_forward_option_to_project.rb b/db/migrate/20150827121444_add_fast_forward_option_to_project.rb index e2293db9d08..6f22641077d 100644 --- a/db/migrate/20150827121444_add_fast_forward_option_to_project.rb +++ b/db/migrate/20150827121444_add_fast_forward_option_to_project.rb @@ -12,6 +12,8 @@ class AddFastForwardOptionToProject < ActiveRecord::Migration end def down - remove_column(:projects, :merge_requests_ff_only_enabled) + if column_exists?(:projects, :merge_requests_ff_only_enabled) + remove_column(:projects, :merge_requests_ff_only_enabled) + end end end diff --git a/db/migrate/20171004121444_make_sure_fast_forward_option_exists.rb b/db/migrate/20171004121444_make_sure_fast_forward_option_exists.rb new file mode 100644 index 00000000000..ac266c3e22e --- /dev/null +++ b/db/migrate/20171004121444_make_sure_fast_forward_option_exists.rb @@ -0,0 +1,25 @@ +# rubocop:disable all +class MakeSureFastForwardOptionExists < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # Set this constant to true if this migration requires downtime. + DOWNTIME = false + + disable_ddl_transaction! + + def up + # We had to fix the migration db/migrate/20150827121444_add_fast_forward_option_to_project.rb + # And this is why it's possible that someone has ran the migrations but does + # not have the merge_requests_ff_only_enabled column. This migration makes sure it will + # be added + unless column_exists?(:projects, :merge_requests_ff_only_enabled) + add_column_with_default(:projects, :merge_requests_ff_only_enabled, :boolean, default: false) + end + end + + def down + if column_exists?(:projects, :merge_requests_ff_only_enabled) + remove_column(:projects, :merge_requests_ff_only_enabled) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3428807dd7c..fa1aad257db 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: 20170928100231) do +ActiveRecord::Schema.define(version: 20171004121444) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -- cgit v1.2.3