Add `datetime_with_timezone` to table definition
What does this MR do?
Adds datetime_with_timezone
as an ActiveRecord table definition so you can do this:
class Users < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :users do |t|
t.string :username, null: false
t.datetime_with_timezone :did_something_at, null: true
end
end
end
Also fixes schema.rb
generation to output t.datetime_with_timezone
columns where appropriate.
Why was this MR needed?
Rubocop now registers an offense for the following migration:
class Users < ActiveRecord::Migration
DOWNTIME = false
def change
create_table :users do |t|
t.string :username, null: false
t.datetime :did_something_at, null: true
end
end
end
The offense:
C: Migration/Datetime: Do not use the datetime data type, use datetime_with_timezone instead
The cop was added in: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11229
The problem
t.datetime_with_timezone
is not defined.
The schema problem
For a column of type timestamptz
, Rails outputs the column type in schema.rb
as datetime
, instead of our new datetime_with_timezone
.
Screenshots (if relevant)
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary -
Documentation created/updated -
API support added - Tests
-
Added for this feature/bug -
All builds are passing
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Branch has no merge conflicts with master
(if it does - rebase it please) -
Squashed related commits together
Edited by Yorick Peterse