diff options
author | Nick Thomas <nick@gitlab.com> | 2018-01-16 18:19:20 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-01-16 18:19:20 +0000 |
commit | 19b76cd4d8e069f19068df16b6cd0dba930cf7aa (patch) | |
tree | e9331794f003354695af2c6c809e37144b558914 | |
parent | 66ae75600af3cdcaf67991b4ae0701d84de2f31a (diff) | |
parent | 58282e355a9047462cc102054657ee49c6fb0af7 (diff) | |
download | gitlab-ce-19b76cd4d8e069f19068df16b6cd0dba930cf7aa.tar.gz |
Merge branch '42047-pg-10-support' into 'master'
Resolve "postgresql 10 support for GitLab"
Closes #42047
See merge request gitlab-org/gitlab-ce!16471
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | changelogs/unreleased/42047-pg-10-support.yml | 5 | ||||
-rw-r--r-- | config/initializers/ar5_pg_10_support.rb | 57 | ||||
-rw-r--r-- | doc/install/requirements.md | 2 |
5 files changed, 66 insertions, 4 deletions
@@ -115,7 +115,7 @@ gem 'google-api-client', '~> 0.13.6' gem 'unf', '~> 0.1.4' # Seed data -gem 'seed-fu', '2.3.6' # Upgrade to > 2.3.7 once https://github.com/mbleigh/seed-fu/issues/123 is solved +gem 'seed-fu', '~> 2.3.7' # Markdown and HTML processing gem 'html-pipeline', '~> 1.11.0' diff --git a/Gemfile.lock b/Gemfile.lock index b83a3f0f7a4..10e2585a0e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -831,7 +831,7 @@ GEM rake (>= 0.9, < 13) sass (~> 3.5.3) securecompare (1.0.0) - seed-fu (2.3.6) + seed-fu (2.3.7) activerecord (>= 3.1) activesupport (>= 3.1) select2-rails (3.5.9.3) @@ -1170,7 +1170,7 @@ DEPENDENCIES sanitize (~> 2.0) sass-rails (~> 5.0.6) scss_lint (~> 0.56.0) - seed-fu (= 2.3.6) + seed-fu (~> 2.3.7) select2-rails (~> 3.5.9) selenium-webdriver (~> 3.5) sentry-raven (~> 2.5.3) diff --git a/changelogs/unreleased/42047-pg-10-support.yml b/changelogs/unreleased/42047-pg-10-support.yml new file mode 100644 index 00000000000..f98e59329c3 --- /dev/null +++ b/changelogs/unreleased/42047-pg-10-support.yml @@ -0,0 +1,5 @@ +--- +title: Support PostgreSQL 10 +merge_request: 16471 +author: +type: added diff --git a/config/initializers/ar5_pg_10_support.rb b/config/initializers/ar5_pg_10_support.rb new file mode 100644 index 00000000000..6fae770015c --- /dev/null +++ b/config/initializers/ar5_pg_10_support.rb @@ -0,0 +1,57 @@ +raise "Vendored ActiveRecord 5 code! Delete #{__FILE__}!" if ActiveRecord::VERSION::MAJOR >= 5 + +require 'active_record/connection_adapters/postgresql_adapter' +require 'active_record/connection_adapters/postgresql/schema_statements' + +# +# Monkey-patch the refused Rails 4.2 patch at https://github.com/rails/rails/pull/31330 +# +# Updates sequence logic to support PostgreSQL 10. +# +# rubocop:disable all +module ActiveRecord + module ConnectionAdapters + + # We need #postgresql_version to be public as in ActiveRecord 5 for seed_fu + # to work. In ActiveRecord 4, it is protected. + # https://github.com/mbleigh/seed-fu/issues/123 + class PostgreSQLAdapter + public :postgresql_version + end + + module PostgreSQL + module SchemaStatements + # Resets the sequence of a table's primary key to the maximum value. + def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc: + unless pk and sequence + default_pk, default_sequence = pk_and_sequence_for(table) + + pk ||= default_pk + sequence ||= default_sequence + end + + if @logger && pk && !sequence + @logger.warn "#{table} has primary key #{pk} with no default sequence" + end + + if pk && sequence + quoted_sequence = quote_table_name(sequence) + max_pk = select_value("SELECT MAX(#{quote_column_name pk}) FROM #{quote_table_name(table)}") + if max_pk.nil? + if postgresql_version >= 100000 + minvalue = select_value("SELECT seqmin FROM pg_sequence WHERE seqrelid = #{quote(quoted_sequence)}::regclass") + else + minvalue = select_value("SELECT min_value FROM #{quoted_sequence}") + end + end + + select_value <<-end_sql, 'SCHEMA' + SELECT setval(#{quote(quoted_sequence)}, #{max_pk ? max_pk : minvalue}, #{max_pk ? true : false}) + end_sql + end + end + end + end + end +end +# rubocop:enable all diff --git a/doc/install/requirements.md b/doc/install/requirements.md index baecf9455b0..272148033b5 100644 --- a/doc/install/requirements.md +++ b/doc/install/requirements.md @@ -121,7 +121,7 @@ Existing users using GitLab with MySQL/MariaDB are advised to ### PostgreSQL Requirements -As of GitLab 10.0, PostgreSQL 9.6 or newer (but less than 10) is required, and earlier versions are +As of GitLab 10.0, PostgreSQL 9.6 or newer is required, and earlier versions are not supported. We highly recommend users to use PostgreSQL 9.6 as this is the PostgreSQL version used for development and testing. |