From: Andy Allan Date: Sat, 8 Nov 2008 16:47:02 +0000 (+0000) Subject: Moving AUTO_INCREMENTs to monkeypatching. Seems a bit hacky though X-Git-Tag: live~7573^2~198 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/fc9046ce6fcb3b4c4962285737767ea094b4cb00?hp=40b5b876f850e6a5e31463f90e268bfc2451c7a5 Moving AUTO_INCREMENTs to monkeypatching. Seems a bit hacky though --- diff --git a/db/migrate/001_create_osm_db.rb b/db/migrate/001_create_osm_db.rb index 689ca3c20..fdced3e1b 100644 --- a/db/migrate/001_create_osm_db.rb +++ b/db/migrate/001_create_osm_db.rb @@ -16,7 +16,7 @@ class CreateOsmDb < ActiveRecord::Migration add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx" add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx" - change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" + change_column :current_nodes, :id, :bigint_auto_64 create_table "current_segments", innodb_table do |t| t.column "id", :bigint, :limit => 64, :null => false @@ -32,7 +32,7 @@ class CreateOsmDb < ActiveRecord::Migration add_index "current_segments", ["node_a"], :name => "current_segments_a_idx" add_index "current_segments", ["node_b"], :name => "current_segments_b_idx" - change_column "current_segments", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" + change_column :current_segments, :id, :bigint_auto_64 create_table "current_way_segments", innodb_table do |t| t.column "id", :bigint, :limit => 64 @@ -53,18 +53,14 @@ class CreateOsmDb < ActiveRecord::Migration execute "CREATE FULLTEXT INDEX `current_way_tags_v_idx` ON `current_way_tags` (`v`)" create_table "current_ways", myisam_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "user_id", :bigint, :limit => 20 t.column "timestamp", :datetime t.column "visible", :boolean end - add_primary_key "current_ways", ["id"] - - change_column "current_ways", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" - create_table "diary_entries", myisam_table do |t| - t.column "id", :bigint, :limit => 20, :null => false + t.column "id", :bigint_pk, :null => false t.column "user_id", :bigint, :limit => 20, :null => false t.column "title", :string t.column "body", :text @@ -72,21 +68,14 @@ class CreateOsmDb < ActiveRecord::Migration t.column "updated_at", :datetime end - add_primary_key "diary_entries", ["id"] - - change_column "diary_entries", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT" - create_table "friends", myisam_table do |t| - t.column "id", :bigint, :limit => 20, :null => false + t.column "id", :bigint_pk, :null => false t.column "user_id", :bigint, :limit => 20, :null => false t.column "friend_user_id", :bigint, :limit => 20, :null => false end - add_primary_key "friends", ["id"] add_index "friends", ["friend_user_id"], :name => "user_id_idx" - change_column "friends", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT" - create_table "gps_points", myisam_table do |t| t.column "altitude", :float t.column "user_id", :integer, :limit => 20 @@ -104,16 +93,13 @@ class CreateOsmDb < ActiveRecord::Migration create_table "gpx_file_tags", myisam_table do |t| t.column "gpx_id", :bigint, :limit => 64, :default => 0, :null => false t.column "tag", :string - t.column "id", :integer, :limit => 20, :null => false + t.column "id", :bigint_pk, :null => false end - add_primary_key "gpx_file_tags", ["id"] add_index "gpx_file_tags", ["gpx_id"], :name => "gpx_file_tags_gpxid_idx" - change_column "gpx_file_tags", "id", :integer, :null => false, :options => "AUTO_INCREMENT" - create_table "gpx_files", myisam_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "user_id", :bigint, :limit => 20 t.column "visible", :boolean, :default => true, :null => false t.column "name", :string, :default => "", :null => false @@ -126,12 +112,9 @@ class CreateOsmDb < ActiveRecord::Migration t.column "inserted", :boolean end - add_primary_key "gpx_files", ["id"] add_index "gpx_files", ["timestamp"], :name => "gpx_files_timestamp_idx" add_index "gpx_files", ["visible", "public"], :name => "gpx_files_visible_public_idx" - change_column "gpx_files", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" - create_table "gpx_pending_files", myisam_table do |t| t.column "originalname", :string t.column "tmpname", :string @@ -139,7 +122,7 @@ class CreateOsmDb < ActiveRecord::Migration end create_table "messages", myisam_table do |t| - t.column "id", :bigint, :limit => 20, :null => false + t.column "id", :bigint_pk, :null => false t.column "user_id", :bigint, :limit => 20, :null => false t.column "from_user_id", :bigint, :limit => 20, :null => false t.column "from_display_name", :string, :default => "" @@ -150,21 +133,14 @@ class CreateOsmDb < ActiveRecord::Migration t.column "to_user_id", :bigint, :limit => 20, :null => false end - add_primary_key "messages", ["id"] add_index "messages", ["from_display_name"], :name => "from_name_idx" - change_column "messages", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT" - create_table "meta_areas", myisam_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "user_id", :bigint, :limit => 20 t.column "timestamp", :datetime end - add_primary_key "meta_areas", ["id"] - - change_column "meta_areas", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" - create_table "nodes", myisam_table do |t| t.column "id", :bigint, :limit => 64 t.column "latitude", :double @@ -194,7 +170,7 @@ class CreateOsmDb < ActiveRecord::Migration create_table "users", innodb_table do |t| t.column "email", :string - t.column "id", :bigint, :limit => 20, :null => false + t.column "id", :bigint_pk, :null => false t.column "token", :string t.column "active", :integer, :default => 0, :null => false t.column "pass_crypt", :string @@ -211,12 +187,9 @@ class CreateOsmDb < ActiveRecord::Migration t.column "home_zoom", :integer, :limit => 2, :default => 3 end - add_primary_key "users", ["id"] add_index "users", ["email"], :name => "users_email_idx" add_index "users", ["display_name"], :name => "users_display_name_idx" - change_column "users", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT" - create_table "way_segments", myisam_table do |t| t.column "id", :bigint, :limit => 64, :default => 0, :null => false t.column "segment_id", :integer diff --git a/db/migrate/002_cleanup_osm_db.rb b/db/migrate/002_cleanup_osm_db.rb index b99055e52..1358febd8 100644 --- a/db/migrate/002_cleanup_osm_db.rb +++ b/db/migrate/002_cleanup_osm_db.rb @@ -150,15 +150,11 @@ class CleanupOsmDb < ActiveRecord::Migration change_column "nodes", "id", :bigint, :limit => 64 create_table "meta_areas", myisam_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "user_id", :bigint, :limit => 20 t.column "timestamp", :datetime end - add_primary_key "meta_areas", ["id"] - - change_column "meta_areas", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" - remove_index "messages", :name => "messages_to_user_id_idx" change_column "messages", "message_read", :boolean, :default => false change_column "messages", "sent_on", :datetime @@ -223,6 +219,6 @@ class CleanupOsmDb < ActiveRecord::Migration change_column "current_nodes", "user_id", :bigint, :limit => 20 change_column "current_nodes", "longitude", :double change_column "current_nodes", "latitude", :double - change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" + change_column "current_nodes", "id", :bigint_auto_64 end end diff --git a/db/migrate/004_user_enhancements.rb b/db/migrate/004_user_enhancements.rb index 92f01bf5d..a6e81d222 100644 --- a/db/migrate/004_user_enhancements.rb +++ b/db/migrate/004_user_enhancements.rb @@ -13,18 +13,15 @@ class UserEnhancements < ActiveRecord::Migration add_primary_key "user_preferences", ["user_id", "k"] create_table "user_tokens", innodb_table do |t| - t.column "id", :bigint, :limit => 20, :null => false + t.column "id", :bigint_pk, :null => false t.column "user_id", :bigint, :limit => 20, :null => false t.column "token", :string, :null => false t.column "expiry", :datetime, :null => false end - add_primary_key "user_tokens", ["id"] add_index "user_tokens", ["token"], :name => "user_tokens_token_idx", :unique => true add_index "user_tokens", ["user_id"], :name => "user_tokens_user_id_idx" - change_column "user_tokens", "id", :bigint, :limit => 20, :null => false, :options => "AUTO_INCREMENT" - User.find(:all, :conditions => "token is not null").each do |user| UserToken.create(:user_id => user.id, :token => user.token, :expiry => 1.week.from_now) end diff --git a/db/migrate/006_tile_nodes.rb b/db/migrate/006_tile_nodes.rb index 3a50cc9b0..f3a1edbb2 100644 --- a/db/migrate/006_tile_nodes.rb +++ b/db/migrate/006_tile_nodes.rb @@ -36,7 +36,7 @@ class TileNodes < ActiveRecord::Migration rename_table "current_nodes", "current_nodes_v5" create_table "current_nodes", innodb_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "latitude", :integer, :null => false t.column "longitude", :integer, :null => false t.column "user_id", :bigint, :limit => 20, :null => false @@ -46,11 +46,9 @@ class TileNodes < ActiveRecord::Migration t.column "tile", :integer, :null => false end - add_primary_key "current_nodes", ["id"] add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx" add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx" - change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" change_column "current_nodes", "tile", :integer, :null => false, :unsigned => true upgrade_table "current_nodes_v5", "current_nodes", Node @@ -85,7 +83,7 @@ class TileNodes < ActiveRecord::Migration rename_table "current_nodes", "current_nodes_v6" create_table "current_nodes", innodb_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "latitude", :double, :null => false t.column "longitude", :double, :null => false t.column "user_id", :bigint, :limit => 20, :null => false @@ -94,12 +92,9 @@ class TileNodes < ActiveRecord::Migration t.column "timestamp", :datetime, :null => false end - add_primary_key "current_nodes", ["id"] add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx" add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx" - change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" - downgrade_table "current_nodes_v6", "current_nodes" drop_table "current_nodes_v6" diff --git a/db/migrate/007_add_relations.rb b/db/migrate/007_add_relations.rb index a30642e32..5dcdeb28d 100644 --- a/db/migrate/007_add_relations.rb +++ b/db/migrate/007_add_relations.rb @@ -27,15 +27,12 @@ class AddRelations < ActiveRecord::Migration execute "CREATE FULLTEXT INDEX `current_relation_tags_v_idx` ON `current_relation_tags` (`v`)" create_table "current_relations", innodb_table do |t| - t.column "id", :bigint, :limit => 64, :null => false + t.column "id", :bigint_pk_64, :null => false t.column "user_id", :bigint, :limit => 20, :null => false t.column "timestamp", :datetime, :null => false t.column "visible", :boolean, :null => false end - add_primary_key "current_relations", ["id"] - change_column "current_relations", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT" - create_table "relation_members", myisam_table do |t| t.column "id", :bigint, :limit => 64, :default => 0, :null => false t.column "member_type", :string, :limit => 11, :null => false diff --git a/lib/migrate.rb b/lib/migrate.rb index 68ff04615..782436af3 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -45,6 +45,8 @@ module ActiveRecord types[:bigint] = { :name => "bigint", :limit => 20 } types[:double] = { :name => "double" } types[:bigint_pk] = { :name => "bigint(20) DEFAULT NULL auto_increment PRIMARY KEY" } + types[:bigint_pk_64] = { :name => "bigint(64) DEFAULT NULL auto_increment PRIMARY KEY" } + types[:bigint_auto_64] = { :name => "bigint(64) DEFAULT NULL auto_increment" } types end