aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation/delete_all_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add Relation#annotate for SQL commentingMatt Yoho2019-03-211-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch has two main portions: 1. Add SQL comment support to Arel via Arel::Nodes::Comment. 2. Implement a Relation#annotate method on top of that. == Adding SQL comment support Adds a new Arel::Nodes::Comment node that represents an optional SQL comment and teachers the relevant visitors how to handle it. Comment nodes may be added to the basic CRUD statement nodes and set through any of the four (Select|Insert|Update|Delete)Manager objects. For example: manager = Arel::UpdateManager.new manager.table table manager.comment("annotation") manager.to_sql # UPDATE "users" /* annotation */ This new node type will be used by ActiveRecord::Relation to enable query annotation via SQL comments. == Implementing the Relation#annotate method Implements `ActiveRecord::Relation#annotate`, which accepts a comment string that will be appeneded to any queries generated by the relation. Some examples: relation = Post.where(id: 123).annotate("metadata string") relation.first # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 # LIMIT 1 /* metadata string */ class Tag < ActiveRecord::Base scope :foo_annotated, -> { annotate("foo") } end Tag.foo_annotated.annotate("bar").first # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */ Also wires up the plumbing so this works with `#update_all` and `#delete_all` as well. This feature is useful for instrumentation and general analysis of queries generated at runtime.
* Oracle database can run `delete` statement with `order by` and`fetch first n ↵Yasuo Honda2019-03-031-19/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | rows only` Since https://github.com/rails/arel/pull/337 Oracle adapter uses better top N query using `fetch first n rows only`, which can remove this unless condition. * This commit passes with Oracle database ```ruby $ ARCONN=oracle bin/test test/cases/relation/delete_all_test.rb -n test_delete_all_with_order_and_limit_deletes_subset_only Using oracle Run options: -n test_delete_all_with_order_and_limit_deletes_subset_only --seed 1081 . Finished in 8.068626s, 0.1239 runs/s, 0.6197 assertions/s. 1 runs, 5 assertions, 0 failures, 0 errors, 0 skips $ ``` * SQL statement includes `ORDER BY` and `FETCH FIRST n ROWS ONLY` ```sql Post Destroy (12.5ms) DELETE FROM "POSTS" WHERE "POSTS"."ID" IN (SELECT "POSTS"."ID" FROM "POSTS" WHERE "POSTS"."AUTHOR_ID" = :a1 ORDER BY "POSTS"."ID" ASC FETCH FIRST :a2 ROWS ONLY) [["author_id", 1], ["LIMIT", 1]] ```
* Extract `{update,delete}_all_test.rb` from `persistence_test.rb` and ↵Ryuta Kamizono2018-09-161-0/+104
`relations_test.rb` `persistence_test.rb` and `relations_test.rb` have too many lines, so I'd like to extract relation around tests to dedicated files before newly test added.