From 2246218cc00e1f8db92cae7234131ca00943f567 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 2 Sep 2016 15:24:19 +0200 Subject: Remove gitorious from import_sources on ApplicationSetting model --- CHANGELOG | 1 + ...op_gitorious_field_from_application_settings.rb | 31 ++++++++++++++++++++++ db/schema.rb | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb diff --git a/CHANGELOG b/CHANGELOG index 3f52fab74d7..f54a17e1ea2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -90,6 +90,7 @@ v 8.11.5 (unreleased) - Fix member expiration date picker after update - Fix suggested colors options for new labels in the admin area. !6138 - Fix GitLab import button + - Remove gitorious from import_sources v 8.11.4 - Fix resolving conflicts on forks. !6082 diff --git a/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb b/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb new file mode 100644 index 00000000000..5395d38ea8f --- /dev/null +++ b/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb @@ -0,0 +1,31 @@ +class DropGitoriousFieldFromApplicationSettings < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + # After the deploy the caches will be cold anyway + DOWNTIME = false + + def up + require 'yaml' + + yaml = connection.execute('SELECT import_sources FROM application_settings;').values[0][0] + yaml = YAML.safe_load(yaml) + yaml.delete 'gitorious' + + # No need for a WHERE clause as there is only one + connection.execute("UPDATE application_settings SET import_sources = #{update_yaml(yaml)}") + end + + def down + # noop, gitorious still yields a 404 anyway + end + + private + + def connection + ActiveRecord::Base.connection + end + + def update_yaml(yaml) + connection.quote(YAML.dump(yaml)) + end +end diff --git a/db/schema.rb b/db/schema.rb index c9023a02c77..5c283141084 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: 20160901141443) do +ActiveRecord::Schema.define(version: 20160902122721) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -- cgit v1.2.1 From e683eecdd99748f4b08359e2e979f94bf8ab5792 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 2 Sep 2016 22:36:20 +0200 Subject: Support MySQL too, when removing gitorious from import_sources --- ...20160902122721_drop_gitorious_field_from_application_settings.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb b/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb index 5395d38ea8f..3342744ba93 100644 --- a/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb +++ b/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb @@ -7,7 +7,11 @@ class DropGitoriousFieldFromApplicationSettings < ActiveRecord::Migration def up require 'yaml' - yaml = connection.execute('SELECT import_sources FROM application_settings;').values[0][0] + yaml = if Gitlab::Database.postgresql? + connection.execute('SELECT import_sources FROM application_settings;').values[0][0] + else + connection.execute('SELECT import_sources FROM application_settings;').first[0] + end yaml = YAML.safe_load(yaml) yaml.delete 'gitorious' -- cgit v1.2.1 From 5204911f610c4062ce7d831e8182b0e959eda17c Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 5 Sep 2016 19:29:49 +0200 Subject: Don't fail on an empty database --- ...2721_drop_gitorious_field_from_application_settings.rb | 15 ++++++++++----- db/schema.rb | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb b/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb index 3342744ba93..b7b6e9b3484 100644 --- a/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb +++ b/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb @@ -7,11 +7,16 @@ class DropGitoriousFieldFromApplicationSettings < ActiveRecord::Migration def up require 'yaml' - yaml = if Gitlab::Database.postgresql? - connection.execute('SELECT import_sources FROM application_settings;').values[0][0] - else - connection.execute('SELECT import_sources FROM application_settings;').first[0] - end + import_sources = connection.execute('SELECT import_sources FROM application_settings;') + + yaml = if Gitlab::Database.postgresql? + import_sources.values[0][0] + else + return unless import_sources.first + + import_sources.first[0] + end + yaml = YAML.safe_load(yaml) yaml.delete 'gitorious' diff --git a/db/schema.rb b/db/schema.rb index 5c283141084..c9023a02c77 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: 20160902122721) do +ActiveRecord::Schema.define(version: 20160901141443) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -- cgit v1.2.1