Commit Graph

345 Commits

Author SHA1 Message Date
Ryuta Kamizono
9abf606a79 Should not update children when the parent creation with no reason
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.
2016-12-29 16:24:57 +09:00
Julia Lopez
5e46f4ccb4 fix #create_fixtures when equal table names in different databases 2016-12-21 11:09:29 +01:00
Pavel Pravosud
3e452b1204 Make pg adapter use bigserial for pk by default 2016-12-05 11:40:32 -08:00
Jon McCartie
b92ae61069 Change MySQL and Postgresql to use Bigint primary keys 2016-12-05 11:34:35 -08:00
Yaw Boakye
b915b11cca
For PostgreSQL >= 9.4 use gen_random_uuid()
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.
2016-11-22 22:11:18 +00:00
yui-knk
4360ecf7df Remove a confusing comment
These comment sometimes explain a face which does not match
the face.
2016-10-31 10:27:01 +09:00
yui-knk
7808a90990 Fix the order of create_table to match a comment about :inverse_of options
In ActiveRecord test :men, :faces, :interests and :zines tables are
used for `:inverse_of` test cases, not `:wheels`.
2016-10-31 10:26:09 +09:00
bogdanvlviv
22a822e581 Fixed: Optimistic locking does not work well with null in the database 2016-10-21 19:06:02 +03:00
Ryuta Kamizono
5025fd3a99 Dump index options to pretty format
```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
```
2016-10-10 11:53:22 +09:00
Yosuke Kabuto
6009107caf Add tests for ActiveRecord::Enum#enum when suffix specified
Make name of attribute medium instead of normal
2016-09-12 08:52:02 +09:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria
9617db2078 applies new string literal convention in activerecord/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:53 +02:00
Rafael França
70ec7feaec Merge pull request #25767 from kamipo/association_name_is_the_same_as_join_table_name
Correctly return `associated_table` when `associated_with?` is true
2016-07-27 23:23:05 -03:00
Xavier Noria
99cf755800 systematic revision of =~ usage in AR
Where appropriatei, prefer the more concise Regexp#match?,
String#include?, String#start_with?, or String#end_with?
2016-07-23 20:22:20 +02:00
Ryuta Kamizono
b7d229d1fa Correctly return associated_table when associated_with? is true
`AssociationQueryHandler` requires `association` initialized
`TableMetadata` even if `table_name == arel_table.name`.

Fixes #25689.
2016-07-10 11:42:51 +09:00
Ryuta Kamizono
7b7b7c5ce6 Extract foreign key action from information_schema
Fixes #25300.
2016-06-07 06:26:49 +09:00
Ryuta Kamizono
edc2b77187
Add Expression Indexes and Operator Classes support for PostgreSQL
Example:

    create_table :users do |t|
      t.string :name
      t.index 'lower(name) varchar_pattern_ops'
    end

Fixes #19090.
Fixes #21765.
Fixes #21819.
Fixes #24359.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-24 14:56:29 -07:00
Ryuta Kamizono
a80e944e18 Remove unused table_with_autoincrement table 2016-04-19 17:17:19 +09:00
Ladislav Smola
cb4f6875b6 Fix undefined method `owners' for NullPreloader:Class
* Fix undefined method `owners' for NullPreloader:Class

Fixing undefined method `owners' for
ActiveRecord::Associations::Preloader::NullPreloader:Class

* Use Ruby 1.9 hash format

Use Ruby 1.9 hash format

#24192

[Rafael Mendonça França + Ladislav Smola]
2016-04-06 00:46:55 -03:00
Ryuta Kamizono
3b910de771 Remove except helper for test schema 2016-03-30 06:49:04 +09:00
Rafael França
eefcc78f7a Merge pull request #23797 from kamipo/case_sensitive_comparison_for_non_string_column
The BINARY Operator is only needed for string columns
2016-03-11 19:10:29 -03:00
Mehmet Emin İNAÇ
0784dccc4f Execute default_scope defined by abstract class within the scope of subclass 2016-03-08 14:56:00 +02:00
Sean Griffin
96c1ada82d Merge pull request #23628 from maclover7/fix-23625
Fix issue #23625
2016-02-23 12:24:07 -07:00
Ryuta Kamizono
b8f86ae29f The BINARY Operator is only needed for string columns
Follow up to #13040.
2016-02-22 10:03:03 +09:00
Aaron Patterson
2df891dccd eliminate warnings about multiple primary keys on habtm join tables
habtm join tables commonly have two id columns and it's OK to make those
two id columns a primary key.  This commit eliminates the warnings for
join tables that have this setup.

  ManageIQ/manageiq#6713
2016-02-19 15:31:56 -08:00
Jon Moss
55385c8a39 Fix issue #23625
This resolves a bug where if the primary key used is not `id` (ex:
`uuid`), and has a `validates_uniqueness_of` in the model, a uniqueness error
would be raised. This is a partial revert of commit `119b9181ece399c67213543fb5227b82688b536f`, which introduced this behavior.
2016-02-18 00:32:38 -05:00
Ryuta Kamizono
8e083e1502 Use t.index in create_table instead of add_index in test schema
For reduce bootstrap queries in tests.
2016-01-31 17:36:04 +09:00
Ryuta Kamizono
d0054b4908 Fix bigint? for Enum columns in MySQL
Follow up to #22896.
2016-01-31 01:07:02 +09:00
Vipul A M
b334bc93c6 Add missing source_type if provided on hmt which belongs to an sti record
Fixes #23209
2016-01-24 22:25:12 +05:30
Sean Griffin
67c1719012 Use the database type to deserialize enum
This fixes incorrect assumptions made by e991c7b that we can assume the
DB is already casting the value for us. The enum type needs additional
information to perform casting, and needs a subtype.

I've opted not to call `super` in `cast`, as we have a known set of
types which we accept there, and the subtype likely doesn't accept them
(symbol -> integer doesn't make sense)

Close #23190
2016-01-23 08:44:16 -07:00
Rafael França
de2259791c Merge pull request #20005 from kamipo/default_expression_support
Add `:expression` option support on the schema default
2016-01-16 04:18:21 -02:00
Kasper Timm Hansen
1aa1cec777 Revert "Merge pull request #20835 from glittershark/if-and-unless-in-secure-token"
This reverts commit 224eddfc0eeff6555ae88691306e61c7a9e8b758, reversing
changes made to 9d681fc74c6251d5f2b93fa9576c9b2113116680.

When merging the pull request, I misunderstood `has_secure_token` as declaring a model
has a token from birth and through the rest of its lifetime.

Therefore, supporting conditional creation doesn't make sense. You should never mark a
model as having a secure token if there's a time when it shouldn't have it on creation.
2016-01-14 21:52:03 +01:00
Ryuta Kamizono
744552f72d Fix extract default with CURRENT_TIMESTUMP 2016-01-13 22:03:56 +09:00
Ryuta Kamizono
5fd30ac52d Add expression support on the schema default
Example:

    create_table :posts do |t|
      t.datetime :published_at, default: -> { 'NOW()' }
    end
2016-01-13 22:03:56 +09:00
Kasper Timm Hansen
62abae9172 Add conditional_token to users.
Fix the NoMethodErrors introduced in 224eddf, when adding conditional token creation.

The model declarations but the column wasn't added to the schema.
2016-01-09 22:31:13 +01:00
Ryuta Kamizono
4d4239f980 Add short-hand methods for text and blob types in MySQL
In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length.
But in MySQL, these have limited length for each types (ref #21591, #21619).
This change adds short-hand methods for each text and blob types.

Example:

    create_table :foos do |t|
      t.tinyblob   :tiny_blob
      t.mediumblob :medium_blob
      t.longblob   :long_blob
      t.tinytext   :tiny_text
      t.mediumtext :medium_text
      t.longtext   :long_text
    end
2016-01-05 10:36:37 +09:00
Ryuta Kamizono
2f373dd916 Fix unsigned? and blob_or_text_column? for Enum columns in MySQL 2016-01-04 14:46:59 +09:00
Ryuta Kamizono
d9ca8e20ff Remove unused test/schema/mysql_specific_schema.rb
Follow up to #22642.
2015-12-19 18:05:55 +09:00
Yves Senn
0f82f661b7 tests, pluralize singular table name.
This solves the following error:

     ActiveRecord::StatementInvalid: Could not find table 'guitars'

It seems that the table structure of the `Guitar` model has not been
necessary until now. Due to the wrong table name the model was not
correctly linked to the table.
2015-12-02 16:02:01 +01:00
yui-knk
817c1825c1 Except keys of build_record's argument from create_scope in initialize_attributes
If argument of `build_record` has key and value which is same as
default value of database, we should also except the key from
`create_scope` in `initialize_attributes`.
Because at first `build_record` initialize record object with argument
of `build_record`, then assign attributes derived from Association's scope.
In this case `record.changed` does not include the key, which value is
same as default value of database, so we should add the key to except list.

Fix #21893.
2015-11-16 23:15:45 +09:00
Sean Griffin
f7d0a3ba7e Merge pull request #18548 from sebjacobs/support-bidirectional-destroy-dependencies
Add support for bidirectional destroy dependencies
2015-10-28 12:24:07 -06:00
Sean Griffin
118232aef4 Merge pull request #19686 from tsun1215/index_errors
Errors can be indexed with nested attributes

Close #8638
2015-10-26 16:05:16 -06:00
Sean Griffin
5c32f41d52 Fix merge conflicts for #19938
This is a separate commit, as it is not just a changelog conflict. Want
to point out the changes in the code
2015-10-20 16:57:47 -06:00
Sean Griffin
72fba7db41 Merge pull request #21932 from kamipo/add_stored_procedure_test_in_mysql2
Add stored procedure test in mysql2
2015-10-20 14:02:23 -06:00
Ryuta Kamizono
d39b6f77fc Add stored procedure test in mysql2 2015-10-15 13:18:21 +09:00
Ryuta Kamizono
f8438ae336 Fix to correctly schema dump the tinyblob
Currently `tinyblob` is dumped to `t.binary "tiny_blob", limit: 255`.
But `t.binary ... limit: 255` is generating SQL to `varchar(255)`.
It is incorrect. This commit fixes this problem.
2015-10-15 05:38:43 +09:00
eileencodes
ee824c8858 Fix regression in inverse_of on through associations
`inverse_of` on through associations was accidently removed/caused to
stop working in commit f8d2899 which was part of a refactoring on
`ThroughReflection`.

To fix we moved `inverse_of` and `check_validity_of_inverse!` to the
`AbstractReflection` so it's available to the `ThroughReflection`
without having to dup any methods. We then need to delegate `inverse_name`
method in `ThroughReflection`. `inverse_name` can't be moved to
`AbstractReflection` without moving methods that set the instance
variable `@automatic_inverse_of`.

This adds a test that ensures that `inverse_of` on a `ThroughReflection`
returns the correct class name, and the correct record for the inverse
relationship.

Fixes #21692
2015-09-26 16:26:56 -04:00
Jean Boussier
4ccdd4122d Implement ActiveRecord::Base.ignored_columns 2015-09-24 11:04:44 -04:00
Sean Griffin
2c7d0d42ac 0 precision is not the same as no precision
And we are passing them as separate types in the query, which means 0
precision is still not supported by older versions of MySQL. I also
missed a handful of other cases where they need to be conditionally
applied.
2015-09-23 09:15:59 -06:00
Sean Griffin
f696494aed Don't attempt to specify datetime precision unless supported
Specifically, versions of MySQL prior to 5.6 do not support this, which
is what's used on Travis by default. The method `mysql_56?` appeared to
only ever be used to conditionally apply subsecond precision, so I've
generalized it and used it more liberally.

This should fix the test failures caused by #20317
2015-09-23 09:09:50 -06:00