[Git][noosfero/noosfero][master] 2 commits: adding backport to run with postgres 10

Leandro Nunes gitlab at mg.gitlab.com
Thu Feb 21 11:19:11 BRT 2019


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
766aef0f by Leandro Nunes dos Santos at 2019-02-06T11:59:06Z
adding backport to run with postgres 10

- - - - -
5e7cae06 by Leandro Nunes at 2019-02-21T14:18:55Z
Merge branch 'backport-pg-10' into 'master'

adding backport to run with postgres 10

See merge request noosfero/noosfero!1671
- - - - -


1 changed file:

- + config/initializers/backport_pg_10_support_to_rails_4.rb


Changes:

=====================================
config/initializers/backport_pg_10_support_to_rails_4.rb
=====================================
@@ -0,0 +1,45 @@
+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.
+#
+
+module ActiveRecord
+  module ConnectionAdapters
+    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



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/94568bd8d88ab68c2239364d89bba2c332fcad18...5e7cae060cec2f48939c1285d33b6901f039f30e

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/94568bd8d88ab68c2239364d89bba2c332fcad18...5e7cae060cec2f48939c1285d33b6901f039f30e
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20190221/1505f1f9/attachment-0001.html>


More information about the Noosfero-dev mailing list