Skip to content

Commit

Permalink
Installing psql.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aquaj committed Mar 27, 2019
1 parent 513c2be commit b83be07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Expand Up @@ -28,12 +28,14 @@ jobs:
- run: sudo apt-get install tesseract-ocr-fra tesseract-ocr-eng tesseract-ocr-spa poppler-utils

# Install postgres extensions
- run: sudo apt install -y postgresql-client || true
- run: psql -U postgres -c 'CREATE DATABASE ekylibre_test;'
- run: psql -U postgres -d ekylibre_test -c 'CREATE SCHEMA IF NOT EXISTS postgis;'
- run: psql -U postgres -d ekylibre_test -c 'CREATE EXTENSION IF NOT EXISTS postgis SCHEMA postgis;'
- run: psql -U postgres -d ekylibre_test -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp" SCHEMA postgis;'
- run: psql -U postgres -d ekylibre_test -c 'CREATE EXTENSION IF NOT EXISTS "unaccent" SCHEMA postgis;'


# Set test database.yml config
- run: cp -f test/ci/database.yml config/database.yml

Expand Down
45 changes: 45 additions & 0 deletions config/initializers/backport_pg10_fix_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

0 comments on commit b83be07

Please sign in to comment.