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)
11 if ENV["USE_DB_FUNCTIONS"]
13 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
14 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
15 user_id, visible, tags, timestamp,
16 tile_for_point(CAST(ROUND(latitude * 10000000) AS INTEGER),
17 CAST(ROUND(longitude * 10000000) AS INTEGER))
22 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
23 SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
24 user_id, visible, tags, timestamp, 0
28 model.all.each(&:save!)
32 def self.downgrade_table(from_table, to_table)
34 INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
35 SELECT id, latitude / 10000000, longitude / 10000000,
36 user_id, visible, tags, timestamp
42 remove_index "current_nodes", :name => "current_nodes_timestamp_idx"
44 rename_table "current_nodes", "current_nodes_v5"
46 create_table "current_nodes", :id => false do |t|
47 t.column "id", :bigserial, :primary_key => true, :null => false
48 t.column "latitude", :integer, :null => false
49 t.column "longitude", :integer, :null => false
50 t.column "user_id", :bigint, :null => false
51 t.column "visible", :boolean, :null => false
52 t.column "tags", :text, :default => "", :null => false
53 t.column "timestamp", :datetime, :null => false
54 t.column "tile", :integer, :null => false
57 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
58 add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
60 change_column "current_nodes", "tile", :bigint
62 upgrade_table "current_nodes_v5", "current_nodes", Node
64 drop_table "current_nodes_v5"
66 remove_index "nodes", :name => "nodes_uid_idx"
67 remove_index "nodes", :name => "nodes_timestamp_idx"
68 rename_table "nodes", "nodes_v5"
70 create_table "nodes", :id => false do |t|
71 t.column "id", :bigint, :null => false
72 t.column "latitude", :integer, :null => false
73 t.column "longitude", :integer, :null => false
74 t.column "user_id", :bigint, :null => false
75 t.column "visible", :boolean, :null => false
76 t.column "tags", :text, :default => "", :null => false
77 t.column "timestamp", :datetime, :null => false
78 t.column "tile", :integer, :null => false
81 add_index "nodes", ["id"], :name => "nodes_uid_idx"
82 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
83 add_index "nodes", ["tile"], :name => "nodes_tile_idx"
85 change_column "nodes", "tile", :bigint
87 upgrade_table "nodes_v5", "nodes", OldNode
93 rename_table "current_nodes", "current_nodes_v6"
95 create_table "current_nodes", :id => false do |t|
96 t.column "id", :bigserial, :primary_key => true, :null => false
97 t.column "latitude", :float, :limit => 53, :null => false
98 t.column "longitude", :float, :limit => 53, :null => false
99 t.column "user_id", :bigint, :null => false
100 t.column "visible", :boolean, :null => false
101 t.column "tags", :text, :default => "", :null => false
102 t.column "timestamp", :datetime, :null => false
105 add_index "current_nodes", %w[latitude longitude], :name => "current_nodes_lat_lon_idx"
106 add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
108 downgrade_table "current_nodes_v6", "current_nodes"
110 drop_table "current_nodes_v6"
112 rename_table "nodes", "nodes_v6"
114 create_table "nodes", :id => false do |t|
115 t.column "id", :bigint, :null => false
116 t.column "latitude", :float, :limit => 53, :null => false
117 t.column "longitude", :float, :limit => 53, :null => false
118 t.column "user_id", :bigint, :null => false
119 t.column "visible", :boolean, :null => false
120 t.column "tags", :text, :default => "", :null => false
121 t.column "timestamp", :datetime, :null => false
124 add_index "nodes", ["id"], :name => "nodes_uid_idx"
125 add_index "nodes", %w[latitude longitude], :name => "nodes_latlon_idx"
126 add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
128 downgrade_table "nodes_v6", "nodes"
130 drop_table "nodes_v6"