]> git.openstreetmap.org Git - rails.git/blobdiff - db/migrate/020_populate_node_tags_and_remove.rb
Fix most auto-correctable rubocop issues
[rails.git] / db / migrate / 020_populate_node_tags_and_remove.rb
index dc048f1906134eab74d7f3b7bf35c09d3bfb3e77..8315cb14375fe2bb4539019607d80f8c10939fe4 100644 (file)
@@ -1,23 +1,25 @@
+require 'migrate'
+
 class PopulateNodeTagsAndRemove < ActiveRecord::Migration
   def self.up
     have_nodes = select_value("SELECT count(*) FROM current_nodes").to_i != 0
 
     if have_nodes
-      prefix = File.join Dir.tmpdir, "020_populate_node_tags_and_remove.#{$$}."
+      prefix = File.join Dir.tmpdir, "020_populate_node_tags_and_remove.#{$PROCESS_ID}."
 
       cmd = "db/migrate/020_populate_node_tags_and_remove_helper"
       src = "#{cmd}.c"
-      if not File.exists? cmd or File.mtime(cmd) < File.mtime(src) then 
-        system 'cc -O3 -Wall `mysql_config --cflags --libs` ' +
-          "#{src} -o #{cmd}" or fail
+      if !File.exist?(cmd) || File.mtime(cmd) < File.mtime(src)
+        system('cc -O3 -Wall `mysql_config --cflags --libs` ' +
+          "#{src} -o #{cmd}") || fail
       end
 
       conn_opts = ActiveRecord::Base.connection.instance_eval { @connection_options }
-      args = conn_opts.map { |arg| arg.to_s } + [prefix]
+      args = conn_opts.map(&:to_s) + [prefix]
       fail "#{cmd} failed" unless system cmd, *args
 
-      tempfiles = ['nodes', 'node_tags', 'current_nodes', 'current_node_tags'].
-        map { |base| prefix + base }
+      tempfiles = %w(nodes node_tags current_nodes current_node_tags)
+                  .map { |base| prefix + base }
       nodes, node_tags, current_nodes, current_node_tags = tempfiles
     end
 
@@ -25,17 +27,17 @@ class PopulateNodeTagsAndRemove < ActiveRecord::Migration
     remove_column :nodes, :tags
     remove_column :current_nodes, :tags
 
-    add_column :nodes, :version, :bigint, :limit => 20, :null => false
+    add_column :nodes, :version, :bigint, :null => false
 
-    create_table :current_node_tags, innodb_table do |t|
-      t.column :id,          :bigint, :limit => 64, :null => false
+    create_table :current_node_tags, :id => false do |t|
+      t.column :id,          :bigint, :null => false
       t.column :k,          :string, :default => "", :null => false
       t.column :v,          :string, :default => "", :null => false
     end
 
-    create_table :node_tags, innodb_table do |t|
-      t.column :id,          :bigint, :limit => 64, :null => false
-      t.column :version,     :bigint, :limit => 20, :null => false
+    create_table :node_tags, :id => false do |t|
+      t.column :id,          :bigint, :null => false
+      t.column :version,     :bigint, :null => false
       t.column :k,          :string, :default => "", :null => false
       t.column :v,          :string, :default => "", :null => false
     end
@@ -44,7 +46,7 @@ class PopulateNodeTagsAndRemove < ActiveRecord::Migration
     csvopts = "FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\\n'"
 
     if have_nodes
-      execute "LOAD DATA INFILE '#{nodes}' INTO TABLE nodes #{csvopts} (id, latitude, longitude, user_id, visible, timestamp, tile, version)";
+      execute "LOAD DATA INFILE '#{nodes}' INTO TABLE nodes #{csvopts} (id, latitude, longitude, user_id, visible, timestamp, tile, version)"
       execute "LOAD DATA INFILE '#{node_tags}' INTO TABLE node_tags #{csvopts} (id, version, k, v)"
       execute "LOAD DATA INFILE '#{current_node_tags}' INTO TABLE current_node_tags #{csvopts} (id, k, v)"
     end
@@ -53,8 +55,8 @@ class PopulateNodeTagsAndRemove < ActiveRecord::Migration
   end
 
   def self.down
-    raise IrreversibleMigration.new
-#    add_column :nodes, "tags", :text, :default => "", :null => false
-#    add_column :current_nodes, "tags", :text, :default => "", :null => false
+    fail ActiveRecord::IrreversibleMigration
+    #    add_column :nodes, "tags", :text, :default => "", :null => false
+    #    add_column :current_nodes, "tags", :text, :default => "", :null => false
   end
 end