Commit Graph

15211 Commits

Author SHA1 Message Date
Vipul A M
c91f4cc0f6 Change to use a more realistic example and not giving the impression that destroy_all is preferred way to destroy related records.
This example just wants to demonstrate callback behaviour.

[ci skip]
2016-05-05 15:30:21 -05:00
Arthur Neves
34856ba9fa
Retrive the right pool for db tasks 2016-05-05 15:29:11 -05:00
Arthur Neves
7d9d076e73
inline retrive_conn_pool method 2016-05-05 15:29:11 -05:00
Arthur Neves
40a8d2f3b5
Better code readability 2016-05-05 15:29:11 -05:00
Arthur Neves
c1ae7ec15b
Test to swap connection at runtime 2016-05-05 15:29:11 -05:00
Arthur Neves
9872905336
fix test 2016-05-05 15:29:11 -05:00
Arthur Neves
ac1c4e141b
Add spec_id tests 2016-05-05 15:29:11 -05:00
Arthur Neves
79154a3281
Use spec key, when given as spec_id 2016-05-05 15:29:11 -05:00
Arthur Neves
c1bc0d83de
Better specification_id method 2016-05-05 15:29:11 -05:00
Arthur Neves
314cf0398c
Rename method 2016-05-05 15:29:11 -05:00
Arthur Neves
b83fb84733
Refactor connection handler
ConnectionHandler will not have any knowlodge of AR models now, it will
only know about the specs.
Like that we can decouple the two, and allow the same model to use more
than one connection.

Historically, folks used to create abstract AR classes on the fly in
order to have multiple connections for the same model, and override the
connection methods.

With this, now we can override the `specificiation_id` method in the
model, to return a key, that will be used to find the connection_pool
from the handler.
2016-05-05 15:29:11 -05:00
Vipul A M
8afea8ebe7 delegate encode_with instead of to_yaml, which is deprecated 2016-05-05 15:08:18 -05:00
Kasper Timm Hansen
19ba522b90 [ci skip] Don't promote SQL interpolation.
After fb898e9, the `before_destroy` had some code that used
SQL interpolation left over. Don't think we should promote
that even if the values aren't directly from user input.
2016-05-05 17:04:21 +02:00
Vipul A M
fb898e986f Merge pull request #24859 from y-yagi/do_not_pass_conditon_to_destroy_all
do not pass conditions to `#destroy_all` [ci skip]
2016-05-05 07:37:20 -05:00
yuuji.yaginuma
c16a4ca397 do not pass conditions to #destroy_all [ci skip]
Passing conditions to `#destroy_all` was deprecated in c82c5f8.
2016-05-05 21:21:26 +09:00
Joe Rafaniello
d2660c8cad Fix some typos in comments.
[ci skip]
2016-05-04 12:22:23 -04:00
Vipul A M
a51bdd3ddc Followup of #24835
Fix failing tests
2016-05-03 17:18:21 -05:00
प्रथमेश Sonpatki
5fd17b9257 Merge pull request #24833 from Erol/fix-typo
Fix small typo in Active Record Migrations documentation
2016-05-03 06:59:19 -05:00
Erol Fornoles
2687a5e0ab Fix small typo in Active Record Migrations documentation [ci skip] 2016-05-03 19:55:45 +08:00
yuuji.yaginuma
e86a1bd1d7 remove empty? from CHANGELOG [ci skip]
Follow up to 98264a1343fad6bb6637893a37fd571916b4158c
2016-05-03 20:49:07 +09:00
Sean Griffin
98264a1343 Do not delegate AR::Base#empty? to all
Unlike `one?` and `none?`, `empty?` has interactions with methods
outside of enumerable. It also doesn't fit in the same vein.
`Topic.any?` makes sense. `Topic.empty?` does not, as `Topic` is not a
container.

Fixes #24808
Close #24812
2016-05-02 16:36:17 -05:00
Ryuta Kamizono
2e82ef3642 Add :nodoc: to schema_creation [ci skip]
`schema_creation` is not public API.

https://github.com/rails/rails/blob/v5.0.0.beta4/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L121
https://github.com/rails/rails/blob/v5.0.0.beta4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L78
2016-05-02 13:36:37 +09:00
Sean Griffin
a4b3c78e86 Merge pull request #24713 from tomkadwill/fix_counter_cache_increment
Fix counter_cache double increment bug

Close #24183
2016-04-30 22:48:50 -06:00
Vipul A M
7b37e3edaf Move comment up to the class, for both of the methods, and document on class level why we are doing this.
[ci skip]
2016-05-01 02:44:52 +05:30
Jon Moss
76f7da0c65 Replace Rails.version.to_f with Active Record
Rails should not be explicity mentioned within Active Record, since
railties and the Rails ecosystem is not required for use.
2016-04-30 12:32:30 -04:00
Vipul A M
3458ad92a1
rm unused require
Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-29 19:33:50 -07:00
Ryuta Kamizono
0eac27904e
Extract add_sql_comment! method
Refactor of #22911.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-29 17:54:38 -07:00
Ryuta Kamizono
2db8514d21
Treat blank comments as no comment for indexes
Follow up of 1683410.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-29 17:52:37 -07:00
yui-knk
7fc4979d4d
Migrations: move version-finding responsibility
`ActiveRecord::Migration` needn't know about migration version
compatibility lookup. Delegate it to the Compatibility module.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-29 15:10:03 -07:00
Vijay Dev
9d1bf059c0 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/configuring.md
2016-04-29 16:00:15 +00:00
Keenan Brock
ba05b3c218 test the number of times the schema is loading 2016-04-28 17:48:41 -04:00
Keenan Brock
dffbba1e2a schema_load triggers 2nd schema_load (via locking)
Currently, loading the schema (schema_load)
accesses the locking column (locking_column)
which defaults the value (reset_locking_column)
which invalidates the schema (reload_schema_from_cache)
which forces another schema load.

Good news:
The second schema_load does accesses locking_column,
but locking_column is set, so it does not reset_locking_column
and it does not trigger an infinite loop.

The solution is not invalidate the cache while default locking_column
2016-04-28 17:48:41 -04:00
Tom Kadwill
c3e3577f9d Fix counter_cache double increment bug 2016-04-28 21:22:26 +01:00
eileencodes
f7a986012a Prep Rails 5 beta 4 2016-04-27 15:48:47 -05:00
yuuji.yaginuma
cfa1df4b07 update record specified in key
`#first_or_initialize` does not use attributes to data acquisition.
Therefore, there is a possibility of updating the different record than the one
specified in the key, I think this is not expected behavior.
2016-04-27 10:33:27 +09:00
Rafael França
4a4eedb240 Merge pull request #24730 from vipulnsward/move-savepoints
Move remaining current_savepoint_name to savepoints module
2016-04-25 19:19:58 -03:00
Vipul A M
2af2d6b057 Dont simply assume a type is a valid database type. This is only always true in the case of sqlite.
Others adapters need to perform a check for validity.
Add coverage for mysql2 db type validation
2016-04-25 23:35:36 +05:30
Vipul A M
d58d9f713c Move remaining current_savepoint_name to savepoints module 2016-04-25 23:21:56 +05:30
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
Seva Orlov
c41ef01aec
remove_index do not fetch indexes if name is specified
There is no need to fetch all table indexes in remove_index if name is specified. If name is wrong, then StatementInvalid will be raised.

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-24 14:32:55 -07:00
Vipul A M
6c6eeda54d
Follow up of #23461
- Rename max to statement_limit
- Remove magic number 1000 from everywhere
- Defined StatementPool::DEFAULT_STATEMENT_LIMIT and started using it everywhere

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-24 13:28:48 -07:00
Vipul A M
35f32036b6
Include the Savepoints module in all adapters.
Adapters override `#supports_savepoints?` to return `true` if they
support transaction savepoints. Defaults to `false`.
2016-04-24 10:53:40 -07:00
Vipul A M
2fab3eee1f :nodoc: internal StatementPool class.
[ci skip]
2016-04-24 21:22:12 +05:30
Vipul A M
0f91e2bc25 s/statment/statement/ 2016-04-24 16:24:19 +05:30
Jeremy Daer
ab56c92f3c
Merge pull request #23461 from kamipo/prepared_statements_for_mysql2_adapter
Add prepared statements support for `Mysql2Adapter`
2016-04-23 22:28:52 -07:00
Jeremy Daer
7c45fa57a1
Merge pull request #24708 from kamipo/move_select_rows_implementation_to_super_class
Move `select_rows` implementation to super class
2016-04-23 21:26:33 -07:00
Guillermo Iguaran
77cd14bbbf Merge pull request #24705 from kamipo/add_nodoc_to_insert_versions_sql
Add `:nodoc:` to `insert_versions_sql` [ci skip]
2016-04-23 22:52:47 -05:00
Guillermo Iguaran
9f8a6c47c8 Merge pull request #24706 from kamipo/remove_in_doc_about_mysql_versions_below_5
Remove in the doc about MySQL versions below 5 [ci skip]
2016-04-23 22:50:26 -05:00
Ryuta Kamizono
c1ab4a2dbf Move select_rows implementation to super class 2016-04-24 11:20:46 +09:00
Ryuta Kamizono
9c8a086863 Move require 'ipaddr' in postgresql/oid/cidr.rb
`IPAddr` is used in `OID::Cidr`.
2016-04-24 11:09:08 +09:00
Ryuta Kamizono
7ec31ac429 Remove in the doc about MySQL versions below 5 [ci skip]
Follow up to #23458.
Active Record supports MySQL >= 5.0 now.
2016-04-24 11:02:30 +09:00
Ryuta Kamizono
5394f2cde8 Add :nodoc: to insert_versions_sql [ci skip]
Follow up to #24685. `insert_versions_sql` is not public API.
2016-04-24 10:54:53 +09:00
Vipul A M
210729c4cc Followup of #15771
Make sure we handle explicitly passed nil's to lock_version as well.
An explicitly passed nil value is now converted to 0 on LockingType,
so that we don't end up with ActiveRecord::StaleObjectError in update record
optimistic locking

Fixes #24695
2016-04-24 04:01:18 +05:30
Jeremy Daer
4c76ce6404
Schema load: Fix dupe version insert
Re. 6e098284e97250eaed6f30f5c7c362d87da986b0
2016-04-22 18:32:47 -07:00
Jeremy Daer
a14c811026
Merge pull request #24685 from vipulnsward/sqlite-compat-for-multi-insert
Gracefully fallback on version migrations for sqlite < 3.7.11
2016-04-22 15:33:59 -07:00
Vipul A M
6e098284e9 42dd2336b3 changed INSERT INTO versions to run in 1 single query.
This breaks for sqlite versions < 3.7.11, which is especially the case on Ubuntu 12.04 LTS, that has SQLite version 3.7.9 as default.

So we check for support for multi insert, before performing single query inserts, else fallback to older version of running multiple queries.
[Vipul A M & Yasuo Honda]
2016-04-23 03:18:13 +05:30
Sean Griffin
1ca6f7f767 Do not attempt to return connection with open transaction to pool (#24610)
When the query cache completes, if Active Record is still inside of a
transaction, it is because the transaction is meant to be left open
above this unit of work (such as transactional fixtures in tests). There
were several tests around the behavior of "tests" that were invalid, as
tests are not run through the executor. They have been changed to
reflect the new behavior, which is closer to what actually occurs in
Rails tests.

Fixes #23989
Fixes #24491
Close #24500
2016-04-22 12:56:43 -06:00
Rafael França
875c679a33 Merge pull request #24672 from mrkjlchvz/mc-space-bump
Minor space bump.
2016-04-21 10:51:47 -03:00
Mark
64bf0fcff4 Minor space bump. 2016-04-21 19:20:54 +08:00
प्रथमेश Sonpatki
868a49262c Revert "add doc for :type option of #create_join_table [ci skip]" 2016-04-21 07:54:06 +05:30
yuuji.yaginuma
1a409956de add doc for :type option of #create_join_table [ci skip]
Follow up to #24221.
2016-04-21 11:09:53 +09:00
Ryuta Kamizono
3f6574efb1 Add prepared statements support for Mysql2Adapter 2016-04-21 09:17:42 +09:00
Kasper Timm Hansen
3ff6b800f2 Merge pull request #24221 from gregmolnar/uuid
create_join_table should work with uuid
2016-04-20 22:13:17 +02:00
Jeremy Daer
3b38fb3d57
Merge pull request #23557 from kamipo/dump_indexes_in_create_for_generates_sql_in_one_query
Dump indexes in `create_table` for generates SQL in one query
2016-04-20 11:05:22 -07:00
Ryuta Kamizono
67f4994a0b
undef_method is not needed 2016-04-19 23:03:46 -07:00
Ryuta Kamizono
74b5112282 Dump indexes in create_table for generates SQL in one query
If the adapter supports indexes in create table, it generates SQL
in one query.
2016-04-20 10:24:18 +09:00
Ryuta Kamizono
da87a679c5 Fix test_blank_columns_created_in_block
Follow up to 1683410.
2016-04-20 07:38:04 +09:00
Jon Moss
1909095aea Remove unecessary comment 2016-04-19 16:48:40 -04:00
Jeremy Daer
1683410c5e
Database comments: Treat blank comments as no comment. Don't dump blank comments. 2016-04-19 12:31:23 -07:00
Ryuta Kamizono
dd58c3bf23 Define arel_visitor method on all adapters
`Arel::Visitors::VISITORS` was removed at https://github.com/rails/arel/pull/412.
2016-04-20 01:27:08 +09:00
Ryuta Kamizono
a80e944e18 Remove unused table_with_autoincrement table 2016-04-19 17:17:19 +09:00
Jeremy Daer
0c77018f8d
Merge pull request #24317 from Gaurav2728/unused_set_in_active_record
connection adapters column, delegation in Active Record have not use …
2016-04-19 01:08:39 -07:00
Jeremy Daer
db06ad6149
Merge pull request #24503 from prathamesh-sonpatki/add-test-for-warn-on-records-fetched-greater-than
Add missing test case for record_fetched_greater_than config
2016-04-19 01:06:04 -07:00
Jeremy Daer
0575f4646a
Merge pull request #24576 from yahonda/quote_column_name_for_reserved_word_size
Address ORA-00923 error by quoting a reserved word "SIZE"
2016-04-19 00:59:38 -07:00
Jeremy Daer
ca13731e61
Merge pull request #23497 from kamipo/extract_schema_qualified_name
Extract `extract_schema_qualified_name` method
2016-04-19 00:44:10 -07:00
Jeremy Daer
7854e69c74
Merge pull request #23515 from kamipo/extract_arel_visitor
Extract `arel_visitor` and move up to the abstract adapter
2016-04-19 00:43:11 -07:00
Jeremy Daer
f2f2d64429
Merge pull request #23523 from kamipo/avoid_truncation_in_uniqueness_validation
Avoid a string value truncation in uniqueness validation
2016-04-18 17:53:22 -07:00
Jeremy Daer
446190fbd2
Merge pull request #23522 from kamipo/add_value_too_long_exception_class
Add `ActiveRecord::ValueTooLong` exception class
2016-04-18 17:31:28 -07:00
Jeremy Daer
b36078fb8b
Merge pull request #24614 from kamipo/foreign_key_respects_table_name_prefix_and_suffix
`foreign_key` respects `table_name_prefix` and `table_name_suffix`
2016-04-18 17:21:28 -07:00
Ryuta Kamizono
0cae0ce5ce foreign_key respects table_name_prefix and table_name_suffix 2016-04-19 07:33:31 +09:00
Jeremy Daer
fe685c6292
Merge pull request #23622 from kamipo/primary_key_should_be_not_null
Primary key should be `NOT NULL`
2016-04-18 15:31:15 -07:00
Jeremy Daer
811c532351
Fix isolated test failures due to referencing ActiveRecord::Tasks::DatabaseAlreadyExists before another test happened to make it available 2016-04-18 13:03:37 -07:00
Sean Griffin
d63054bbcb Merge pull request #24607 from vipulnsward/where-clause-frozen-array
Don't create new arrays when trying to compute non_empty_predicates for ast generation
2016-04-18 14:00:46 -06:00
Jeremy Daer
485e7f25f2
Database comments: switch to keyword args for new table options
* Switch to keyword args where we can without breaking compat.
* Use add_table_options! for :options, too.
* Some code polish.
2016-04-18 12:42:24 -07:00
Vipul A M
1a9eb19ac4 Don't create new arrays when trying to compute non_empty_predicates for where clause predicate. Get a 3-4% improvement in AST generation.
Perf compare: https://gist.github.com/vipulnsward/7e4e9ecb157e574002313249a7969c82
2016-04-18 23:59:27 +05:30
Vipul A M
7f0df7b6a9 Merge pull request #24535 from tomash/association-validate-docs
Update ActiveRecord associations documentation on :validate option [ci skip]
2016-04-18 15:13:23 +05:30
Tomasz Stachewicz
33a9c57ee4 [ci skip] Update ActiveRecord associations documentation to avoid confusion with :validate option. Caused by #24532. 2016-04-18 11:38:53 +02:00
Yves Senn
38d6d4129b Merge pull request #24581 from vipulnsward/add-reference-named-unique-index-test
Add test to verify named unique index, when creating reference via add_reference
2016-04-18 09:35:38 +02:00
Prathamesh Sonpatki
dbaef766fb
Move CHANGELOG entry about database notices at the top [ci skip] 2016-04-18 10:37:17 +05:30
Jeremy Daer
5154701e20 Merge pull request #24551 from bogdanvlviv/notice_for_tasks
Added notice when a database is successfully created or dropped.
2016-04-17 15:21:43 -07:00
bogdanvlviv
26861302c9 Added notice when a database is successfully created or dropped. 2016-04-17 23:12:16 +03:00
Jeremy Daer
3b0a627a94 Merge pull request #22911 from Envek/database_comments
Add support for specifying comments for tables, columns, and indexes in database itself
2016-04-16 22:19:47 -07:00
Vipul A M
bca1872198 documentation for add_references index option [ci skip]
documentation for add_references index option [ci skip]
2016-04-17 02:06:25 +05:30
Alex Handley
d9565811f0
[ci skip] docs for add_references index option
- Add link for finding the addional options for index.
- Add example for unique index as this is a common requirement.
- Add link in guide for index options.
2016-04-16 21:32:22 +01:00
Vipul A M
ddb4636d24 Add test to verify named unique index, when creating reference via add_reference 2016-04-16 20:44:08 +05:30
Yasuo Honda
8a4a8b2aca Address ORA-00923 error by quoting a reserved word "SIZE" 2016-04-16 10:02:49 +00:00
Andrey Novikov
c690b9ce39
Add support for specifying comments for tables, columns, and indexes.
Comments are specified in migrations, stored in database itself (in its schema),
and dumped into db/schema.rb file.

This allows to generate good documentation and explain columns and tables' purpose
to everyone from new developers to database administrators.

For PostgreSQL and MySQL only. SQLite does not support comments at the moment.

See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html
See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
2016-04-16 10:17:26 +03:00
Vipul A M
65a7e90cc1 Add changelog for #24542
[ci skip]
2016-04-15 12:06:56 +05:30
Ryuta Kamizono
73af7945d5 Should keep quoting behaivor of a time column value in sqlite3 adapter
Follow up to #24542.

In MySQL and PostgreSQL, a time column value is saved as ignored the
date part of it. But in SQLite3, a time column value is saved as a string.

We should keep previous quoting behavior in sqlite3 adapter.

```
sqlite> CREATE TABLE "foos" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "start" time(0), "finish" time(4));
sqlite> INSERT INTO "foos" ("start", "finish") VALUES ('2000-01-01 12:30:00', '2000-01-01 12:30:00.999900');
sqlite> SELECT "foos".* FROM "foos";
1|2000-01-01 12:30:00|2000-01-01 12:30:00.999900
sqlite> SELECT  "foos".* FROM "foos" WHERE "foos"."start" = '2000-01-01 12:30:00' LIMIT 1;
1|2000-01-01 12:30:00|2000-01-01 12:30:00.999900
sqlite> SELECT  "foos".* FROM "foos" WHERE "foos"."start" = '12:30:00' LIMIT 1;
sqlite>
```
2016-04-15 03:45:02 +09:00
Ryuta Kamizono
28ec8c4a57 Add quoted_time for truncating the date part of a time column value
Context #24522.

TIME column on MariaDB doesn't ignore the date part of the string when
it coerces to time.

```
root@localhost [test] > CREATE TABLE `foos` (`id` int AUTO_INCREMENT PRIMARY KEY, `start` time(0), `finish` time(4)) ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec)

root@localhost [test] > INSERT INTO `foos` (`start`, `finish`) VALUES ('2000-01-01 12:30:00', '2000-01-01 12:30:00.999900');
Query OK, 1 row affected, 2 warnings (0.00 sec)

Note (Code 1265): Data truncated for column 'start' at row 1
Note (Code 1265): Data truncated for column 'finish' at row 1
root@localhost [test] > SELECT `foos`.* FROM `foos`;
+----+----------+---------------+
| id | start    | finish        |
+----+----------+---------------+
|  1 | 12:30:00 | 12:30:00.9999 |
+----+----------+---------------+
1 row in set (0.00 sec)

root@localhost [test] > SELECT  `foos`.* FROM `foos` WHERE `foos`.`start` = '2000-01-01 12:30:00' LIMIT 1;
Empty set (0.00 sec)

root@localhost [test] > SELECT  `foos`.* FROM `foos` WHERE `foos`.`start` = '12:30:00' LIMIT 1;
+----+----------+---------------+
| id | start    | finish        |
+----+----------+---------------+
|  1 | 12:30:00 | 12:30:00.9999 |
+----+----------+---------------+
1 row in set (0.00 sec)
```
2016-04-14 14:22:16 +09:00