Commit Graph

12494 Commits

Author SHA1 Message Date
Akira Matsuda
8cc828c9b1 Missing require "active_support/multibyte/chars"
this probably fixes #25840
2017-01-27 20:20:11 +09:00
yuuji.yaginuma
b8c34d1a09 move db_migrate_path method to Migration module
Since `Migration` module is included in both `MigrationGenerator` and
`ModelGenerator`, no need to define a common method for each class.
2017-01-22 11:44:31 +09:00
Ryuta Kamizono
7674df550b Deprecate initialize_schema_migrations_table and initialize_internal_metadata_table
These internal initialize methods are no longer used internally.
2017-01-20 00:21:30 +09:00
Matthew Draper
893d5fb0a2 Revert "Merge pull request #27718 from kamipo/remove_internal_public_methods"
This reverts commit 39c77eb1843f79925c7195e8869afc7cb7323682, reversing
changes made to 9f6f51be78f8807e18fc6562c57af2fdbf8ccb56.
2017-01-20 01:02:03 +10:30
Matthew Draper
7b4514c6ab Merge pull request #27384 from matthewd/bigint-pk-tweaks
Tweak bigint PK handling
2017-01-20 00:58:41 +10:30
Matthew Draper
72e59fedb1 Tweak bigint PK handling
* Don't force PKs on tables that have explicitly opted out
* All integer-like PKs are autoincrement unless they have an explicit
  default
2017-01-18 23:25:52 +10:30
Ryuta Kamizono
5c624d0c1c Remove initialize_schema_migrations_table and initialize_internal_metadata_table internal public methods
These internal methods accidentally appeared in the doc, and so almost
useless. It is enough to create these internal tables directly, and
indeed do so in several places.

https://github.com/rails/rails/blob/v5.0.1/activerecord/lib/active_record/schema.rb#L55
https://github.com/rails/rails/blob/v5.0.1/activerecord/lib/active_record/railties/databases.rake#L6
https://github.com/rails/rails/blob/v5.0.1/activerecord/lib/active_record/tasks/database_tasks.rb#L230
2017-01-18 12:22:27 +09:00
Andrew White
4965fc1249 Merge pull request #27674 from kjg/migration_generator_honor_path_config
Generate migrations at path set by `config.paths["db/migrate"]`
2017-01-17 15:56:07 +00:00
Ryuta Kamizono
24f264e9ca SQLite: Foreign Key Support
https://www.sqlite.org/foreignkeys.html
2017-01-17 08:20:10 +09:00
Kevin Glowacz
c942361a60
Generate migrations at path set by config.paths["db/migrate"] 2017-01-16 12:24:37 -06:00
Ryuta Kamizono
974f5fbbc2 Translate Foreign Key violation to the specific exception for SQLite3 adapter
Raise `ActiveRecord::InvalidForeignKey` when a record cannot be inserted
or updated because it references a non-existent record for SQLite3
adapter.
2017-01-16 22:44:35 +09:00
Kasper Timm Hansen
a5632d8495 Revert "Don't guard against touch: []."
`timestamp_attributes_for_updates_in_model` returns an empty
array when a model has no `updated_at` or `updated_on`.

So my previously thought uncommon case is a lot more likely
now.

This reverts commit a0a1ede8c2eb6436571eae8778033162d1f9dcc3.
2017-01-15 21:53:57 +01:00
Kasper Timm Hansen
0bc8d0fb88 Merge pull request #27618 from kamipo/fix_uuid_default_nil
Fix UUID primary key with default nil in legacy migration
2017-01-15 20:08:02 +01:00
Kasper Timm Hansen
a0a1ede8c2 Don't guard against touch: [].
Closes #27683.

Seeing a code sample that leads to what we're guarding against:

```ruby
Topic.update_counters(1, replies_count: 1, touch: [])
```

It doesn't look like a case people would ever intentionally end
up with. Thus we're better off sparing the conditional.

Note: it could happen if a method returns an empty array
that's then passed to `update_counters` and its touchy friends.
But `[].presence` can fix that once people see their query blow
up.

[ Eugene Kenny & Kasper Timm Hansen ]
2017-01-15 19:36:34 +01:00
Kasper Timm Hansen
31a95eda42 Merge pull request #27660 from akihiro17/updates-timestamp
Add the touch option to ActiveRecord#increment! and decrement!
2017-01-14 19:00:07 +01:00
Ryuta Kamizono
57c44f0d09 type_condition should be overwritten by create_with_value in scope_for_create
`type_condition` should be overwritten by `create_with_value`. So `type`
in `create_with_value` should be a string because `where_values_hash`
keys are converted to string.

Fixes #27600.
2017-01-15 01:09:51 +09:00
eileencodes
e15a23fa35 Fix pool_from_any_process to use most recent spec
If a process is forked more than once, the pool was grabbing the oldest
spec, not the most recent spec. This wasn't noticed before because most
folks are lilely forking the process only once.

If you're forking the process multiple times however the wrong spec name
will be returned and an incorrect connection will be used for the
process.

This fixes the issue by reversing the list of spec names so we can grab
the most recent spec rather than the oldest spec.
2017-01-13 16:34:01 -08:00
akihiro17
bad9bfbea6 Add the touch option to ActiveRecord#increment! and decrement!
Supports the `touch` option from update_counters.
The default behavior is not to update timestamp columns.
2017-01-14 01:00:33 +09:00
Akira Matsuda
9360b6be63 class Foo < Struct.new(:x) creates an extra unneeded anonymous class
because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
2017-01-13 15:13:47 +09:00
Akira Matsuda
b70fc698e1 Reduce string objects by using \ instead of + or << for concatenating strings
(I personally prefer writing one string in one line no matter how long it is, though)
2017-01-12 17:45:37 +09:00
Akira Matsuda
d688814a67 beginrescueend 2017-01-12 17:45:37 +09:00
Vijay Dev
8898a0ae2a Merge branch 'master' of github.com:rails/docrails
Conflicts:
	railties/lib/rails/generators.rb
2017-01-11 15:15:13 +00:00
Kouhei Sutou
b260b13c5b Fix indent 2017-01-11 17:06:56 +09:00
Ryuta Kamizono
4cfa60558a Improve deprecation message for deprecated reflection class name 2017-01-10 05:07:25 +09:00
Ryuta Kamizono
3cd4c7c0ff Suppress deprecation message to has_and_belongs_to_many only once
Passing a class to `has_and_belongs_to_many` show deprecation message
three times. It is enough only once.
2017-01-10 05:00:53 +09:00
Kasper Timm Hansen
3bc747bd86 Merge pull request #27551 from kirs/deprecate-class-name-as-class
Deprecate reflection class name to accept a class
2017-01-09 19:58:22 +01:00
Kir Shatrov
8312a0d222 Deprecate reflection class name to accept a class
The idea of `class_name` as an option of reflection is that passing a
string would allow us to lazy autoload the class.

Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary
and creating possible circular dependencies.
2017-01-09 13:08:33 -05:00
Ryuta Kamizono
c352f12cbb Fix UUID primary key with default nil in legacy migration
UUID primary key with no default value feature (#10404, #18206) was lost
in legacy migration caused by #25395 got merged. Restore the feature
again in legacy migration.
2017-01-09 22:29:44 +09:00
Kasper Timm Hansen
7f19f30819 Merge pull request #25427 from eugeneius/update_increment_documentation
Update increment! documentation [ci skip]
2017-01-08 20:56:38 +01:00
Sean Griffin
11a50f4811 Merge pull request #27598 from NickLaMuro/fix-deep-nesting-where-clauses-with-joins
Fix bug with symbolized keys in .where with nested join
2017-01-07 17:30:34 -05:00
Nick LaMuro
c322b7c2b1 Adds .to_s to table_name call
Avoids a NoMethodError when table_name is a symbol instead of a string.
2017-01-06 17:59:30 -06:00
schneems
93ee268ef4 Preserve up and down return type
In Rails 4.2 calling `ActiveRecord::Migrator.migrate` would return an array of results. Without realizing that this return type was expected I accidentally introduced a change in 4d60e93174

This PR preserves the previous behavior and adds a test on the return type. This will need a backport to 5.0 branch.
2017-01-06 13:30:42 -06:00
Rafael França
b3bd6451b1 Merge pull request #27294 from eavgerinos/doc-ar-callbacks-order
[documentation] ActiveRecord: Document order of Callbacks
2017-01-06 04:39:31 -05:00
Akira Matsuda
5f03172f54 Privatize unneededly protected methods in Active Record 2017-01-05 20:01:02 +09:00
Akira Matsuda
5473e390d3 self. is not needed when calling its own instance method
Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
2017-01-05 19:58:52 +09:00
Akira Matsuda
d8e0282af9 This method is never called since 8e633e505880755e7e366ccec2210bbe2b5436e7 2017-01-05 18:55:28 +09:00
Ryuta Kamizono
801a21e6c9 Optimizing information_schema query for foreign_keys
Need `table_name` to avoid all databases scan.
See https://dev.mysql.com/doc/refman/5.7/en/information-schema-optimization.html.

```
> EXPLAIN SELECT fk.referenced_table_name AS 'to_table', fk.referenced_column_name AS 'primary_key', fk.column_name AS 'column', fk.constraint_name AS 'name', rc.update_rule AS 'on_update', rc.delete_rule AS 'on_delete' FROM information_schema.key_column_usage fk JOIN information_schema.referential_constraints rc USING (constraint_schema, constraint_name) WHERE fk.referenced_column_name IS NOT NULL AND fk.table_schema = 'activerecord_unittest' AND fk.table_name = 'fk_test_has_pk' AND rc.table_name = 'fk_test_has_pk'\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: fk
   partitions: NULL
         type: ALL
possible_keys: NULL
          key: TABLE_SCHEMA,TABLE_NAME
      key_len: NULL
          ref: NULL
         rows: NULL
     filtered: NULL
        Extra: Using where; Open_full_table; Scanned 0 databases
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: rc
   partitions: NULL
         type: ALL
possible_keys: NULL
          key: TABLE_NAME
      key_len: NULL
          ref: NULL
         rows: NULL
     filtered: NULL
        Extra: Using where; Open_full_table; Scanned 1 database; Using join buffer (Block Nested Loop)
2 rows in set, 1 warning (0.00 sec)
```

Fixes #27579.
2017-01-05 14:36:48 +09:00
Chris Holmes
f8ab3ae18f Raise error when has_many through is defined before through association
https://github.com/rails/rails/issues/26834

This change raises an error if a has_many through association
is defined before the through association.
2017-01-04 11:56:08 +00:00
Ryuta Kamizono
b334aa0ea4 Fix find_by and where consistency
The alternative of #26213.

Currently `find_by` and `where` with AR object return inconsistent
result. This is caused by statement cache does not support AR object.
Passing to finder method to fix the issue.

Fixes #26210.
2017-01-04 12:27:44 +09:00
Rafael Mendonça França
127509c071
Revert "Merge pull request #21233 from mtsmfm/disable-referential-integrity-without-superuser-privileges"
This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing
changes made to 5c40239d3104543e70508360d27584a3e4dc5baf.

Reason: Broke the isolated tests.
https://travis-ci.org/rails/rails/builds/188721346
2017-01-03 22:11:16 -05:00
Rafael Mendonça França
b6ffb5efcb
Revert "Merge pull request #27550 from mtsmfm/fix-generator-command-for-nested-rails-engine"
This reverts commit 1e969bfb98b88799e2c759fce25a1d8cf00d7ce7, reversing
changes made to a5041f267ded119c2d00b8786c2f2c1e3f93c8a1.

Reason: It breaks the public API
2017-01-03 21:51:18 -05:00
Rafael França
1e969bfb98 Merge pull request #27550 from mtsmfm/fix-generator-command-for-nested-rails-engine
Fix generator command for nested (namespaced) rails engine
2017-01-03 21:45:25 -05:00
Rafael França
eeac6151a5 Merge pull request #21233 from mtsmfm/disable-referential-integrity-without-superuser-privileges
Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
2017-01-03 20:38:50 -05:00
Rafael França
5c40239d31 Merge pull request #25522 from kamipo/fix_select_rows_method_signature_for_consistency
Fix `select_rows` method signature for consistency
2017-01-03 19:48:56 -05:00
Rafael Mendonça França
61b5f5d2f1
Remove unneeded requires at active record 2017-01-03 19:42:36 -05:00
Rafael Mendonça França
fdc219e0f8
Merge pull request #26689 from kamipo/deprecate_passing_name_to_indexes
Deprecate passing `name` to `indexes` like `tables`
2017-01-03 19:25:14 -05:00
Rafael Mendonça França
0df8649f58
Remove deprecation of using ActiveRecord::Base instance in .update 2017-01-03 19:22:52 -05:00
Rafael Mendonça França
e229580b4b
Remove deprecated db:test:clone* tasks 2017-01-03 19:10:31 -05:00
Ryuta Kamizono
457e6c77d4 Deprecate passing name to indexes like tables
Passing `name` to `tables` is already deprecated at #21601.
Passing `name` to `indexes` is also unused.
2017-01-04 08:48:59 +09:00
Ryuta Kamizono
cb1803591e Fix select_rows method signature for consistency
Related #22973, #24708.

`select_all`, `select_one`, `select_value`, and `select_values` method
signature is `(arel, name = nil, binds = [])`.
But `select_rows` is `(sql, name = nil, binds = [])`.
2017-01-04 07:44:45 +09:00