Commit Graph

155 Commits

Author SHA1 Message Date
Sebastián Palma
db6eb846eb This PR adds support to retrieve partitioned indexes when asking for
indexes in a table.

Currently the pg_class catalog is filtered out to retrieve the indexes in a
table by its relkind value. Which in versions lower than 11 of PostgreSQL
is always `i` (lower case). But since version 11, PostgreSQL
supports partitioned indexes referenced with a relkind value of `I`
(upper case). This makes any feature within the current code base to exclude those
partitioned indexes.

The solution proposed is to make use of the `IN` clause to filter those
relkind values of `i` and/or `I` when retrieving a table indexes.
2020-02-06 07:36:44 +02:00
Jean Boussier
48c716bbfa Instantiate ConnectionPool with a DatabaseConfig rather than a ConnectionSpecification 2019-09-24 15:12:22 +02:00
John Crepezzi
b8b2d40659 Make all reads on configuration_hash use methods
Convert all uses of `db_config.configuration_hash[*]` to use methods
defined on an implementation of `DatabaseConfigurations::DatabaseConfig`.

Since we want to get away from accessing properties directly on the
underlying configuration hash, we'll move here to accessing those values
via the implementations on `DatabaseConfig` (or more specifically,
`HashConfig`).

There are still codepaths that are passing around `configuration_hash`,
and follow-on PRs will address those with the goal of using
configuration objects everywhere up until the point we pass a resolved
hash over to the underlying client.

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-09-23 16:46:05 -04:00
eileencodes
b8fc0150d6 Reduce surface area of ConnectionSpecification
Eventually we'd like to get rid of this class altogether but for now
this PR reduces the surface area by removing methods from the class and
moving classes out into their own files.

* `adapter_method` was moved into database configurations
* `initialize_dup` was removed because it was only used in tests
* Resolver is now it's own class under connection adapters
* ConnectionUrlResolver, only used by the configurations, is in a class
under DatabaseConfigurations

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2019-09-13 22:05:02 -04:00
eileencodes
ce9b197cc9 Use symbols everywhere for database configurations
Previously in some places we used symbol keys, and in some places we used
string keys. That made it pretty confusing to figure out in a particular
place what type of configuration object you were working with.

Now internally, all configuration hashes are keyed by symbols and
converted to such on the way in.

A few exceptions:

- `DatabaseConfigurations#to_h` still returns strings for backward compatibility
- Same for `legacy_hash`
- `default_hash` previously could return strings, but the associated
  comment mentions it returns symbol-key `Hash` and now it always does

Because this is a change in behavior, a few method renames have happened:

- `DatabaseConfig#config` is now `DatabaseConfig#configuration_hash` and returns a symbol-key `Hash`
- `ConnectionSpecification#config` is now `ConnectionSpecification#underlying_configuration_hash` and returns the `Hash` of the underlying `DatabaseConfig`
- `DatabaseConfig#config` was added back, returns `String`-keys for backward compatibility, and is deprecated in favor of the new `configuration_hash`

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-09-13 08:53:22 -04:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
Fumiaki MATSUSHIMA
61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
Ali Ibrahim
1c6e508ade Cache database version in schema cache
* The database version will get cached in the schema cache file during the
    schema cache dump. When the database version check happens, the version will
    be pulled from the schema cache and thus avoid querying the database for
    the version.
  * If the schema cache file doesn't exist, we'll query the database for the
    version and cache it on the schema cache object.
  * To facilitate this change, all connection adapters now implement
    #get_database_version and #database_version. #database_version returns the
    value from the schema cache.
  * To take advantage of the cached database version, the database version check
    will now happen after the schema cache is set on the connection in the
    connection pool.
2019-04-03 11:10:14 -04:00
Ryuta Kamizono
97347d8c40 Support Optimizer Hints
We as Arm Treasure Data are using Optimizer Hints with a monkey patch
(https://gist.github.com/kamipo/4c8539f0ce4acf85075cf5a6b0d9712e),
especially in order to use `MAX_EXECUTION_TIME` (refer #31129).

Example:

```ruby
class Job < ApplicationRecord
  default_scope { optimizer_hints("MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(jobs)") }
end
```

Optimizer Hints is supported not only for MySQL but also for most
databases (PostgreSQL on RDS, Oracle, SQL Server, etc), it is really
helpful to turn heavy queries for large scale applications.
2019-03-16 18:44:55 +09:00
Bob Lail
91ed21b304 Add insert_all to ActiveRecord models (#35077)
Adds a method to ActiveRecord allowing records to be inserted in bulk without instantiating ActiveRecord models. This method supports options for handling uniqueness violations by skipping duplicate records or overwriting them in an UPSERT operation.

ActiveRecord already supports bulk-update and bulk-destroy actions that execute SQL UPDATE and DELETE commands directly. It also supports bulk-read actions through `pluck`. It makes sense for it also to support bulk-creation.
2019-03-05 11:16:44 -08:00
Ryuta Kamizono
a2ad8f456e Support default expression for MySQL
MySQL 8.0.13 and higher supports default value to be a function or
expression.

https://dev.mysql.com/doc/refman/8.0/en/create-table.html
2018-10-25 18:11:22 +09:00
utilum
a72bca8230 Add method_call_assertions and use them instead of Mocha
Six Mocha calls prove quite resistant to Minitestification. For example,
if we replace

```
  ActiveRecord::Associations::HasManyAssociation
    .any_instance
    .expects(:reader)
    .never
```

with `assert_not_called`, Minitest wisely raises

```
NameError: undefined method `reader' for class `ActiveRecord::Associations::HasManyAssociation'
```

as `:reader` comes from a deeply embedded abstract class,
`ActiveRecord::Associations::CollectionAssociation`.

This patch tackles this difficulty by adding
`ActiveSupport::Testing::MethodCallAsserts#assert_called_on_instance_of`
which injects a stubbed method into `klass`, and verifies the number of
times it is called, similar to `assert_called`. It also adds  a convenience
method, `assert_not_called_on_instance_of`, mirroring
`assert_not_called`.

It uses the new method_call_assertions to replace the remaining Mocha
calls in `ActiveRecord` tests.

[utilum + bogdanvlviv + kspath]
2018-08-13 13:05:14 +02:00
James Mead
30735ab726 Make Mocha setup explcitly Minitest-specific
This has been possible since Mocha v1.0 and makes it clear that we want
Mocha to integrate with Minitest, not Test::Unit.
2018-04-07 12:23:40 +01:00
Rafael Mendonça França
feb1ddae02 Merge remote-tracking branch 'origin/master' into unlock-minitest 2017-08-01 17:34:14 -04:00
Kir Shatrov
831be98f9a Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Matthew Draper
50c4bd9ff6 Reset the fixture cache after (re)loading the schema 2017-06-03 16:28:54 +09:30
Ryuta Kamizono
416d85b65e
Remove unused require
These files are not using `strip_heredoc`.

Closes #27976
2017-02-12 19:38:49 -07:00
Rafael Mendonça França
41e177ee06
Set time as a timezone aware type and remove related deprecation 2016-12-29 17:53:03 -05:00
Ryuta Kamizono
407e43866e Consolidate ActiveRecord::TestCase and ActiveSupport::TestCase in AR test cases 2016-08-14 04:34:35 +09:00
Xavier Noria
80e66cc4d9 normalizes indentation and whitespace across the project 2016-08-06 20:16:27 +02: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
Arthur Neves
2abcdfd978 Remove load_paths file 2016-02-27 13:03:57 -05:00
Abdelkader Boudih
fb24d0ed6c Remove legacy mysql adapter 2015-12-17 15:54:57 +00:00
Yasuo Honda
0dc8166536 Use adapter supports_datetime_with_precision to support 3rd party adapter tests 2015-11-30 20:04:46 +00:00
Ryuta Kamizono
d9e74ace9f Make AbstractMysqlAdapter#version public 2015-10-15 07:18:55 +09:00
Ryuta Kamizono
94d2499156 Fix subsecond precision supported version
Fractional Seconds supported version is 5.6.4 or higher.

http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
2015-10-08 18:20:30 +09: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
Ronak Jangir
796c83fca9 Removed mocha from Active Record Part 1 2015-08-25 22:07:25 +05:30
Jori Hardman
e975d7cd1a Ensure that microsecond precision is only used for version of mysql that support it. Fixes #19711 2015-07-20 15:30:10 -05: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
Matthew Draper
b5eb0b6cc3 Revert "Leave all our tests as order_dependent! for now"
This reverts commit 2f52f969885b2834198de0045748436a4651a94e.

Conflicts:
	actionmailer/test/abstract_unit.rb
	actionview/test/abstract_unit.rb
	activemodel/test/cases/helper.rb
	activerecord/test/cases/helper.rb
	activesupport/test/abstract_unit.rb
	railties/test/abstract_unit.rb
2015-03-06 04:38:54 +10:30
Ryuta Kamizono
4b38a99e7a Extract precision from datetime and time columns
The cause by which the test suite for the mysql adapter broke in 1502cae
(reverted 89ba5bb) is because the precision was not extracted.

The rounding problem in mysql adapter has not been fixed, but `mysql_56`
helper tested only mysql2 adapter, its behavior was not apparent.
2015-02-19 16:00:16 +09:00
Yves Senn
9e9a3c5314 get rid of transaction warning when running PG tests.
This finally removes the warning "WARNING:  there is no transaction in progress"
when running Active Record tests using PostgreSQL.
2015-02-12 14:45:34 +01:00
Sean Griffin
5cd3bbbb83 Time columns should support time zone aware attributes
The types that are affected by `time_zone_aware_attributes` (which is on
by default) have been made configurable, in case this is a breaking
change for existing applications.
2015-01-15 08:04:43 -07:00
Rafael Mendonça França
07d3d40234 Change transaction callbacks to not swallowing errors.
Before this change any error raised inside a transaction callback
are rescued and printed in the logs.

Now these errors are not rescue anymore and just bubble up,
as the other callbacks.
2015-01-04 11:58:44 -03:00
claudiob
64b09823e6 Remove redundant to_s in interpolation 2014-10-30 08:48:32 -07:00
grosser
336783ad96 speed up fixtures by not loading all their classes 2014-10-06 19:50:58 -07:00
Godfrey Chan
2b41343c34 Default to sorting user's test cases for now
Goals:

1. Default to :random for newly generated applications
2. Default to :sorted for existing applications with a warning
3. Only show the warning once
4. Only show the warning if the app actually uses AS::TestCase

Fixes #16769
2014-09-08 05:32:16 -07:00
Abdelkader Boudih
0ab9301f2a Added enable_extension! to helper 2014-09-05 21:20:17 +00:00
Matthew Draper
2f52f96988 Leave all our tests as order_dependent! for now
We're seeing too many failures to believe otherwise.

This reverts commits bc116a55ca3dd9f63a1f1ca7ade3623885adcc57,
cbde413df3839e06dd14e3c220e9800af91e83ab,
bf0a67931dd8e58f6f878b9510ae818ae1f29a3a, and
2440933fe2c27b27bcafcd9019717800db2641aa.
2014-09-02 23:55:34 +09:30
Jeremy Kemper
41e48c2874 MySQL: skip GTID-unsafe statement tests when enforce_gtid_consistency is enabled 2014-09-01 22:36:05 -07:00
JoseLuis Torres
af16fd5793 adding the exception RecordNotFound to UUID find 2014-08-21 11:46:19 -05:00
Arthur Neves
b11b1e868a
Add option to stop swallowing errors on callbacks.
Currently, Active Record will rescue any errors raised within
after_rollback/after_create callbacks and print them to the
logs. Next versions of rails will not rescue those errors anymore,
and just bubble them up, as the other callbacks.

This adds a opt-in flag to enable that behaviour, of not rescuing
the errors.
    Example:
      # For not swallow errors in after_commit/after_rollback
      config.active_record.errors_in_transactional_callbacks = true

[fixes #13460]
2014-08-18 14:47:48 -04:00
Akira Matsuda
2440933fe2 Finally! None of our tests are order_dependent! 2014-08-14 11:22:24 +09:00
Rafael Mendonça França
82e28492e7 💣 2014-08-12 11:00:01 -03:00
Rafael Mendonça França
e81f3c210e Nobody sucks so nobody should call this awful method name 2014-08-12 10:51:41 -03:00
Akira Matsuda
6ffb29d24e users_dont_suck_but_only_we_suck_and_only_our_tests_are_order_dependent!
Calling ActiveSupport::TestCase.i_suck_and_my_tests_are_order_dependent! in AS::TestCase makes
everyone's tests order dependent, which should never be done by the framework.
2014-08-12 19:37:04 +09:00
Rafael Mendonça França
fd6aaaa0c3 Stop requiring mocha automatically
We are planning to remove mocha from our test suite because of
performance problems. To make this possible we should stop require mocha
on ActionSupport::TestCase.

This should not affect applications since users still need to add mocha
to Gemfile and this already load mocha.

Added FIXME notes to place that still need mocha removal
2014-07-19 17:35:12 -03:00