1 class TileNodes < ActiveRecord::Migration[4.2]
2 class Node < ApplicationRecord
3 self.table_name = "current_nodes"
6 class OldNode < ApplicationRecord
7 self.table_name = "nodes"
10 def self.upgrade_table(from_table, to_table, model)
12 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
13 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
14 user_id, visible, tags, timestamp, 0
18 model.all.each(&:save!)
21 def self.downgrade_table(from_table, to_table)
23 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
24 SELECT id, latitude / 10000000, longitude / 10000000,
25 user_id, visible, tags, timestamp
31 remove_index "current_nodes", :name => "current_nodes_timestamp_idx"
33 rename_table "current_nodes", "current_nodes_v5"
35 create_table "current_nodes", :id => false do |t|
36 t.column "id", :bigserial, :primary_key => true, :null => false
37 t.column "latitude", :integer, :null => false
38 t.column "longitude", :integer, :null => false
39 t.column "user_id", :bigint, :null => false
40 t.column "visible", :boolean, :null => false
41 t.column "tags", :text, :default => "", :null => false
42 t.column "timestamp", :datetime, :null => false
43 t.column "tile", :integer, :null => false
46 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
47 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
49 change_column "current_nodes", "tile", :bigint
51 upgrade_table "current_nodes_v5", "current_nodes", Node
53 drop_table "current_nodes_v5"
55 remove_index "nodes", :name => "nodes_uid_idx"
56 remove_index "nodes", :name => "nodes_timestamp_idx"
57 rename_table "nodes", "nodes_v5"
59 create_table "nodes", :id => false do |t|
60 t.column "id", :bigint, :null => false
61 t.column "latitude", :integer, :null => false
62 t.column "longitude", :integer, :null => false
63 t.column "user_id", :bigint, :null => false
64 t.column "visible", :boolean, :null => false
65 t.column "tags", :text, :default => "", :null => false
66 t.column "timestamp", :datetime, :null => false
67 t.column "tile", :integer, :null => false
70 add_index "nodes", ["id"], :name => "nodes_uid_idx"
71 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
72 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
74 change_column "nodes", "tile", :bigint
76 upgrade_table "nodes_v5", "nodes", OldNode
82 rename_table "current_nodes", "current_nodes_v6"
84 create_table "current_nodes", :id => false do |t|
85 t.column "id", :bigserial, :primary_key => true, :null => false
86 t.column "latitude", :float, :limit => 53, :null => false
87 t.column "longitude", :float, :limit => 53, :null => false
88 t.column "user_id", :bigint, :null => false
89 t.column "visible", :boolean, :null => false
90 t.column "tags", :text, :default => "", :null => false
91 t.column "timestamp", :datetime, :null => false
94 add_index "current_nodes", %w[latitude longitude], :name => "current_nodes_lat_lon_idx"
95 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
97 downgrade_table "current_nodes_v6", "current_nodes"
99 drop_table "current_nodes_v6"
101 rename_table "nodes", "nodes_v6"
103 create_table "nodes", :id => false do |t|
104 t.column "id", :bigint, :null => false
105 t.column "latitude", :float, :limit => 53, :null => false
106 t.column "longitude", :float, :limit => 53, :null => false
107 t.column "user_id", :bigint, :null => false
108 t.column "visible", :boolean, :null => false
109 t.column "tags", :text, :default => "", :null => false
110 t.column "timestamp", :datetime, :null => false
113 add_index "nodes", ["id"], :name => "nodes_uid_idx"
114 add_index "nodes", %w[latitude longitude], :name => "nodes_latlon_idx"
115 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
117 downgrade_table "nodes_v6", "nodes"
119 drop_table "nodes_v6"