Commit Graph

1206 Commits

Author SHA1 Message Date
Yves Senn
557c46a41e Revert "Merge pull request #17920 from calebthompson/dont-rely-on-environment-task-for-schema-load"
This reverts commit 08ff4ccbbb3fb143a02e6752efb974a4bcfcd3bb, reversing
changes made to 6c9ed6dbc62450cdb87559afd15798305e069146.

Caused by #17920.

Closes #19545.

This patch introduced regressions because initializers were no longer
loaded. Specifically missing inflections result in broken restores of
the database.
2015-04-27 11:45:21 +02:00
Rafael Mendonça França
6f37d7e117 Merge pull request #18880 from mudge/timestamp-index-bug
Fix missing index when using timestamps with index
2015-04-23 13:51:55 -03:00
Yves Senn
cdbf685994 pass over CHANGELOGs. [ci skip] 2015-04-22 14:44:30 +02:00
Andrew White
ac2b7a5c4d Rename association option :class to :anonymous_class
In 1f006c an option was added called :class to allow passing anonymous
classes to association definitions. Since using :class instead of
:class_name is a fairly common typo even amongst experienced developers
this can result in hard to debug errors arising in raise_on_type_mismatch?

To fix this we're renaming the option from :class to :anonymous_class as
that is a more correct description of what the option is for. Since this
was an internal, undocumented option there is no need for a deprecation.

Fixes #19659
2015-04-21 08:48:22 -04:00
Sean Griffin
d849f42b4e Autosave existing records on HMT associations when the parent is new
To me it seems like this should only be the case if `autosave: true` is
set on the association. However, when implemented that way, it caused
issues with has many associations, where we have explicit tests stating
that child records are updated when the parent is new, even if autosave
is not set (presumably to update the parent id, but other changed
attributes would be persisted as well).

It's quirky, but at least we should be consistently quirky. This
constitutes a minor but subtle change in behavior, and therefore should
not be backported to 4.2 and earlier.

Fixes #19782
2015-04-18 10:47:04 -04:00
Paul Mucur
c0abeadc0e Fix missing index when using timestamps with index
The `index` option used with `timestamps` should be passed to both
`column` definitions for `created_at` and `updated_at` rather than just
the first.

This was happening because `Hash#delete` is used to extract the `index`
option passed to `timestamps`, thereby mutating the `options` hash
in-place. Now take a copy of the `options` before deleting so that the
original is not modified.
2015-04-15 09:53:55 +01:00
Yves Senn
5f00ed10dd Revert "Merge pull request #19755 from yuki24/activerecord/support-for-set"
This reverts commit 524d40591eaa2f4d007409bfad386f6b107492eb, reversing
changes made to 34d3a6095100245283861ef480a54d0643bbee4c.

Reasoning behind the revert are in the PR discussion:
https://github.com/rails/rails/pull/19755

- This means that types can no longer cast to/from `Set`, and reasonably
  work with `where` (we already have this problem for `array`/`json`
  types on pg)
- This adds precedent for every other `Enumerable`, and we can't target
  `Enumerable` directly.
- Calling `to_a` on a `Set` is reasonable.
2015-04-15 09:10:00 +02:00
Yves Senn
524d40591e Merge pull request #19755 from yuki24/activerecord/support-for-set
Add support for Set to Relation#where
2015-04-14 08:57:10 +02:00
Yuki Nishijima
50cae600bd Add support for Set to Relation#where
Previously `#where` used to treat `Set`objects as nil, but now it treats
them as an array:

  set = Set.new([1, 2])
  Author.where(:id => set)
  # => SELECT "authors".* FROM "authors" WHERE "authors"."id" IN (1, 2)
2015-04-13 20:13:37 -07:00
Sean Griffin
67c2deeb4b Merge branch 'fix_uniqueness_validation_when_value_is_out_of_range' 2015-04-08 11:07:39 -06:00
Andrey Voronkov
1a36be390e Fix uniqueness validation with out of range value 2015-04-08 19:28:45 +03:00
Jeremy Kemper
bd51bbc028 Merge pull request #17574 from kamipo/charset_collation_options
Add charset and collation options support for MySQL string and text columns.
2015-04-07 09:40:16 -07:00
Yves Senn
51eacc71c7 Merge pull request #19652 from vngrs/pluralize_foreign_key_table_name_bug
use singular table name if pluralize_table_names is setted as false whil...
2015-04-06 10:42:44 +02:00
Sean Griffin
445c12f7df Reduce memory usage when loading types in PG
We were never clearing the `PG::Result` object used to query the types
when the connection is first established. This would lead to a
potentially large amount of memory being retained for the life of the
connection.

Investigating this issue also revealed several low hanging fruit on the
performance of these methods, and the number of allocations has been
reduced by ~90%.

Fixes #19578
2015-03-29 13:54:39 -06:00
Jason Nochlin
4d6fbe2934 Add config.active_record.warn_on_records_fetched_greater_than option
When set to an integer, a warning will be logged whenever a result set
larger than the specified size is returned by a query. Fixes #16463

The warning is outputed a module which is prepended in an initializer,
so there will be no performance impact if
`config.active_record.warn_on_records_fetched_greater_than` is not set.
2015-03-25 16:50:11 -04:00
Yves Senn
30a5cd9c8b Merge pull request #19503 from jasoncodes/no-psqlrc
Avoid loading user's psqlrc when loading test structure
2015-03-25 09:42:45 +01:00
Carlos Antonio da Silva
bfd5bf8313 Merge pull request #19452 from pinglamb/fix-referencing-wrong-alias-when-joining-tables-of-has-many-through-association
Fix referencing wrong aliases while joining tables of has many through association
2015-03-24 08:00:59 -03:00
Matthew Draper
8b96c0b7a3 Make sure to persist a newly-nil serialized value
The subtype will (quite reasonably) ignore the possibility that it has
`changed_in_place?` by becoming nil.

Fixes #19467
2015-03-23 15:27:03 +10:30
Carlos Antonio da Silva
8a45e18f11 Move #19447 changelog to the top and reword it a bit [ci skip] 2015-03-22 19:11:06 -03:00
pinglamb
ba057a5ebb Fix referencing wrong aliases while joining tables of has many through
association

While joining table of has_many :through association, ActiveRecord will
use the actual table name instead of through-join alias. It results with
a wrong SQL and exception is raised. This only happens when calculation
methods like #count is called.

This issue is affecting Rails 4.1.x and 4.2.x as well.
2015-03-22 16:25:23 +08:00
wallerjake
9bc4eb7ee1 Delegate limit to subtype
As described here https://github.com/rails/rails/issues/19420. When
using the Postgres BigInt[] field type the big int value was not being
translated into schema.rb. This caused the field to become just a
regular integer field when building off of schema.rb. This fix will
address this by delegating the limit from the subtype to the Array type.

https://github.com/rails/rails/issues/19420
2015-03-21 19:32:41 -05:00
Yves Senn
dfdb08f092 Merge pull request #19406 from larskanis/add_changelog_entry_for_17680
ActiveRecord: Add a changelog entry for issue #17680. [ci skip]
Conflicts:
	activerecord/CHANGELOG.md
2015-03-19 14:06:26 +01:00
Jon Atack
dbf5433978 Active Record changelog pass [skip ci] 2015-03-19 10:04:11 +05:30
Yves Senn
08615a3bcb Merge pull request #19348 from Empact/null-scope
Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.

Conflicts:
	activerecord/CHANGELOG.md
2015-03-18 11:20:47 +01:00
Ryan Wallace
7ab36f4532 Add config.active_record.dump_schemas.
Fixes db:structure:dump when using schema_search_path and PostgreSQL
extensions.

Closes #17157.
2015-03-17 10:43:26 -07:00
Brandon Weiss
0965863564 Closes rails/rails#18864: Renaming transactional fixtures to transactional tests
I’m renaming all instances of `use_transcational_fixtures` to
`use_transactional_tests` and “transactional fixtures” to
“transactional tests”.

I’m deprecating `use_transactional_fixtures=`. So anyone who is
explicitly setting this will get a warning telling them to use
`use_transactional_tests=` instead.

I’m maintaining backwards compatibility—both forms will work.
`use_transactional_tests` will check to see if
`use_transactional_fixtures` is set and use that, otherwise it will use
itself. But because `use_transactional_tests` is a class attribute
(created with `class_attribute`) this requires a little bit of hoop
jumping. The writer method that `class_attribute` generates defines a
new reader method that return the value being set. Which means we can’t
set the default of `true` using `use_transactional_tests=` as was done
previously because that won’t take into account anyone using
`use_transactional_fixtures`. Instead I defined the reader method
manually and it checks `use_transactional_fixtures`. If it was set then
it should be used, otherwise it should return the default, which is
`true`. If someone uses `use_transactional_tests=` then it will
overwrite the backwards-compatible method with whatever they set.
2015-03-16 11:35:44 -07:00
Ben Woosley
c82cc222c7 Reuse the CollectionAssociation#reader proxy cache if the foreign key is present from the start.
When a new record has the necessary information prior to save, we can
avoid busting the cache.

We could simply clear the @proxy on #reset or #reset_scope, but that
would clear the cache more often than necessary.
2015-03-15 17:29:05 -07:00
Matt Brictson
ba7532700f Require pg~>0.18 to ensure Ruby 2.2 compatibility
Versions of the pg gem earlier than 0.18.0 cannot be used safely with Ruby 2.2.
Specifically, pg 0.17 when used with Ruby 2.2 has a known bug that causes
random bits to be added to the end of strings. Further explanation here:
https://bitbucket.org/ged/ruby-pg/issue/210/crazy-bytes-being-added-to-record
2015-03-11 22:23:36 -07:00
Ryuta Kamizono
0aa83f3b88 Add :charset and :collation options support for MySQL string and text columns
Example:

    create_table :foos do |t|
      t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin'
      t.text   :text_ascii,      charset: 'ascii'
    end
2015-03-06 18:56:19 +09:00
Ryuta Kamizono
6fa6c739d1 Correctly dump serial and bigserial 2015-03-04 17:52:11 +09:00
Yves Senn
1b356c2e7a add CHANGELOG entry for #19176. [ci skip] 2015-03-04 08:46:12 +01:00
Arthur Neves
4e757746a6 Add changelog for #15549 fix [skip ci] 2015-02-27 16:05:28 -05:00
Sean Griffin
38218929e9 Properly create through records when called with where
Various behaviors needed by associations (such as creating the through
record) are lost when `where` is called, since we stop having a
`CollectionProxy` and start having an `AssociationRelation` which does
not contain this behavior. I *think* we should be able to rm
`AssociationRelation`, but we have tests saying the changes required to
do that would be bad (Without saying why. Of course. >_>)

Fixes #19073.
2015-02-26 12:42:55 -07:00
Ryuta Kamizono
3239b6a98a Add SchemaMigration.create_table support any unicode charsets for MySQL.
MySQL unicode support is not only `utf8mb4`.
Then, The index length problem is not only `utf8mb4`.

http://dev.mysql.com/doc/refman/5.6/en/charset-unicode.html

    SELECT * FROM information_schema.character_sets WHERE maxlen > 3;
    +--------------------+----------------------+------------------+--------+
    | CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION      | MAXLEN |
    +--------------------+----------------------+------------------+--------+
    | utf8mb4            | utf8mb4_general_ci   | UTF-8 Unicode    |      4 |
    | utf16              | utf16_general_ci     | UTF-16 Unicode   |      4 |
    | utf16le            | utf16le_general_ci   | UTF-16LE Unicode |      4 |
    | utf32              | utf32_general_ci     | UTF-32 Unicode   |      4 |
    +--------------------+----------------------+------------------+--------+
2015-02-26 07:57:53 +09:00
Yves Senn
72c1557254 rework disable_referential_integrity for PostgreSQL.
[Toby Ovod-Everett & Andrey Nering & Yves Senn]

Closes #17726.
Closes #10939.

This patch makes three distinct modifications:

1. no longer fall back to disabling user triggers if system triggers can't be disabled
2. warn the user when referential integrity can't be disabled
3. restore aborted transactions when referential integrity can't be disabled

The motivation behind these changes is to make the behavior of Rails
transparent and less error-prone. To require superuser privileges is not optimal
but it's what Rails currently needs. Users who absolutely rely on disabling user triggers
can patch `disable_referential_integrity`.

We should investigate `SET CONSTRAINTS` as a possible solution which does not require
superuser privileges.

/cc @matthewd
2015-02-24 17:32:35 +01:00
Ryuta Kamizono
b8d320c129 Allow :limit option for MySQL bigint primary key support
Example:

    create_table :foos, id: :primary_key, limit: 8 do |t|
    end

    # or

    create_table :foos, id: false do |t|
      t.column :id, limit: 8
    end
2015-02-24 01:53:54 +09:00
Yves Senn
e71f5dad4e some indenting and punctuation fixes. [ci skip] 2015-02-23 16:54:40 +01:00
Josef Šimánek
6576f7354e Require belongs_to by default.
Deprecate `required` option in favor of `optional` for belongs_to.
2015-02-21 23:03:10 +01:00
Rafael Mendonça França
0f2261f2d1 Merge pull request #17139 from mfazekas/fix_becomes_changed_attributes
Always reset changed attributes in becomes
2015-02-20 15:01:28 -02:00
Ryuta Kamizono
a088ee9691 Format the time string according to the precision of the time column
It is also necessary to format a time column like a datetime column.
2015-02-20 10:25:31 +09:00
Ryuta Kamizono
9ef870c042 Allow :precision option for time type columns 2015-02-20 10:24:08 +09:00
Rafael Mendonça França
e28721baf2 Copy edit the suppressor documentation
[ci skip]
2015-02-19 09:08:51 -02:00
Michael Ryan
b9a1e9a4b2 Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
Hyonjee Joo
219d71fb90 Add time option to #touch
Fixes #18905. `#touch` now takes time as an option. Setting the option
saves the record with the updated_at/on attributes set to the current time
or the time specified. Updated tests and documentation accordingly.
2015-02-18 10:22:13 -05:00
Sean Griffin
89ba5bb456 Revert "Allow :precision option for time type columns"
This reverts commit 1502caefd30b137fd1a0865be34c5bbf85ba64c1.

The test suite for the mysql adapter broke when this commit was used
with MySQL 5.6.

Conflicts:
	activerecord/CHANGELOG.md
2015-02-17 11:12:52 -07:00
Vipul A M
6598272770 Deprecated passing of start value to find_in_batches and find_each in favour of begin_at value. 2015-02-17 14:10:35 +05:30
Yves Senn
6bd777c851 Merge pull request #18662 from estum/foreign-key-exists
Add `foreign_key_exists?` method.
2015-02-16 09:39:59 +01:00
Yves Senn
57a1d2bf9d remove CHANGELOG entry for Rails 5.0 only feature. #18918
`has_secure_token` hasen't been released yet. No need to track
every change in the CHANGELOG.
2015-02-13 09:16:22 +01:00
Wojciech Wnętrzak
0817bb06f7 Do not overwrite secret token value when already present.
```
user = User.create(token: "custom-secure-token")
user.token # => "custom-secure-token"
```
2015-02-12 22:05:45 +01:00
Eugene Gilburg
d7a7a050e1 Optimize none? and one? relation query methods to use LIMIT and COUNT.
Use SQL COUNT and LIMIT 1 queries for none? and one? methods if no block or limit is given,
instead of loading the entire collection to memory. The any? and many? methods already
follow this behavior.

[Eugene Gilburg & Rafael Mendonça França]
2015-02-12 17:40:59 -02:00