Commit Graph

628 Commits

Author SHA1 Message Date
Sean Griffin
f1a0fa9e19 Refactor microsecond precision to be database agnostic
The various databases don't actually need significantly different
handling for this behavior, and they can achieve it without knowing
about the type of the object.

The old implementation was returning a string, which will cause problems
such as breaking TZ aware attributes, and making it impossible for the
adapters to supply their logic for time objects.
2015-02-10 11:55:59 -07:00
Ryuta Kamizono
f983912037 Fix rounding problem for PostgreSQL timestamp column
If timestamp column have the precision, it need to format according to
the precision of timestamp column.
2015-02-08 22:22:55 +09:00
Andrew White
31fafe0a32 Merge pull request #18602 from kamipo/respect_database_charset_and_collation
Respect the database default charset for `schema_migrations` table.
2015-02-08 13:12:01 +00:00
Ryuta Kamizono
1f39b731c1 Remove unused line 2015-02-08 20:14:07 +09:00
Ryuta Kamizono
0bbff5ee16 Respect the database default charset for schema_migrations table.
The charset of `version` column in `schema_migrations` table is depend
on the database default charset and collation rather than the encoding
of the connection.
2015-02-08 11:19:33 +09:00
Sean Griffin
1492e83e49 rm Type#number?
This predicate is only used in `query_attribute`, and is relatively easy
to remove without adding a bunch of is a checks.
2015-02-07 17:36:22 -07:00
Melody
2eeb29a925 Fix test cases for money, bit and bit_varying 2015-02-04 11:07:08 -05:00
Vipul A M
6eced6a1fe Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 onwards. 2015-02-03 20:51:40 +05:30
Sean Griffin
b93b39eff6 Remove most type related predicates from Column
Remaining are `limit`, `precision`, `scale`, and `type` (the symbol
version). These will remain on the column, since they mirror the options
to the `column` method in the schema definition DSL
2015-01-30 11:42:54 -07:00
Sean Griffin
96ac14a385 Always convert strings to UTF-8, regardless of column type in SQLite
All columns which would map to a string primitive need this behavior.
Binary has it's own marker type, so it won't go through this conversion.
String and text, which need this, will.

Fixes #18585.
2015-01-28 15:19:13 -07:00
Sean Griffin
b06f64c348 Remove Relation#bind_params
`bound_attributes` is now used universally across the board, removing
the need for the conversion layer. These changes are mostly mechanical,
with the exception of the log subscriber. Additional, we had to
implement `hash` on the attribute objects, so they could be used as a
key for query caching.
2015-01-27 16:10:03 -07:00
Sean Griffin
7a69e27cde Fix test failure on PG caused by 7c6f3938dee47f093 2015-01-23 16:16:16 -07:00
Sean Griffin
e8460f8bbe Don't error when invalid json is assigned to a JSON column
Keeping with our behavior elsewhere in the system, invalid input is
assumed to be `nil`.

Fixes #18629.
2015-01-21 11:48:32 -07:00
Yves Senn
7675364fe0 tests, use drop_table if_exists: true in our test suite. 2015-01-20 13:30:12 +01:00
Ryuta Kamizono
bd78cc8833 Should escape regexp wildcard character .
`.` is regexp meta character. It should be escape for `assert_match`
correctly.
2015-01-19 06:11:29 +09:00
Sean Griffin
ac6e6545de Stop passing a column to quote in tests
I'm planning on deprecating the column argument to mirror the
deprecation in [arel].

[arel]: 6160bfbda1
2015-01-10 15:45:47 -07:00
Yves Senn
a076256d63 remove deprecated support for PG ranges with exclusive lower bounds.
addresses 91949e48cf (commitcomment-9144563)
2015-01-05 11:09:29 +01:00
Ryuta Kamizono
3225ebfa06 Prefer array? rather than array
Slightly refactoring `PostgreSQLColumn`. `array` should be readonly.
`default_function` should be initialized by `super`. `sql_type` has been
removed `[]`. Since we already choose to remove it we should not change.
2015-01-04 07:32:03 +09:00
Rafael Mendonça França
acb1991910 Merge pull request #18067 from kamipo/format_datetime_string_according_to_precision
Format the datetime string according to the precision of the datetime field.

Conflicts:
	activerecord/CHANGELOG.md
2015-01-02 11:17:55 -03:00
Ryuta Kamizono
4157f5d172 Format the datetime string according to the precision of the datetime field.
Incompatible to rounding behavior between MySQL 5.6 and earlier.

In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:

http://bugs.mysql.com/bug.php?id=68760
2015-01-02 22:30:07 +09:00
Ryuta Kamizono
ae419af666 Allow precision option for MySQL datetimes. 2015-01-02 22:30:07 +09:00
Sean Griffin
8b07f18599 Stop explicitly passing nil as the column to type_cast
So we can change the arity later.
2015-01-01 11:24:29 -07:00
Sean Griffin
667b3ef873 Stop depending on columns for type information in PG quoting tests
A few of the tests weren't testing anything of value. The IP Address
tests are testing the type, not behavior of the connection adapter.
There are two CVE regression tests which are important, but don't have a
good place to go, so I've left them alone for now, as they call `quote`
and the focus right now is removing `column` from `type_cast`
2015-01-01 10:39:14 -07:00
Sean Griffin
d08dc37959 Stop relying on columns for type information in mysql2 casting tests
The column itself has no actual impact on the return value. These were
actually testing the behavior of the type object, which is sufficiently
covered elsewhere.
2015-01-01 10:11:33 -07:00
Sean Griffin
45973ac3c7 Stop relying on columns in mysql quoting tests
The behavior tested by the removed lines is sufficiently covered
elsewhere.
2015-01-01 10:07:54 -07:00
Sean Griffin
19537ecd0f Stop relying on columns in sqlite quoting tests
The string encoding test wasn't using the types for anything. The
boolean casting test included logic that should be in the tests for the
types, and the string test was legitimately not testing anything useful.
2015-01-01 10:00:08 -07:00
Arthur Neves
5acd24bbea
Ensures that primary_key method will return nil when multi-pk
When table has a composite primary key, the `primary_key` method for
sqlite3 and postgresql was only returning the first field of the key.

Ensures that it will return nil instead, as AR dont support composite pks.
2014-12-30 12:36:37 -05:00
Sean Griffin
b98668decb Go through normal where logic when preloading associations
This will allow eager type casting to take place as needed. There
doesn't seem to be any particular reason that the `in` statement was
forced for single values, and the commit message where it was introduced
gives no context.

See
d90b4e2615
2014-12-26 16:12:56 -07:00
Sean Griffin
a983e1e89c Correctly ignore case_sensitive for UUID uniqueness validation
I think we should deprecate this behavior and just error if you tell us
to do a case insensitive comparison for types which are not case
sensitive. Partially reverts 35592307

Fixes #18195
2014-12-26 13:04:29 -07:00
Ryuta Kamizono
9b3e7b396e Dump the default nil for PostgreSQL UUID primary key. 2014-12-26 17:54:08 +09:00
Sean Griffin
32f30d22d5 Add force: true to table created in tests
If the test is interrupted in a way that the teardown block fails to
run, the tests will fail to run until the table is removed manually
without this option.
2014-12-22 12:49:34 -07:00
Sean Griffin
b0f2b94dd3 Correctly handle limit on int4 and int8 types in PG
PG doesn't register it's types using the `int(4)` format that others do.
As such, if we alias `int8` to the other integer types, the range
information is lost. This is fixed by simply registering it separately.

The other option (which I specifically chose to avoid) is to pass the
information of the original type that was being aliased as an argument.
I'd rather avoid that, since an alias should truly be treated the same.
If we need different behavior for a different type, we should explicitly
register it with that, and not have a conditional based on aliasing.

Fixes #18144

[Sean Griffin & ysbaddaden]
2014-12-22 09:55:41 -07:00
Yves Senn
be1e0241f0 force: :cascade to recreate tables referenced by foreign-keys. 2014-12-19 11:27:04 +01:00
Godfrey Chan
c115a84c8b Relax the UUID regex
Apparently PG does not validate against RFC 4122. The intent of the original
patch is just to protect against PG errors (which potentially breaks txns, etc)
because of bad user input, so we shouldn't try any harder than PG itself.

Closes #17931
2014-12-18 00:51:05 -08:00
Ryuta Kamizono
b61a93b44e Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger. 2014-12-12 00:35:48 +09:00
Sean Griffin
65588b7463 Update test case for TZ aware attributes
The test added in 42418cfc94d1356d35d28d786f63e7fab9406ad6 wasn't
actually testing anything, since the bug was with TZ aware attributes
only.
2014-12-08 15:06:11 -07:00
Sean Griffin
42418cfc94 Allow custom handling of non-standard types in time_zone_conversion
PostgreSQL for example, allows infinity as a valid value for date time
columns. The PG type has explicit handling for that case. However, time
zone conversion will end up trampling that handling. Unfortunately, we
can't call super and then convert time zones.

However, if we get back nil from `.in_time_zone`, it's something we
didn't expect so we can let the superclass handle it.

Fixes #17971
2014-12-08 14:52:06 -07:00
Sean Griffin
4ed60af60d Revert to 4.1 behavior for casting PG arrays
The user is able to pass PG string literals in 4.1, and have it
converted to an array. This is also possible in 4.2, but it would remain
in string form until saving and reloading, which breaks our
`attr = save.reload.attr` contract. I think we should deprecate this in
5.0, and only allow array input from user sources. However, this
currently constitutes a breaking change to public API that did not go
through a deprecation cycle.
2014-12-08 11:42:29 -07:00
Sean Griffin
785d04e310 Add force: true to tables created in PG tests
If the tests are interupted and the teardown block doesn't run, the
developer needs to delete these manually in order to be able to run the
tests again.
2014-12-05 15:54:12 -07:00
Sean Griffin
670e7941d5 Correctly respect subtypes for PG arrays and ranges
The type registration was simply looking for the OID, and eagerly
fetching/constructing the sub type when it was registered. However,
numeric types have additional parameters which are extracted from the
actual SQL string of the type during lookup, and can have their behavior
change based on the result.

We simply need to use the block form of registration, and look up the
subtype lazily instead.

Fixes #17935
2014-12-05 15:34:30 -07:00
noam
b64fb3020b Failure to rollback t.timestamps when within a change_table migration
When running the following migration:

    change_table(:table_name) { |t| t/timestamps }

The following error was produced:

    wrong number of arguments (2 for 1) .... /connection_adapters/abstract/schema_statements.rb:851:in `remove_timestamps'

This is due to `arguments` containing an empty hash as its second
argument.
2014-12-03 11:35:40 -05:00
Yves Senn
780269c732 pg tests, get rid of global schema schema_1. 2014-12-02 12:08:52 +01:00
Yves Senn
90e396ce65 pg tests, move uniqueness validation test to array tests. 2014-12-02 11:53:18 +01:00
Yves Senn
b8ec014b2d tests, extract pg number tests into separate file. 2014-12-02 11:46:08 +01:00
Yves Senn
af7c6e493c tests, move schema shorthand assertions into pg specific tests. 2014-12-02 11:35:53 +01:00
Yves Senn
bcf5b281a8 tests, move pg geometric tests out of base_test. 2014-12-02 11:00:19 +01:00
Aaron Patterson
e47b523fae ugh, forgot to add this test to cdd90f39d796986dabf1678b3277b230dbe18961 2014-12-01 11:46:57 -08:00
Erik Michaels-Ober
d1374f99bf Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
Aaron Patterson
63963801c0 oops, forgot to add the real assertion! 2014-11-24 14:18:33 -08:00
Aaron Patterson
fbef981fdc allow the "USING" statement to be specified on change column calls 2014-11-24 14:15:56 -08:00