annotate db/migrate/20180625074738_convert_timestamps_to_with_time_zone.rb @ 460:b1ef80121c79

Update to use correct timestamp datatype Use sql dump instead of ruby because zone info would be lost otherwise.
author nanaya <me@nanaya.pro>
date Mon, 25 Jun 2018 16:53:47 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
460
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
1 class ConvertTimestampsToWithTimeZone < ActiveRecord::Migration[5.2]
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
2 COLUMNS = {
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
3 ar_internal_metadata: [:created_at, :updated_at],
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
4 pastes: [:created_at, :updated_at],
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
5 }
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
6
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
7 def up
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
8 COLUMNS.each do |table, columns|
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
9 change_table table do |t|
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
10 columns.each do |column|
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
11 t.change column, :timestamptz
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
12 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
13 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
14 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
15 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
16
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
17 def down
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
18 COLUMNS.each do |table, columns|
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
19 change_table table do |t|
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
20 columns.each do |column|
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
21 t.change column, :timestamp
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
22 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
23 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
24 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
25 end
b1ef80121c79 Update to use correct timestamp datatype
nanaya <me@nanaya.pro>
parents:
diff changeset
26 end