Commit Graph

1221 Commits

Author SHA1 Message Date
Rafael Mendonça França
27fdf4591d Merge pull request #20269 from wojobucco/master
Changed mysqldump to include sprocs and functions
2015-05-27 22:43:23 -03:00
keepcosmos
995a473f0c add extend option on has_and_belongs_to_many. 2015-05-26 22:06:53 +09:00
Yves Senn
adfab2dcf4 deprecate Relation#uniq use Relation#distinct instead.
See #9683 for the reasons we switched to `distinct`.

Here is the discussion that triggered the actual deprecation #20198.

`uniq`, `uniq!` and `uniq_value` are still around.
They will be removed in the next minor release after Rails 5.
2015-05-26 10:35:14 +02:00
Prathamesh Sonpatki
daba090dec Pass over CHANGELOGS [ci skip] 2015-05-16 11:00:17 +05:30
Yves Senn
15354b6fd0 Merge branch 'sti-subclass-from-attributes' of https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes
Conflicts:
	activerecord/CHANGELOG.md
2015-05-13 11:08:10 +02:00
Alex Coomans
01f7d14494 Add full set of MySQL CLI options to support SSL authentication when using db:structure dump and load 2015-05-12 17:06:49 -07:00
Alex Robbin
cbd66b430b allow setting of a demodulized class name when using STI
If your STI class looks like this:

```ruby
class Company < ActiveRecord::Base
  self.store_full_sti_class = false

  class GoodCo < Company
  end

  class BadCo < Company
  end
end
```

The expectation (which is valid) is that the `type` in the database is saved as
`GoodCo` or `BadCo`. However, another expectation should be that setting `type`
to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
second expectation is what this should fix.
2015-05-11 09:02:48 -04:00
Rafael Mendonça França
02966105a5 Merge pull request #19994 from kamipo/dump_indexes_in_create_table
Dump indexes in `create_table` instead of `add_index`
2015-05-03 19:33:12 -03:00
Rafael Mendonça França
b6cc44bfa6 Merge pull request #17569 from kamipo/dump_table_options
Correctly dump `:options` on `create_table` for MySQL
2015-05-03 18:43:58 -03:00
Ryuta Kamizono
f8e748b4e8 PostgreSQL: :collation support for string and text columns
Example:

    create_table :foos do |t|
      t.string :string_en, collation: 'en_US.UTF-8'
      t.text   :text_ja,   collation: 'ja_JP.UTF-8'
    end
2015-05-04 03:53:41 +09:00
Ryuta Kamizono
99801c6a7b Dump indexes in create_table instead of add_index
If the adapter supports indexes in create table, generated SQL is
slightly more efficient.
2015-05-03 23:35:13 +09:00
Ryuta Kamizono
22ba159efc Correctly dump :options on create_table for MySQL 2015-05-03 16:41:19 +09:00
thiagoaugusto
361f1bc7c5 Improvement on Activerecord CHANGELOG 2015-05-01 11:34:19 -03:00
Yves Senn
80f011ea54 Merge pull request #19546 from DianthuDia/fix_unscope_for_less_than
Fix unscope for less than
2015-04-28 11:37:59 +02:00
Yves Senn
cdf3548a45 Merge pull request #19718 from eagletmt/find_by-without-arg
Raise ArgumentError when find_by receives no arguments
2015-04-28 11:06:53 +02:00
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