New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time column improvements #32220

Merged
merged 3 commits into from Mar 15, 2018

Conversation

Projects
None yet
1 participant
@pixeltrix
Member

pixeltrix commented Mar 11, 2018

  • Apply precision when assigning values to time columns (Fixes #30301)
  • Fixes issues with time columns not being normalised on sqlite
  • Ensures that times with a date component other than 2000-01-01 get stripped when quoting for databases like MySQL and PostgreSQL

Probably for Rails 6.0 we might want to introduce storing times without the date component via a config option that defaults to true for new apps.

cc @matthewd @kamipo

pixeltrix added some commits Mar 11, 2018

Apply time column precision on assignment
In #20317, datetime columns had their precision applied on assignment but
that behaviour wasn't applied to time columns - this commit fixes that.

Fixes #30301.
Normalize date component when writing to time columns
For legacy reasons Rails stores time columns on sqlite as full
timestamp strings. However because the date component wasn't being
normalized this meant that when they were read back they were being
prefixed with 2001-01-01 by ActiveModel::Type::Time. This had a
twofold result - first it meant that the fast code path wasn't being
used because the string was invalid and second it was corrupting the
second fractional component being read by the Date._parse code path.

Fix this by a combination of normalizing the timestamps on writing
and also changing Active Model to be more lenient when detecting
whether a string starts with a date component before creating the
dummy time value for parsing.
Ensure that leading date is stripped by quoted_time
In #24542, quoted_time was introduced to strip the leading date
component for time columns because it was having a significant
effect in mariadb. However, it assumed that the date component
was always 2000-01-01 which isn't the case, especially if the
source wasn't another time column.

@pixeltrix pixeltrix merged commit 8fc2b51 into master Mar 15, 2018

3 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@pixeltrix pixeltrix deleted the fix-time-columns-on-sqlite3 branch Mar 15, 2018

pixeltrix added a commit that referenced this pull request Mar 15, 2018

pixeltrix added a commit that referenced this pull request Mar 15, 2018

pixeltrix added a commit that referenced this pull request Mar 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment