aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/schema
Commit message (Collapse)AuthorAgeFilesLines
* Using existing models for building multiple has_one through testsRyuta Kamizono2018-04-221-14/+2
| | | | Follow up of #32514.
* Fix .new with multiple through associationsSam DeCesare2018-04-091-0/+13
| | | | | | | | | | | | | | | | | | | This fixes a bug with building an object that has multiple `has_many :through` associations through the same object. Previously, when building the object via .new, the intermediate object would be created instead of just being built. Here's an example: Given a GameBoard, that has_one Owner and Collection through Game. The following line would cause a game object to be created in the database. GameBoard.new(owner: some_owner, collection: some_collection) Whereas, if passing only one of those associations into `.new` would cause the Game object to be built and not created in the database. Now the above code will only build the Game object, and not save it.
* Merge pull request #30956 from CJStadler/with-lock-changed-deprecationRafael França2018-03-281-0/+4
| | | | Fix deprecation warnings from with_lock
* Add custom prefix to ActiveRecord::Store accessorsTan Huynh2018-03-231-0/+2
| | | | | | Add a prefix option to ActiveRecord::Store.store_accessor and ActiveRecord::Store.store. This option allows stores to have identical keys with different accessors.
* Fix multiline expression indexes for postgresql (#31621)fatkodima2018-03-161-1/+1
|
* Fix occurrences Fixnum|Bignumbogdanvlviv2018-03-041-1/+1
| | | | Related to https://github.com/rails/rails/commit/d4eb0dc89ee6b476e2e10869dc282a96f956c6c7#r27830891
* Make `reflection.klass` raise if `polymorphic?` not to be misusedRyuta Kamizono2018-02-191-0/+2
| | | | | | | | | | | | | | | | This is an alternative of #31877 to fix #31876 caused by #28808. This issue was caused by a combination of several loose implementation. * finding automatic inverse association of polymorphic without context (caused by #28808) * returning `klass` even if `polymorphic?` (exists before #28808) * loose verification by `valid_inverse_reflection?` (exists before #28808) This makes `klass` raise if `polymorphic?` not to be misused. This issue will not happen unless polymorphic `klass` is misused. Fixes #31876. Closes #31877.
* Don't update counter cache when through record was not destroyedEugene Kenny2018-01-141-0/+2
| | | | | | When removing a record from a has many through association, the counter cache was being updated even if the through record halted the callback chain and prevented itself from being destroyed.
* Fix conflicts `counter_cache` with `touch: true` by optimistic locking.bogdanvlviv2017-12-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` # create_table :posts do |t| # t.integer :comments_count, default: 0 # t.integer :lock_version # t.timestamps # end class Post < ApplicationRecord end # create_table :comments do |t| # t.belongs_to :post # end class Comment < ApplicationRecord belongs_to :post, touch: true, counter_cache: true end ``` Before: ``` post = Post.create! # => begin transaction INSERT INTO "posts" ("created_at", "updated_at", "lock_version") VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0) commit transaction comment = Comment.create!(post: post) # => begin transaction INSERT INTO "comments" ("post_id") VALUES (1) UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1, "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1 UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330', "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0 rollback transaction # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post. Comment.take.destroy! # => begin transaction DELETE FROM "comments" WHERE "comments"."id" = 1 UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1, "lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1 UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901', "lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0 rollback transaction # => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post. ``` After: ``` post = Post.create! # => begin transaction INSERT INTO "posts" ("created_at", "updated_at", "lock_version") VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0) commit transaction comment = Comment.create!(post: post) # => begin transaction INSERT INTO "comments" ("post_id") VALUES (1) UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1, "lock_version" = COALESCE("lock_version", 0) + 1, "updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1 commit transaction comment.destroy! # => begin transaction DELETE FROM "comments" WHERE "comments"."id" = 1 UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1, "lock_version" = COALESCE("lock_version", 0) + 1, "updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1 commit transaction ``` Fixes #31199.
* Refactor `length`, `order`, and `opclass` index options dumpingRyuta Kamizono2017-12-031-0/+2
|
* Ensure `apply_join_dependency` for `collection_cache_key` if eager-loading ↵Ryuta Kamizono2017-11-061-0/+1
| | | | | | is needed Fixes #30315.
* Fix CI failure due to reference type mismatchRyuta Kamizono2017-08-141-10/+9
| | | | | | | | `Firm.id` is a bigint if mysql2 adapter is used, but `firm_id` is an integer. It will cause an out of range error. https://travis-ci.org/rails/rails/jobs/264112814#L776 https://travis-ci.org/rails/rails/jobs/264112835#L919
* Specify `table.name` only when `scope.table` and `table` are different (#29058)Ryuta Kamizono2017-08-111-0/+1
| | | Fixes #29045.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-194-0/+8
|
* Fix unscoping `default_scope` in STI associationsRyuta Kamizono2017-07-191-0/+1
| | | | | | | Since 5c71000, it has lost to be able to unscope `default_scope` in STI associations. This change will use `.empty_scope?` instead of `.values.empty?` to regard as an empty scope if only have `type_condition`.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-024-4/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-014-0/+4
|
* Fix `ids_reader` to respect case sensitive primary keyRyuta Kamizono2017-06-281-1/+1
| | | | | | | | | | | | ```ruby car = Car.create!(name: "Tofaş") # Before car.bulb_ids # => SELECT "bulbs".ID FROM "bulbs" WHERE "bulbs"."name" = $1 AND "bulbs"."car_id" = $2 [["name", "defaulty"], ["car_id", 3]] # After car.bulb_ids # => SELECT "bulbs"."ID" FROM "bulbs" WHERE "bulbs"."name" = $1 AND "bulbs"."car_id" = $2 [["name", "defaulty"], ["car_id", 3]] ```
* Ensure that using correct alias trackerRyuta Kamizono2017-06-251-1/+1
| | | | | | Covering #27994 in tests. Closes #27994.
* Fix ActiveRecord::Persistence#touch with lockingbogdanvlviv2017-06-211-0/+2
| | | | | | `ActiveRecord::Persistence#touch` does not work well when optimistic locking enabled and `locking_column`, without default value, is null in the database.
* Use nullable `id` column instead of a primary keyRyuta Kamizono2017-06-161-1/+2
| | | | | | | | | `id` column in `subscribers` was added as a primary key for ignorable in INSERT. But it caused `NotNullViolation` for oracle-enhanced adapter. https://github.com/rsim/oracle-enhanced/issues/1357 I changed the column to nullable to address the issue.
* Avoid overwriting the methods of `AttributeMethods::PrimaryKey`Ryuta Kamizono2017-06-071-6/+8
| | | | | | | | | Currently the methods of `AttributeMethods::PrimaryKey` are overwritten by `define_attribute_methods`. It will be broken if a table that customized primary key has non primary key id column. It should not be overwritten if a table has any primary key. Fixes #29350.
* Don't attempt to create a new record that was already created.Isaac Betesh2017-04-201-0/+7
| | | | Fixes #24032
* Use a query that's compatible with PostgreSQL 9.2Matthew Draper2017-04-121-3/+5
| | | | | | Also, explicitly apply the order: generate_subscripts is unlikely to start returning values out of order, but we should still be clear about what we want.
* Correctly dump native timestamp types for MySQLRyuta Kamizono2017-02-231-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The native timestamp type in MySQL is different from datetime type. Internal representation of the timestamp type is UNIX time, This means that timestamp columns are affected by time zone. ``` > SET time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec) > INSERT INTO time_with_zone(ts,dt) VALUES (NOW(),NOW()); Query OK, 1 row affected (0.02 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 22:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) > SET time_zone = '-08:00'; Query OK, 0 rows affected (0.00 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 14:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) ```
* Fix rubocop violationsRafael Mendonça França2017-02-131-3/+3
|
* Omit redundant `using: :btree` for schema dumpingRyuta Kamizono2017-02-131-1/+1
|
* Schema dumping support for PostgreSQL oid typeRyuta Kamizono2017-02-121-10/+6
| | | | Closes #27980
* Schema dumping support for PostgreSQL interval typeRyuta Kamizono2017-02-121-11/+8
| | | | Closes #27979
* Fix inspection behavior when the :id column is not primary keynamusyaka2017-02-091-0/+4
|
* `primary_key` and `references` columns should be identical typeRyuta Kamizono2017-02-071-6/+6
| | | | | | | | Follow up to #26266. The default type of `primary_key` and `references` were changed to `bigint` since #26266. But legacy migration and sqlite3 adapter should keep its previous behavior.
* Chain scope constraints should respect own table aliasRyuta Kamizono2017-02-011-0/+9
| | | | Fixes #27666.
* SQLite: Foreign Key SupportRyuta Kamizono2017-01-171-18/+0
| | | | https://www.sqlite.org/foreignkeys.html
* Should work foreign key in test schema without `if supports_foreign_keys?` ↵Ryuta Kamizono2017-01-171-7/+5
| | | | | | | | | statement If an adapter does not support foreign key feature, should be noop. https://github.com/rails/rails/blob/v5.0.0.rc1/activerecord/test/cases/migration/foreign_key_test.rb#L288-L294 https://github.com/rails/rails/blob/v5.0.0.rc1/activerecord/test/cases/migration/references_foreign_key_test.rb#L208-L214
* Should not update children when the parent creation with no reasonRyuta Kamizono2016-12-291-0/+1
| | | | | | | | This issue was introduced with d849f42 to solve #19782. However, we can solve #19782 without causing the issue. It is enough to save only when necessary. Fixes #27338.
* fix #create_fixtures when equal table names in different databasesJulia Lopez2016-12-211-0/+2
|
* Make pg adapter use bigserial for pk by defaultPavel Pravosud2016-12-051-0/+3
|
* Change MySQL and Postgresql to use Bigint primary keysJon McCartie2016-12-051-3/+3
|
* For `PostgreSQL >= 9.4` use `gen_random_uuid()`Yaw Boakye2016-11-221-0/+1
| | | | | | | | | | Since 9.4, PostgreSQL recommends using `pgcrypto`'s `gen_random_uuid()` to generate version 4 UUIDs instead of the functions in the `uuid-ossp` extension. These changes uses the appropriate UUID function depending on the underlying PostgreSQL server's version, while maintaining `uuid_generate_v4()` in older migrations.
* Remove a confusing commentyui-knk2016-10-311-1/+0
| | | | | These comment sometimes explain a face which does not match the face.
* Fix the order of `create_table` to match a comment about `:inverse_of` optionsyui-knk2016-10-311-4/+4
| | | | | In ActiveRecord test :men, :faces, :interests and :zines tables are used for `:inverse_of` test cases, not `:wheels`.
* Fixed: Optimistic locking does not work well with null in the databasebogdanvlviv2016-10-211-0/+2
|
* Dump index options to pretty formatRyuta Kamizono2016-10-101-1/+1
| | | | | | | | | | ```ruby # Before t.index ["firm_id", "type", "rating"], name: "company_index", order: {"rating"=>:desc}, using: :btree # After t.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }, using: :btree ```
* Add tests for ActiveRecord::Enum#enum when suffix specifiedYosuke Kabuto2016-09-121-0/+1
| | | | Make name of attribute medium instead of normal
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies new string literal convention in activerecord/testXavier Noria2016-08-063-35/+35
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #25767 from ↵Rafael França2016-07-271-0/+5
|\ | | | | | | | | kamipo/association_name_is_the_same_as_join_table_name Correctly return `associated_table` when `associated_with?` is true
| * Correctly return `associated_table` when `associated_with?` is trueRyuta Kamizono2016-07-101-0/+5
| | | | | | | | | | | | | | `AssociationQueryHandler` requires `association` initialized `TableMetadata` even if `table_name == arel_table.name`. Fixes #25689.
* | systematic revision of =~ usage in ARXavier Noria2016-07-231-1/+1
|/ | | | | Where appropriatei, prefer the more concise Regexp#match?, String#include?, String#start_with?, or String#end_with?
* Extract foreign key action from `information_schema`Ryuta Kamizono2016-06-071-7/+8
| | | | Fixes #25300.