diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-04 10:14:06 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-01-04 10:14:06 +0000 |
commit | ac409fb44402622dfd6abb076f7a85df4b27d39d (patch) | |
tree | e32e266d1ab620e70486926f31bafcc4e3e7ae88 /db | |
parent | b1e1990ee263bcae73f0e55526a55cff66103220 (diff) | |
parent | 78d22fb20db14c90861318b9f316466fbf002114 (diff) | |
download | gitlab-ce-ac409fb44402622dfd6abb076f7a85df4b27d39d.tar.gz |
Merge branch 'change-issues-closed-at-background-migration' into 'master'
Use a background migration for migrating issues.closed_at
See merge request gitlab-org/gitlab-ce!16083
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb | 45 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 46 insertions, 1 deletions
diff --git a/db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb b/db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb new file mode 100644 index 00000000000..be18c5866ae --- /dev/null +++ b/db/post_migrate/20171221140220_schedule_issues_closed_at_type_change.rb @@ -0,0 +1,45 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class ScheduleIssuesClosedAtTypeChange < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + class Issue < ActiveRecord::Base + self.table_name = 'issues' + include EachBatch + + def self.to_migrate + where('closed_at IS NOT NULL') + end + end + + def up + return unless migrate_column_type? + + change_column_type_using_background_migration( + Issue.to_migrate, + :closed_at, + :datetime_with_timezone + ) + end + + def down + return if migrate_column_type? + + change_column_type_using_background_migration( + Issue.to_migrate, + :closed_at, + :datetime + ) + end + + def migrate_column_type? + # Some environments may have already executed the previous version of this + # migration, thus we don't need to migrate those environments again. + column_for('issues', 'closed_at').type == :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 9d3b5db117e..925629f28fb 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: 20171220191323) do +ActiveRecord::Schema.define(version: 20171221140220) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |