Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 8706_rails_5_2
Browse files Browse the repository at this point in the history
Fix all the merge problems from master.

* origin/master:
  Updated logic to correctly dumping single column indexes with an alternate order. diff --git a/lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb b/lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb index fd91fdb..7055acc 100644 --- a/lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb +++ b/lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb @@ -9,6 +9,12 @@ module ActiveRecord # :nodoc:        # Regex to find where clause in index statements        INDEX_WHERE_EXPRESSION = /WHERE (.+)$/
  • Loading branch information
albertosaurus committed Oct 24, 2019
2 parents cb808cc + 3e7ca40 commit 52a39a7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SimpleCov.start do
# Fail the build when coverage is weak:
at_exit do
SimpleCov.result.format!
threshold, actual = 97.83, SimpleCov.result.covered_percent
threshold, actual = 97.839, SimpleCov.result.covered_percent
if actual < threshold
msg = "\nLow coverage: "
msg << red("#{actual}%")
Expand Down
12 changes: 12 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ remove_foreign_key(:comments, column: :post_id, remove_index: true)

PgSaurus v4.X requires Rails 5. Rails 5.2 is recommended.
You can use the new Rails 5 semantics to create comments and indexes inline.
You also need to use the index order options using the Rails 5 semantics.

```ruby
# THIS FAILS
add_index :books, ["author_id DESC NULLS FIRST", "publisher_id DESC NULLS LAST"],
name: "books_author_id_and_publisher_id"

# DO THIS INSTEAD
add_index :books, ["author_id", "publisher_id"],
name: "books_author_id_and_publisher_id",
order: { author_id: "DESC NULLS FIRST", publisher_id: "DESC NULLS LAST" }
```

### Migration notes - upgrading from Rails 4.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def indexes(table_name)

result.map do |row|
index_name = row[0]
unique = row[1]
indkey = row[2].split(" ").map(&:to_i)
inddef = row[3]
oid = row[4]
comment = row[5]
unique = row[1]
indkey = row[2].split(" ").map(&:to_i)
inddef = row[3]
oid = row[4]
comment = row[5]

using, expressions, where = inddef.scan(/ USING (\w+?) \((.+?)\)(?: WHERE (.+))?\z/m).flatten

Expand Down
12 changes: 7 additions & 5 deletions pg_saurus.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ Gem::Specification.new do |s|
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 = "2019-09-17"
s.date = "2019-10-24"
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.executables = ["rails".freeze]
s.extra_rdoc_files = [
"README.markdown"
]
s.files = [
"README.markdown",
"lib/colorized_text.rb",
"lib/core_ext/active_record/connection_adapters/abstract/schema_statements.rb",
"lib/core_ext/active_record/connection_adapters/postgresql_adapter.rb",
"lib/core_ext/active_record/connection_adapters/postgresql/schema_statements.rb",
"lib/core_ext/active_record/errors.rb",
"lib/core_ext/active_record/schema_dumper.rb",
"lib/generators/pg_saurus/install/install_generator.rb",
Expand All @@ -37,7 +37,6 @@ Gem::Specification.new do |s|
"lib/pg_saurus/connection_adapters/abstract_adapter/trigger_methods.rb",
"lib/pg_saurus/connection_adapters/foreign_key_definition.rb",
"lib/pg_saurus/connection_adapters/function_definition.rb",
"lib/pg_saurus/connection_adapters/index_definition.rb",
"lib/pg_saurus/connection_adapters/postgresql_adapter.rb",
"lib/pg_saurus/connection_adapters/postgresql_adapter/comment_methods.rb",
"lib/pg_saurus/connection_adapters/postgresql_adapter/extension_methods.rb",
Expand Down Expand Up @@ -78,7 +77,7 @@ Gem::Specification.new do |s|
]
s.homepage = "https://github.com/HornsAndHooves/pg_saurus".freeze
s.licenses = ["MIT".freeze]
s.rubygems_version = "3.0.4".freeze
s.rubygems_version = "2.7.9".freeze
s.summary = "ActiveRecord extensions for PostgreSQL.".freeze

if s.respond_to? :specification_version then
Expand All @@ -97,6 +96,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
s.add_development_dependency(%q<pry>.freeze, [">= 0"])
s.add_development_dependency(%q<pry-byebug>.freeze, [">= 0"])
s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
else
s.add_dependency(%q<pg>.freeze, [">= 0"])
s.add_dependency(%q<railties>.freeze, ["~> 5.2.3"])
Expand All @@ -110,6 +110,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<byebug>.freeze, [">= 0"])
s.add_dependency(%q<pry>.freeze, [">= 0"])
s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
end
else
s.add_dependency(%q<pg>.freeze, [">= 0"])
Expand All @@ -124,6 +125,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<byebug>.freeze, [">= 0"])
s.add_dependency(%q<pry>.freeze, [">= 0"])
s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
end
end

4 changes: 4 additions & 0 deletions spec/active_record/schema_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
@dump.should =~ /t.index \["title"\], name: "index_books_on_title_varchar_pattern_ops", opclass: :varchar_pattern_ops/
end

it "dumps indexes with simple columns with an alternate order" do
@dump.should =~ /t.index \["author_id", "publisher_id"\], name: "books_author_id_and_publisher_id", order: { author_id: :desc, publisher_id: "DESC NULLS LAST" }/
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"/
end
Expand Down
6 changes: 6 additions & 0 deletions spec/dummy/db/migrate/20190213151821_create_books.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
class CreateBooks < ActiveRecord::Migration[5.2]
def change
create_table :books do |t|
t.integer :author_id
t.integer :publisher_id
t.string :title
t.json :tags

t.timestamps
end

add_index :books, ["author_id", "publisher_id"],
name: "books_author_id_and_publisher_id",
order: { author_id: "DESC NULLS FIRST", publisher_id: "DESC NULLS LAST" }

add_index :books, "title varchar_pattern_ops"

add_index :books, "((tags->'attrs'->>'edition')::int)", name: "books_tags_json_index", skip_column_quoting: true
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@
FUNCTION_DEFINITION

create_table "books", comment: "Information about books", force: :cascade do |t|
t.integer "author_id"
t.integer "publisher_id"
t.string "title", comment: "Book title"
t.json "tags"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index "((((tags -> 'attrs'::text) ->> 'edition'::text))::integer)", name: "books_tags_json_index", skip_column_quoting: true
t.index ["author_id", "publisher_id"], name: "books_author_id_and_publisher_id", order: { author_id: :desc, publisher_id: "DESC NULLS LAST" }
t.index ["title"], name: "index_books_on_title_varchar_pattern_ops", opclass: :varchar_pattern_ops
end

Expand Down

0 comments on commit 52a39a7

Please sign in to comment.