Skip to content

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

Raise minimum PSQL version to 10, allowing leaner bigint migration

Oliver Günther3122e468ffe2
diff --git a/db/migrate/20220408080838_bigint_primary_key_on_relations.rb b/db/migrate/20220408080838_bigint_primary_key_on_relations.rb
index e16b5060993..1adf244af78 100644
--- a/db/migrate/20220408080838_bigint_primary_key_on_relations.rb
+++ b/db/migrate/20220408080838_bigint_primary_key_on_relations.rb
@@ -28,39 +28,17 @@
class BigintPrimaryKeyOnRelations < ActiveRecord::Migration[6.1]
def up
- change_relations_id(:bigint, 9223372036854775807)
- end
-
- def down
- change_relations_id(:integer, 2147483647)
- end
-
- private
+ unless OpenProject::Database.version_matches?(100000)
+ version = OpenProject::Database.version
+ raise "This migration requires a PostgreSQL server version of at least 10.0, found #{version}"
+ end
- def change_relations_id(type, maxvalue)
- # We cannot simply use
- #
- # ALTER SEQUENCE relations_id_seq AS bigint;
- #
- # since that is not supported by PostgreSQL 9.6.
execute <<~SQL.squish
- ALTER SEQUENCE relations_id_seq RENAME TO relations_id_seq_old;
-
- CREATE SEQUENCE IF NOT EXISTS relations_id_seq
- INCREMENT 1
- START 1
- MINVALUE 1
- MAXVALUE #{maxvalue}
- CACHE 1
- OWNED BY relations.id;
-
- SELECT setval('relations_id_seq', (SELECT MAX(id) + 1 FROM relations));
+ ALTER SEQUENCE relations_id_seq AS bigint;
SQL
+ end
- change_column :relations, :id, type, default: -> { "nextval('relations_id_seq')" }
-
- execute <<~SQL.squish
- DROP SEQUENCE relations_id_seq_old;
- SQL
+ def down
+ # nothing to do
end
end
diff --git a/docker/ci/Dockerfile b/docker/ci/Dockerfile
index 1d4b0a75e37..0412c6844d3 100644
--- a/docker/ci/Dockerfile
+++ b/docker/ci/Dockerfile
@@ -15,7 +15,7 @@ RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/a
RUN apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
- postgresql-9.6 postgresql-client-9.6 postgresql-13 postgresql-client-13 time pandoc imagemagick libpq-dev default-jre-headless firefox-esr
+ postgresql-10 postgresql-client-10 postgresql-13 postgresql-client-13 time pandoc imagemagick libpq-dev default-jre-headless firefox-esr
# Try Downloading binary from fallback source if first one fails
RUN for url in $CHROME_SOURCE_URL; do \
@@ -35,7 +35,7 @@ ENV CAPYBARA_DOWNLOADED_FILE_DIR=/tmp
# disable deprecations and other warnings in output
ENV RUBYOPT="-W0"
ENV DATABASE_URL=postgres://app:[email protected]/app
-ENV PGVERSION=9.6
+ENV PGVERSION=10
RUN gem install bundler --version "$BUNDLER_VERSION" --no-document
diff --git a/lib/open_project/database.rb b/lib/open_project/database.rb
index 72e71871058..a31228fc2b6 100644
--- a/lib/open_project/database.rb
+++ b/lib/open_project/database.rb
@@ -57,8 +57,8 @@ module OpenProject
# Get the database system requirements
def self.required_version
{
- numeric: 90500, # PG_VERSION_NUM
- string: '9.5.0'
+ numeric: 100000, # PG_VERSION_NUM
+ string: '10.0.0'
}
end