1. 15 2月, 2017 1 次提交
  2. 06 2月, 2017 1 次提交
  3. 23 12月, 2016 1 次提交
  4. 11 12月, 2016 1 次提交
    • R
      Use `inspect` in `type_cast_for_schema` for date/time and decimal values · b01740f9
      Ryuta Kamizono 提交于
      Currently dumping defaults on schema is inconsistent.
      
      Before:
      
      ```ruby
        create_table "defaults", force: :cascade do |t|
          t.string   "string_with_default",   default: "Hello!"
          t.date     "date_with_default",     default: '2014-06-05'
          t.datetime "datetime_with_default", default: '2014-06-05 07:17:04'
          t.time     "time_with_default",     default: '2000-01-01 07:17:04'
          t.decimal  "decimal_with_default",  default: 1234567890
        end
      ```
      
      After:
      
      ```ruby
        create_table "defaults", force: :cascade do |t|
          t.string   "string_with_default",   default: "Hello!"
          t.date     "date_with_default",     default: "2014-06-05"
          t.datetime "datetime_with_default", default: "2014-06-05 07:17:04"
          t.time     "time_with_default",     default: "2000-01-01 07:17:04"
          t.decimal  "decimal_with_default",  default: "1234567890"
        end
      ```
      b01740f9
  5. 23 10月, 2016 1 次提交
  6. 15 10月, 2016 1 次提交
  7. 03 10月, 2016 1 次提交
  8. 24 9月, 2016 1 次提交
  9. 26 8月, 2016 1 次提交
  10. 07 8月, 2016 2 次提交
  11. 12 5月, 2016 1 次提交
    • S
      Fix false positive mutation detection when JSON is used with serialize · 6007e584
      Sean Griffin 提交于
      When looking for mutation, we compare the serialized version of the
      value to the before_type_cast form. `Type::Serialized` was breaking this
      contract by passing the already serialized attribute to the subtype's
      mutation detection. This never manifested previously, as all mutable
      subtypes either didn't do anything in their `serialize` method, or had a
      way to detect double serialization (e.g. `is_a?(String)`). However, now
      that JSON types can handle string primitives, we need to avoid double
      serialization.
      
      Fixes #24993.
      6007e584
  12. 14 4月, 2016 2 次提交
    • R
      Add `quoted_time` for truncating the date part of a time column value · 28ec8c4a
      Ryuta Kamizono 提交于
      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)
      ```
      28ec8c4a
    • S
      Properly serialize all JSON primitives in the AR JSON type · efaa6e4f
      Sean Griffin 提交于
      Previously we were assuming that the only valid types for encoding were
      arrays and hashes. However, any JSON primitive is an accepted value by
      both PG and MySQL.
      
      This does involve a minor breaking change in the handling of `default`
      in the schema dumper. This is easily worked around, as passing a
      hash/array literal would have worked fine in previous versions of Rails.
      However, because of this, I will not be backporting this to 4.2 or
      earlier.
      
      Fixes #24234
      efaa6e4f
  13. 05 11月, 2015 1 次提交
  14. 25 9月, 2015 1 次提交
    • S
      Clean up the implementation of AR::Dirty · 8e633e50
      Sean Griffin 提交于
      This moves a bit more of the logic required for dirty checking into the
      attribute objects. I had hoped to remove the `with_value_from_database`
      stuff, but unfortunately just calling `dup` on the attribute objects
      isn't enough, since the values might contain deeply nested data
      structures. I think this can be cleaned up further.
      
      This makes most dirty checking become lazy, and reduces the number of
      object allocations and amount of CPU time when assigning a value. This
      opens the door (but doesn't quite finish) to improving the performance
      of writes to a place comparable to 4.1
      8e633e50
  15. 22 9月, 2015 4 次提交
    • S
      Simplify the implementation of Active Model's type registry · 4590d772
      Sean Griffin 提交于
      Things like decorations, overrides, and priorities only matter for
      Active Record, so the Active Model registry can be implemented much more
      simply. At this point, I wonder if having Active Record's registry
      inherit from Active Model's is even worth the trouble?
      
      The Active Model class was also missing test cases, which have been
      backfilled.
      
      This removes the error when two types are registered with the same name,
      but given that Active Model is meant to be significantly more generic, I
      do not think this is an issue for now. If we want, we can raise an error
      at the point that someone tries to register it.
      4590d772
    • S
      Various stylistic nitpicks · 22cc2b86
      Sean Griffin 提交于
      We do not need to require each file from AM individually, the type
      module does that for us. Even if the classes are extremely small right
      now, I'd rather keep any custom classes needed by AR in their own files,
      as they can easily have more complex changes in the future.
      22cc2b86
    • S
      `TypeMap` and `HashLookupTypeMap` shouldn't be in Active Model · e467deb6
      Sean Griffin 提交于
      These are used by the connection adapters to convert SQL type
      information into the appropriate type object, and makes no sense outside
      of the context of Active Record
      e467deb6
    • K
      Move ActiveRecord::Type to ActiveModel · 9cc8c6f3
      Kir Shatrov 提交于
      The first step of bringing typecasting to ActiveModel
      9cc8c6f3
  16. 19 9月, 2015 1 次提交
  17. 02 9月, 2015 1 次提交
  18. 22 8月, 2015 1 次提交
    • S
      JSON is still an adapter specific type. · ffc4710c
      Sean Griffin 提交于
      Several changes were made in #21110 which I am strongly opposed to.
      (this is what I get for going on vacation. :trollface:) No type should
      be introduced into the generic `ActiveRecord::Type` namespace, and
      *certainly* should not be registered into the registry unconstrained
      unless it is supported by *all* adapters (which basically means that it
      was specified in the ANSI SQL standard).
      
      I do not think `# :nodoc:` ing the type is sufficient, as it still makes
      the code of Rails itself very unclear as to what the role of that class
      is. While I would argue that this shouldn't even be a super class, and
      that MySql and PG's JSON types are only superficially duplicated (they
      might look the same but will change for different reasons in the
      future).
      
      However, I don't feel strongly enough about it as a point of contention
      (and the biggest cost of harming the blameability has already occured),
      so I simply moved the superclass into a namespace where its role is
      absolutely clear.
      
      After this change, `attribute :foo, :json` will once again work with
      MySQL and PG, but not with Sqlite3 or any third party adapters.
      
      Unresolved questions
      --------------------
      
      The types that and adapter publishes (at least those are unique to that
      adapter, and not adding additional behavior like `MysqlString` should
      probably be part of the adapter's public API. Should we standardize the
      namespace for these, and document them?
      ffc4710c
  19. 18 8月, 2015 1 次提交
  20. 24 6月, 2015 1 次提交
  21. 18 5月, 2015 1 次提交
  22. 30 3月, 2015 1 次提交
    • S
      Reduce memory usage when loading types in PG · 445c12f7
      Sean Griffin 提交于
      We were never clearing the `PG::Result` object used to query the types
      when the connection is first established. This would lead to a
      potentially large amount of memory being retained for the life of the
      connection.
      
      Investigating this issue also revealed several low hanging fruit on the
      performance of these methods, and the number of allocations has been
      reduced by ~90%.
      
      Fixes #19578
      445c12f7
  23. 23 3月, 2015 2 次提交
  24. 05 3月, 2015 1 次提交
  25. 20 2月, 2015 1 次提交
  26. 18 2月, 2015 4 次提交
  27. 16 2月, 2015 2 次提交
  28. 11 2月, 2015 2 次提交
    • S
      Remove most PG specific type subclasses · aafee233
      Sean Griffin 提交于
      The latest version of the PG gem can actually convert the primitives for
      us in C code, which gives a pretty substantial speed up. A few cases
      were only there to add the `infinity` method, which I just put on the
      range type (which is the only place it was used). Floats also needed to
      parse `Infinity` and `NaN`, but it felt reasonable enough to put that on
      the generic form.
      aafee233
    • S
      Refactor microsecond precision to be database agnostic · f1a0fa9e
      Sean Griffin 提交于
      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.
      f1a0fa9e
  29. 08 2月, 2015 1 次提交