OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Set statement_timeout to 0 when running migrations (#13818)
Oliver Güntheracbc421ba54b
diff --git a/config/initializers/migration_statement_timeout.rb b/config/initializers/migration_statement_timeout.rbdeleted file mode 100644index 338674fe3a1..00000000000--- a/config/initializers/migration_statement_timeout.rb+++ /dev/null@@ -1,35 +0,0 @@-# frozen_string_literal: true--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--require_relative '../../lib_static/open_project/migration_statement_timeout/manager'-require_relative '../../lib_static/open_project/migration_statement_timeout/migration_extensions'--ActiveRecord::Migration.prepend(MigrationStatementTimeout::Manager)-ActiveRecord::Migration.extend(MigrationStatementTimeout::MigrationExtensions)diff --git a/db/migrate/20230608151123_add_validity_period_to_journals.rb b/db/migrate/20230608151123_add_validity_period_to_journals.rbindex e2b86ce8644..6a65e62ab87 100644--- a/db/migrate/20230608151123_add_validity_period_to_journals.rb+++ b/db/migrate/20230608151123_add_validity_period_to_journals.rb@@ -1,6 +1,4 @@class AddValidityPeriodToJournals < ActiveRecord::Migration[7.0]- set_minimum_statement_timeout('15min')-def changeadd_column :journals, :validity_period, :tstzrangediff --git a/docs/installation-and-operations/operation/upgrading/README.md b/docs/installation-and-operations/operation/upgrading/README.mdindex 98ad034c339..2550593cbd0 100644--- a/docs/installation-and-operations/operation/upgrading/README.md+++ b/docs/installation-and-operations/operation/upgrading/README.md@@ -12,8 +12,7 @@ sidebar_navigation:| ------------------------------------------------------------ | ------------------------------------------------------------ || [Package-based installation](#package-based-installation-debrpm) | How to upgrade a package-based installation of OpenProject. || [Docker-based installation](#compose-based-installation) | How to upgrade a Docker-based installation of OpenProject. |-| [Troubleshooting](#troubleshooting) | Solutions for common problems |-| [Upgrade notes to 13.x](#upgrade-notes-to-13x) | How to upgrade from OpenProject 9.x or greater to OpenProject 12.x. |+| [Upgrade notes from 9.x](#upgrade-notes-from-9x) | How to upgrade from OpenProject 9.x or greater to OpenProject 13.x and higher || [Upgrade notes for 8.x to 9.x](#upgrade-notes-for-8x-to-9x) | How to upgrade from OpenProject 8.x to OpenProject 9.x. || [Upgrade notes for 7.x to 8.x](#upgrade-notes-for-openproject-7x-to-8x) | How to upgrade from OpenProject 7.x to OpenProject 8.x. |@@ -162,20 +161,7 @@ sudo chown -R 102 /volume1/openproject/*After that it's simply a matter of launching the new container mounted with the copied `pgdata` and `assets` foldersas described in the [installation section](../../installation/docker/#one-container-per-process-recommended).---## Troubleshooting--**Question: My upgrade fails due to these errors: `PG::QueryCanceled: canceling statement due to statement timeout`**--Your migrations are exceeding the assigned statement timeout of your PostgreSQL database. The default time might vary from your installation, but you can customize the timeout for the duration of the migrations by setting the following environment variable (e.g., setting the value to 1 hour):--- **Packaged installations:** `openproject config:set POSTGRES_STATEMENT_TIMEOUT=60min`-- **Docker-based / Compose / Helm installations** Add `POSTGRES_STATEMENT_TIMEOUT=60min` to your environment.--After you set the environment flag, re-deploy your containers or restart the failing upgrade command again.--## Upgrade notes to 13.x+## Upgrade notes from 9.xGenerally, there are no special steps or caveats when upgrading to OpenProject 13.x or higher from any version greater than 9.x. Simply follow the upgrade steps outlined above for your type of installation.diff --git a/lib/tasks/database.rake b/lib/tasks/database.rakeindex c8ead032c70..3a57f8e937c 100644--- a/lib/tasks/database.rake+++ b/lib/tasks/database.rake@@ -97,7 +97,12 @@ namespace 'openproject' dowarn "Failed to perform postgres version check: #{e} - #{e.message}. #{override_msg}"raise eend++ task remove_statement_timeout: %w[openproject:db:check_connection] do+ ActiveRecord::Base.connection.execute("SET statement_timeout = 0;")+ endendendRake::Task["db:migrate"].enhance ["openproject:db:ensure_database_compatibility"]+Rake::Task["db:migrate"].enhance ["openproject:db:remove_statement_timeout"]diff --git a/lib_static/open_project/migration_statement_timeout/manager.rb b/lib_static/open_project/migration_statement_timeout/manager.rbdeleted file mode 100644index 98010514343..00000000000--- a/lib_static/open_project/migration_statement_timeout/manager.rb+++ /dev/null@@ -1,116 +0,0 @@-# frozen_string_literal: true--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module MigrationStatementTimeout- module Manager- class SetMinimumStatementTimeout- attr_reader :conn-- def initialize(conn, migration)- @conn = conn- @migration = migration- end-- delegate :say, to: :@migration-- def call(min_timeout)- if same_timeout?(min_timeout)- say "ignore set statement_timeout to #{min_timeout}: " \- "current statement timeout is already #{current_timeout}"- elsif current_timeout_disabled?- say "ignore set statement_timeout to #{min_timeout}: " \- "current statement timeout is disabled (value is 0)"- elsif current_timeout_is_greater_than?(min_timeout)- say "ignore set statement_timeout to #{min_timeout}: " \- "current statement timeout #{current_timeout} is greater"- else- set_timeout(min_timeout)- say "set statement_timeout to #{min_timeout} (was #{current_timeout} before)"- end- end-- def current_timeout_disabled?- in_ms(current_timeout).zero?- end-- def same_timeout?(min_timeout)- in_ms(current_timeout) == in_ms(min_timeout)- end-- def current_timeout_is_greater_than?(min_timeout)- in_ms(min_timeout).positive? && in_ms(current_timeout) > in_ms(min_timeout)- end-- def current_timeout- @current_timeout ||= get_timeout- end-- def get_timeout- conn.execute('SHOW statement_timeout').first['statement_timeout']- end-- def set_timeout(timeout)- conn.execute("SET LOCAL statement_timeout = '#{timeout}'")- end-- def in_ms(timeout)- case timeout- when Integer- timeout- when /\A\d+(ms)?\z/- timeout.to_i- when /\A\d+s\z/- timeout.to_i * 1000- when /\A\d+min\z/- timeout.to_i * 1000 * 60- when /\A\d+h\z/- timeout.to_i * 1000 * 60 * 60- else- raise ArgumentError, "Unrecognized statement timeout duration #{timeout.inspect}"- end- end- end-- def exec_migration(conn, direction)- min_timeout = self.class.minimum_statement_timeout- return super unless min_timeout- return super unless direction == :up-- if disable_ddl_transaction- raise 'Cannot set local statement_timeout outside of a transaction. ' \- 'Try removing disable_ddl_transaction! from your migration.'- end-- SetMinimumStatementTimeout.new(conn, self).call(min_timeout)-- super- end- end-enddiff --git a/lib_static/open_project/migration_statement_timeout/migration_extensions.rb b/lib_static/open_project/migration_statement_timeout/migration_extensions.rbdeleted file mode 100644index 19f7c20a831..00000000000--- a/lib_static/open_project/migration_statement_timeout/migration_extensions.rb+++ /dev/null@@ -1,53 +0,0 @@-# frozen_string_literal: true--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 the OpenProject GmbH-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License version 3.-#-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:-# Copyright (C) 2006-2013 Jean-Philippe Lang-# Copyright (C) 2010-2013 the ChiliProject Team-#-# This program is free software; you can redistribute it and/or-# modify it under the terms of the GNU General Public License-# as published by the Free Software Foundation; either version 2-# of the License, or (at your option) any later version.-#-# This program is distributed in the hope that it will be useful,-# but WITHOUT ANY WARRANTY; without even the implied warranty of-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-# GNU General Public License for more details.-#-# You should have received a copy of the GNU General Public License-# along with this program; if not, write to the Free Software-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.-#-# See COPYRIGHT and LICENSE files for more details.-#++--module MigrationStatementTimeout- module MigrationExtensions- attr_accessor :minimum_statement_timeout-- # Sets the minimum statement timeout for this migration.- #- # If the current statement timeout is lower than the given value, it will be- # set to this value. It does nothing if the statement timeout is already set- # to a higher value.- #- # When the given value is an integer or a string without units, it is- # interpreted as milliseconds.- #- # When the given value is a string with units, it is interpreted- # accordingly. Valid units for this parameter are "ms", "s", "min", and "h".- # Examples: "15min", "90s", "2h".- #- # @param [Integer|String] timeout duration- def set_minimum_statement_timeout(timeout)- self.minimum_statement_timeout = timeout- end- end-end