Skip to content

Commit

Permalink
Merge branch 'master' of github.com:HornsAndHooves/pg_saurus into rai…
Browse files Browse the repository at this point in the history
…ls_6_research
  • Loading branch information
maneyko committed Sep 30, 2021
2 parents 6f5440c + 395b5f3 commit b45353e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ spec/dummy/log/*.log
spec/dummy/tmp/

.idea
.generators
.rakeTasks

TAGS
ctags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def tables(name = nil)
WHERE schemaname = ANY (ARRAY['public'])
SQL
end

# Returns an array of indexes for the given table.
#
# == Patch 1:
Expand Down Expand Up @@ -233,7 +233,7 @@ def quoted_columns_for_index(column_names, **options)
column_name, operator_name = split_column_name(name)

result_name = if column_name =~ FUNCTIONAL_INDEX_REGEXP
_name = "#{$1}(#{$2}#{quote_column_name($3)})"
_name = column_name.gsub(/\b#{$3}\b/, quote_column_name($3))
_name += " #{operator_name}"
_name
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def triggers

# Parse the condition from the trigger definition.
def parse_condition(trigger_definition)
trigger_definition[/WHEN[\s](.*?)[\s]EXECUTE[\s]PROCEDURE/m, 1]
trigger_definition[/WHEN[\s](.*?)[\s]EXECUTE[\s](FUNCTION|PROCEDURE)/m, 1]
end
private :parse_condition

Expand All @@ -107,7 +107,7 @@ def parse_event(trigger_definition, trigger_name)

# Parse the procedure name from the trigger definition.
def parse_proc_name(trigger_definition)
trigger_definition[/EXECUTE[\s]PROCEDURE[\s](.*?)$/m,1]
trigger_definition[/EXECUTE[\s](FUNCTION|PROCEDURE)[\s](.*?)$/m, 2]
end
private :parse_proc_name

Expand Down
4 changes: 2 additions & 2 deletions lib/pg_saurus/schema_dumper/extension_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def dump_extensions(stream)
extensions = @connection.pg_extensions
commands = extensions.map do |extension_name, options|
result = [%Q|create_extension "#{extension_name}"|]
result << %Q|:schema_name => "#{options[:schema_name]}"| unless options[:schema_name] == 'public'
result << %Q|:version => "#{options[:version]}"|
result << %Q|schema_name: "#{options[:schema_name]}"| unless options[:schema_name] == 'public'
result << %Q|version: "#{options[:version]}"|
result.join(', ')
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pg_saurus/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PgSaurus
# Version of pg_saurus gem.
VERSION = "4.1.0"
VERSION = "4.3.0"
end
9 changes: 6 additions & 3 deletions pg_saurus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
# stub: pg_saurus 4.1.0 ruby lib
# stub: pg_saurus 4.3.0 ruby lib

Gem::Specification.new do |s|
s.name = "pg_saurus".freeze
s.version = "4.1.0"
s.version = "4.3.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["Potapov Sergey".freeze, "Arthur Shagall".freeze, "Artem Ignatyev".freeze, "Matt Dressel".freeze, "Bruce Burdick".freeze, "HornsAndHooves".freeze]
s.date = "2020-01-31"
s.date = "2021-09-22"
s.description = "ActiveRecord extensions for PostgreSQL. Provides useful tools for schema, foreign_key, index, function, trigger, comment and extension manipulations in migrations.".freeze
s.email = ["[email protected]".freeze, "[email protected]".freeze, "[email protected]".freeze, "[email protected]".freeze, "[email protected]".freeze]
s.extra_rdoc_files = [
Expand Down Expand Up @@ -85,6 +85,7 @@ Gem::Specification.new do |s|

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<pg>.freeze, [">= 0"])
s.add_runtime_dependency(%q<psych>.freeze, ["~> 3"])
s.add_runtime_dependency(%q<railties>.freeze, ["~> 6"])
s.add_runtime_dependency(%q<activemodel>.freeze, ["~> 6"])
s.add_runtime_dependency(%q<activerecord>.freeze, ["~> 6"])
Expand All @@ -99,6 +100,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
else
s.add_dependency(%q<pg>.freeze, [">= 0"])
s.add_dependency(%q<psych>.freeze, ["~> 3"])
s.add_dependency(%q<railties>.freeze, ["~> 6"])
s.add_dependency(%q<activemodel>.freeze, ["~> 6"])
s.add_dependency(%q<activerecord>.freeze, ["~> 6"])
Expand All @@ -114,6 +116,7 @@ Gem::Specification.new do |s|
end
else
s.add_dependency(%q<pg>.freeze, [">= 0"])
s.add_dependency(%q<psych>.freeze, ["~> 3"])
s.add_dependency(%q<railties>.freeze, ["~> 6"])
s.add_dependency(%q<activemodel>.freeze, ["~> 6"])
s.add_dependency(%q<activerecord>.freeze, ["~> 6"])
Expand Down
6 changes: 3 additions & 3 deletions spec/active_record/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

context "Extensions" do
it 'dumps loaded extension modules' do
@dump.should =~ /create_extension "fuzzystrmatch", :version => "\d+\.\d+"/
@dump.should =~ /create_extension "btree_gist", :schema_name => "demography", :version => "\d+\.\d+"/
@dump.should =~ /create_extension "fuzzystrmatch", version: "\d+\.\d+"/
@dump.should =~ /create_extension "btree_gist", schema_name: "demography", version: "\d+\.\d+"/
end
end

Expand Down Expand Up @@ -105,7 +105,7 @@
end

it "dumps functional indexes with longer operator strings" do
@dump.should =~ /t.index "lower\(name\) DESC NULLS LAST", name: "index_pets_on_lower_name_desc_nulls_last"/
@dump.should =~ /t.index "btrim\(lower\(name\)\) DESC NULLS LAST", name: "index_pets_on_lower_name_desc_nulls_last"/
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AddFunctionalIndexWithLongerOperatorString < ActiveRecord::Migration[5.2]
def change
add_index :pets, ["lower(name) DESC NULLS LAST"]
add_index :pets, ["trim(lower(name)) DESC NULLS LAST"]
end
end
6 changes: 3 additions & 3 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
create_schema_if_not_exists "later"
create_schema_if_not_exists "latest"

create_extension "fuzzystrmatch", :version => "1.1"
create_extension "btree_gist", :schema_name => "demography", :version => "1.5"
create_extension "fuzzystrmatch", version: "1.1"
create_extension "btree_gist", schema_name: "demography", version: "1.5"

# These are extensions that must be enabled in order to support this database
enable_extension "btree_gist"
Expand Down Expand Up @@ -109,7 +109,7 @@
t.integer "breed_id"
t.integer "owner_id"
t.boolean "active", default: true
t.index "lower(name) DESC NULLS LAST", name: "index_pets_on_lower_name_desc_nulls_last"
t.index "btrim(lower(name)) DESC NULLS LAST", name: "index_pets_on_lower_name_desc_nulls_last"
t.index "lower(name)", name: "index_pets_on_lower_name"
t.index "to_tsvector('english'::regconfig, name)", name: "index_pets_on_to_tsvector_name_gist", using: :gist, comment: "Functional index on name"
t.index "upper(color)", name: "index_pets_on_upper_color", where: "(name IS NULL)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
context "for functional index with longer operator string" do
let(:expected_query) do
["CREATE", "INDEX", %("index_users_on_lower_first_name_desc_nulls_last"), "ON", %("users"),
%{(lower(first_name)}, "DESC", "NULLS", "LAST)"]
%{(trim(lower(first_name))}, "DESC", "NULLS", "LAST)"]
end

it 'creates functional index for column with longer operator string' do
Expand All @@ -49,7 +49,7 @@
query.split(" ").should == expected_query
end

ActiveRecord::Migration.add_index :users, "lower(first_name) DESC NULLS LAST"
ActiveRecord::Migration.add_index :users, "trim(lower(first_name)) DESC NULLS LAST"
ActiveRecord::Migration.process_postponed_queries
end
end
Expand Down

0 comments on commit b45353e

Please sign in to comment.