Cleanup migrations

Cleanup our migrations, replacing as much of our custom code
and monkey patching with modern standard rails methods.
This commit is contained in:
Tom Hughes 2015-01-10 11:45:39 +00:00
parent e65e41a694
commit ac7bb003ec
36 changed files with 422 additions and 585 deletions

View file

@ -2,13 +2,13 @@ require 'migrate'
class CreateOsmDb < ActiveRecord::Migration
def self.up
create_table "current_nodes", innodb_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
t.column "latitude", :double
t.column "longitude", :double
t.column "user_id", :bigint, :limit => 20
create_table "current_nodes", :id => false do |t|
t.column "id", :bigint, :null => false
t.column "latitude", :float, :limit => 53
t.column "longitude", :float, :limit => 53
t.column "user_id", :bigint
t.column "visible", :boolean
t.column "tags", :text, :default => "", :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime
end
@ -16,15 +16,13 @@ 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_auto_64
create_table "current_segments", innodb_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
t.column "node_a", :bigint, :limit => 64
t.column "node_b", :bigint, :limit => 64
t.column "user_id", :bigint, :limit => 20
create_table "current_segments", :id => false do |t|
t.column "id", :bigint, :null => false
t.column "node_a", :bigint
t.column "node_b", :bigint
t.column "user_id", :bigint
t.column "visible", :boolean
t.column "tags", :text, :default => "", :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime
end
@ -32,51 +30,49 @@ 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_auto_64
create_table "current_way_segments", innodb_table do |t|
t.column "id", :bigint, :limit => 64
t.column "segment_id", :bigint, :limit => 11
t.column "sequence_id", :bigint, :limit => 11
create_table "current_way_segments", :id => false do |t|
t.column "id", :bigint
t.column "segment_id", :bigint
t.column "sequence_id", :bigint
end
add_index "current_way_segments", ["segment_id"], :name => "current_way_segments_seg_idx"
add_index "current_way_segments", ["id"], :name => "current_way_segments_id_idx"
create_table "current_way_tags", myisam_table do |t|
t.column "id", :bigint, :limit => 64
t.column "k", :string, :default => "", :null => false
t.column "v", :string, :default => "", :null => false
create_table "current_way_tags", :id => false do |t|
t.column "id", :bigint
t.column "k", :string, :default => "", :null => false
t.column "v", :string, :default => "", :null => false
end
add_index "current_way_tags", ["id"], :name => "current_way_tags_id_idx"
add_fulltext_index "current_way_tags", "v"
add_index "current_way_tags", "v", :name => "current_way_tags_v_idx"
create_table "current_ways", myisam_table do |t|
t.column "id", :bigint_pk_64, :null => false
t.column "user_id", :bigint, :limit => 20
create_table "current_ways", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint
t.column "timestamp", :datetime
t.column "visible", :boolean
end
create_table "diary_entries", myisam_table do |t|
t.column "id", :bigint_pk, :null => false
t.column "user_id", :bigint, :limit => 20, :null => false
create_table "diary_entries", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint, :null => false
t.column "title", :string
t.column "body", :text
t.column "created_at", :datetime
t.column "updated_at", :datetime
end
create_table "friends", myisam_table do |t|
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
create_table "friends", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint, :null => false
t.column "friend_user_id", :bigint, :null => false
end
add_index "friends", ["friend_user_id"], :name => "user_id_idx"
create_table "gps_points", myisam_table do |t|
create_table "gps_points", :id => false do |t|
t.column "altitude", :float
t.column "user_id", :integer
t.column "trackid", :integer
@ -90,77 +86,77 @@ class CreateOsmDb < ActiveRecord::Migration
add_index "gps_points", ["user_id"], :name => "points_uid_idx"
add_index "gps_points", ["gpx_id"], :name => "points_gpxid_idx"
create_table "gpx_file_tags", myisam_table do |t|
t.column "gpx_id", :bigint, :limit => 64, :default => 0, :null => false
create_table "gpx_file_tags", :id => false do |t|
t.column "gpx_id", :bigint, :default => 0, :null => false
t.column "tag", :string
t.column "id", :bigint_pk, :null => false
t.column "id", :bigserial, :primary_key => true, :null => false
end
add_index "gpx_file_tags", ["gpx_id"], :name => "gpx_file_tags_gpxid_idx"
create_table "gpx_files", myisam_table do |t|
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
t.column "size", :bigint, :limit => 20
t.column "latitude", :double
t.column "longitude", :double
create_table "gpx_files", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint
t.column "visible", :boolean, :default => true, :null => false
t.column "name", :string, :default => "", :null => false
t.column "size", :bigint
t.column "latitude", :float, :limit => 53
t.column "longitude", :float, :limit => 53
t.column "timestamp", :datetime
t.column "public", :boolean, :default => true, :null => false
t.column "description", :string, :default => ""
t.column "public", :boolean, :default => true, :null => false
t.column "description", :string, :default => ""
t.column "inserted", :boolean
end
add_index "gpx_files", ["timestamp"], :name => "gpx_files_timestamp_idx"
add_index "gpx_files", ["visible", "public"], :name => "gpx_files_visible_public_idx"
create_table "gpx_pending_files", myisam_table do |t|
create_table "gpx_pending_files", :id => false do |t|
t.column "originalname", :string
t.column "tmpname", :string
t.column "user_id", :bigint, :limit => 20
t.column "user_id", :bigint
end
create_table "messages", myisam_table do |t|
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 => ""
create_table "messages", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint, :null => false
t.column "from_user_id", :bigint, :null => false
t.column "from_display_name", :string, :default => ""
t.column "title", :string
t.column "body", :text
t.column "sent_on", :datetime
t.column "message_read", :boolean, :default => false
t.column "to_user_id", :bigint, :limit => 20, :null => false
t.column "message_read", :boolean, :default => false
t.column "to_user_id", :bigint, :null => false
end
add_index "messages", ["from_display_name"], :name => "from_name_idx"
create_table "meta_areas", myisam_table do |t|
t.column "id", :bigint_pk_64, :null => false
t.column "user_id", :bigint, :limit => 20
create_table "meta_areas", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint
t.column "timestamp", :datetime
end
create_table "nodes", myisam_table do |t|
t.column "id", :bigint, :limit => 64
t.column "latitude", :double
t.column "longitude", :double
t.column "user_id", :bigint, :limit => 20
create_table "nodes", :id => false do |t|
t.column "id", :bigint
t.column "latitude", :float, :limit => 53
t.column "longitude", :float, :limit => 53
t.column "user_id", :bigint
t.column "visible", :boolean
t.column "tags", :text, :default => "", :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime
end
add_index "nodes", ["id"], :name => "nodes_uid_idx"
add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
create_table "segments", myisam_table do |t|
t.column "id", :bigint, :limit => 64
t.column "node_a", :bigint, :limit => 64
t.column "node_b", :bigint, :limit => 64
t.column "user_id", :bigint, :limit => 20
create_table "segments", :id => false do |t|
t.column "id", :bigint
t.column "node_a", :bigint
t.column "node_b", :bigint
t.column "user_id", :bigint
t.column "visible", :boolean
t.column "tags", :text, :default => "", :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime
end
@ -168,60 +164,56 @@ class CreateOsmDb < ActiveRecord::Migration
add_index "segments", ["node_b"], :name => "street_segments_nodeb_idx"
add_index "segments", ["id"], :name => "street_segment_uid_idx"
create_table "users", innodb_table do |t|
create_table "users", :id => false do |t|
t.column "email", :string
t.column "id", :bigint_pk, :null => false
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "token", :string
t.column "active", :integer, :default => 0, :null => false
t.column "active", :integer, :default => 0, :null => false
t.column "pass_crypt", :string
t.column "creation_time", :datetime
t.column "timeout", :datetime
t.column "display_name", :string, :default => ""
t.column "display_name", :string, :default => ""
t.column "preferences", :text
t.column "data_public", :boolean, :default => false
t.column "description", :text, :default => "", :null => false
t.column "home_lat", :double, :default => 1
t.column "home_lon", :double, :default => 1
t.column "within_lon", :double
t.column "within_lat", :double
t.column "home_zoom", :integer, :limit => 2, :default => 3
t.column "data_public", :boolean, :default => false
t.column "description", :text, :default => "", :null => false
t.column "home_lat", :float, :limit => 53, :default => 1
t.column "home_lon", :float, :limit => 53, :default => 1
t.column "within_lon", :float, :limit => 53
t.column "within_lat", :float, :limit => 53
t.column "home_zoom", :integer, :limit => 2, :default => 3
end
add_index "users", ["email"], :name => "users_email_idx"
add_index "users", ["display_name"], :name => "users_display_name_idx"
create_table "way_segments", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :default => 0, :null => false
create_table "way_segments", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "segment_id", :integer
t.column "version", :bigint, :limit => 20, :default => 0, :null => false
t.column "sequence_id", :bigint, :limit => 11, :null => false
t.column "version", :bigint, :default => 0, :null => false
t.column "sequence_id", :bigint, :null => false
end
add_primary_key "way_segments", ["id", "version", "sequence_id"]
change_column "way_segments", "sequence_id", :bigint_auto_11
create_table "way_tags", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :default => 0, :null => false
create_table "way_tags", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "k", :string
t.column "v", :string
t.column "version", :bigint, :limit => 20
t.column "version", :bigint
end
add_index "way_tags", ["id", "version"], :name => "way_tags_id_version_idx"
create_table "ways", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :default => 0, :null => false
t.column "user_id", :bigint, :limit => 20
create_table "ways", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "user_id", :bigint
t.column "timestamp", :datetime
t.column "version", :bigint, :limit => 20, :null => false
t.column "visible", :boolean, :default => true
t.column "version", :bigint, :null => false
t.column "visible", :boolean, :default => true
end
add_primary_key "ways", ["id", "version"]
add_index "ways", ["id"], :name => "ways_id_version_idx"
change_column "ways", "version", :bigint_auto_20
end
def self.down

View file

@ -2,34 +2,33 @@ require 'migrate'
class CleanupOsmDb < ActiveRecord::Migration
def self.up
change_column "current_nodes", "latitude", :double, :null => false
change_column "current_nodes", "longitude", :double, :null => false
change_column "current_nodes", "user_id", :bigint, :limit => 20, :null => false
change_column "current_nodes", "latitude", :float, :limit => 53, :null => false
change_column "current_nodes", "longitude", :float, :limit => 53, :null => false
change_column "current_nodes", "user_id", :bigint, :null => false
change_column "current_nodes", "visible", :boolean, :null => false
change_column "current_nodes", "timestamp", :datetime, :null => false
add_primary_key "current_nodes", ["id"]
remove_index "current_nodes", :name => "current_nodes_id_idx"
change_column "current_segments", "node_a", :bigint, :limit => 64, :null => false
change_column "current_segments", "node_b", :bigint, :limit => 64, :null => false
change_column "current_segments", "user_id", :bigint, :limit => 20, :null => false
change_column "current_segments", "node_a", :bigint, :null => false
change_column "current_segments", "node_b", :bigint, :null => false
change_column "current_segments", "user_id", :bigint, :null => false
change_column "current_segments", "visible", :boolean, :null => false
change_column "current_segments", "timestamp", :datetime, :null => false
add_primary_key "current_segments", ["id"]
remove_index "current_segments", :name => "current_segments_id_visible_idx"
change_column "current_way_segments", "id", :bigint, :limit => 64, :null => false
change_column "current_way_segments", "segment_id", :bigint, :limit => 64, :null => false
change_column "current_way_segments", "sequence_id", :bigint, :limit => 11, :null => false
change_column "current_way_segments", "id", :bigint, :null => false
change_column "current_way_segments", "segment_id", :bigint, :null => false
change_column "current_way_segments", "sequence_id", :bigint, :null => false
add_primary_key "current_way_segments", ["id", "sequence_id"]
remove_index "current_way_segments", :name => "current_way_segments_id_idx"
change_column "current_way_tags", "id", :bigint, :limit => 64, :null => false
change_column "current_way_tags", "id", :bigint, :null => false
change_column "current_ways", "user_id", :bigint, :limit => 20, :null => false
change_column "current_ways", "user_id", :bigint, :null => false
change_column "current_ways", "timestamp", :datetime, :null => false
change_column "current_ways", "visible", :boolean, :null => false
change_engine "current_ways", "InnoDB"
change_column "diary_entries", "title", :string, :null => false
change_column "diary_entries", "body", :text, :null => false
@ -45,11 +44,11 @@ class CleanupOsmDb < ActiveRecord::Migration
change_column "gps_points", "trackid", :integer, :null => false
change_column "gps_points", "latitude", :integer, :null => false
change_column "gps_points", "longitude", :integer, :null => false
change_column "gps_points", "gpx_id", :bigint, :limit => 64, :null => false
change_column "gps_points", "gpx_id", :bigint, :null => false
change_column "gpx_file_tags", "tag", :string, :null => false
change_column "gpx_files", "user_id", :bigint, :limit => 20, :null => false
change_column "gpx_files", "user_id", :bigint, :null => false
change_column "gpx_files", "timestamp", :datetime, :null => false
change_column "gpx_files", "description", :string, :default => "", :null => false
change_column "gpx_files", "inserted", :boolean, :null => false
@ -67,18 +66,18 @@ class CleanupOsmDb < ActiveRecord::Migration
drop_table "meta_areas"
change_column "nodes", "id", :bigint, :limit => 64, :null => false
change_column "nodes", "latitude", :double, :null => false
change_column "nodes", "longitude", :double, :null => false
change_column "nodes", "user_id", :bigint, :limit => 20, :null => false
change_column "nodes", "id", :bigint, :null => false
change_column "nodes", "latitude", :float, :limit => 53, :null => false
change_column "nodes", "longitude", :float, :limit => 53, :null => false
change_column "nodes", "user_id", :bigint, :null => false
change_column "nodes", "visible", :boolean, :null => false
change_column "nodes", "timestamp", :datetime, :null => false
add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
change_column "segments", "id", :bigint, :limit => 64, :null => false
change_column "segments", "node_a", :bigint, :limit => 64, :null => false
change_column "segments", "node_b", :bigint, :limit => 64, :null => false
change_column "segments", "user_id", :bigint, :limit => 20, :null => false
change_column "segments", "id", :bigint, :null => false
change_column "segments", "node_a", :bigint, :null => false
change_column "segments", "node_b", :bigint, :null => false
change_column "segments", "user_id", :bigint, :null => false
change_column "segments", "visible", :boolean, :null => false
change_column "segments", "timestamp", :datetime, :null => false
add_index "segments", ["timestamp"], :name => "segments_timestamp_idx"
@ -89,20 +88,20 @@ class CleanupOsmDb < ActiveRecord::Migration
change_column "users", "creation_time", :datetime, :null => false
change_column "users", "display_name", :string, :default => "", :null => false
change_column "users", "data_public", :boolean, :default => false, :null => false
change_column "users", "home_lat", :double, :default => nil
change_column "users", "home_lon", :double, :default => nil
change_column "users", "home_lat", :float, :limit => 53, :default => nil
change_column "users", "home_lon", :float, :limit => 53, :default => nil
remove_index "users", :name => "users_email_idx"
add_index "users", ["email"], :name => "users_email_idx", :unique => true
remove_index "users", :name => "users_display_name_idx"
add_index "users", ["display_name"], :name => "users_display_name_idx", :unique => true
change_column "way_segments", "segment_id", :bigint, :limit => 64, :null => false
change_column "way_segments", "segment_id", :bigint, :null => false
change_column "way_tags", "k", :string, :null => false
change_column "way_tags", "v", :string, :null => false
change_column "way_tags", "version", :bigint, :limit => 20, :null => false
change_column "way_tags", "version", :bigint, :null => false
change_column "ways", "user_id", :bigint, :limit => 20, :null => false
change_column "ways", "user_id", :bigint, :null => false
change_column "ways", "timestamp", :datetime, :null => false
change_column "ways", "visible", :boolean, :default => true, :null => false
remove_index "ways", :name => "ways_id_version_idx"
@ -114,9 +113,9 @@ class CleanupOsmDb < ActiveRecord::Migration
add_index "ways", ["id"], :name => "ways_id_version_idx"
change_column "ways", "visible", :boolean, :default => true
change_column "ways", "timestamp", :datetime
change_column "ways", "user_id", :bigint, :limit => 20
change_column "ways", "user_id", :bigint
change_column "way_tags", "version", :bigint, :limit => 20
change_column "way_tags", "version", :bigint
change_column "way_tags", "v", :string, :default => nil
change_column "way_tags", "k", :string, :default => nil
@ -126,8 +125,8 @@ class CleanupOsmDb < ActiveRecord::Migration
add_index "users", ["display_name"], :name => "users_display_name_idx"
remove_index "users", :name => "users_email_idx"
add_index "users", ["email"], :name => "users_email_idx"
change_column "users", "home_lon", :double, :default => 1
change_column "users", "home_lat", :double, :default => 1
change_column "users", "home_lon", :float, :limit => 53, :default => 1
change_column "users", "home_lat", :float, :limit => 53, :default => 1
change_column "users", "data_public", :boolean, :default => false
change_column "users", "display_name", :string, :default => ""
change_column "users", "creation_time", :datetime
@ -138,22 +137,22 @@ class CleanupOsmDb < ActiveRecord::Migration
remove_index "segments", :name => "segments_timestamp_idx"
change_column "segments", "timestamp", :datetime
change_column "segments", "visible", :boolean
change_column "segments", "user_id", :bigint, :limit => 20
change_column "segments", "node_b", :bigint, :limit => 64
change_column "segments", "node_a", :bigint, :limit => 64
change_column "segments", "id", :bigint, :limit => 64
change_column "segments", "user_id", :bigint
change_column "segments", "node_b", :bigint
change_column "segments", "node_a", :bigint
change_column "segments", "id", :bigint
remove_index "nodes", :name => "nodes_timestamp_idx"
change_column "nodes", "timestamp", :datetime
change_column "nodes", "visible", :boolean
change_column "nodes", "user_id", :bigint, :limit => 20
change_column "nodes", "longitude", :double
change_column "nodes", "latitude", :double
change_column "nodes", "id", :bigint, :limit => 64
change_column "nodes", "user_id", :bigint
change_column "nodes", "longitude", :float, :limit => 53
change_column "nodes", "latitude", :float, :limit => 53
change_column "nodes", "id", :bigint
create_table "meta_areas", myisam_table do |t|
t.column "id", :bigint_pk_64, :null => false
t.column "user_id", :bigint, :limit => 20
create_table "meta_areas", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint
t.column "timestamp", :datetime
end
@ -163,27 +162,27 @@ class CleanupOsmDb < ActiveRecord::Migration
change_column "messages", "body", :text
change_column "messages", "title", :string, :default => nil
add_column "messages", "from_display_name", :string, :default => ""
add_column "messages", "user_id", :bigint, :limit => 20, :null => false
add_column "messages", "user_id", :bigint, :null => false
add_index "messages", ["from_display_name"], :name => "from_name_idx"
create_table "gpx_pending_files", myisam_table do |t|
create_table "gpx_pending_files", :id => false do |t|
t.column "originalname", :string
t.column "tmpname", :string
t.column "user_id", :bigint, :limit => 20
t.column "tmpname", :string
t.column "user_id", :bigint
end
change_column "gpx_files", "inserted", :boolean
change_column "gpx_files", "description", :string, :default => ""
change_column "gpx_files", "timestamp", :datetime
change_column "gpx_files", "user_id", :bigint, :limit => 20
change_column "gpx_files", "user_id", :bigint
change_column "gpx_file_tags", "tag", :string, :default => nil
change_column "gps_points", "gpx_id", :integer, :limit => 20
change_column "gps_points", "gpx_id", :integer
change_column "gps_points", "longitude", :integer
change_column "gps_points", "latitude", :integer
change_column "gps_points", "trackid", :integer
add_column "gps_points", "user_id", :integer, :limit => 20
add_column "gps_points", "user_id", :integer
add_index "gps_points", ["user_id"], :name => "points_uid_idx"
remove_index "friends", :name => "friends_user_id_idx"
@ -193,34 +192,32 @@ class CleanupOsmDb < ActiveRecord::Migration
change_column "diary_entries", "body", :text
change_column "diary_entries", "title", :string, :default => nil
change_engine "current_ways", "MyISAM"
change_column "current_ways", "visible", :boolean
change_column "current_ways", "timestamp", :datetime
change_column "current_ways", "user_id", :bigint, :limit => 20
change_column "current_ways", "user_id", :bigint
change_column "current_way_tags", "id", :bigint, :limit => 64
change_column "current_way_tags", "id", :bigint
add_index "current_way_segments", ["id"], :name => "current_way_segments_id_idx"
remove_primary_key "current_way_segments"
change_column "current_way_segments", "sequence_id", :bigint, :limit => 11
change_column "current_way_segments", "segment_id", :bigint, :limit => 11
change_column "current_way_segments", "id", :bigint, :limit => 64
change_column "current_way_segments", "sequence_id", :bigint
change_column "current_way_segments", "segment_id", :bigint
change_column "current_way_segments", "id", :bigint
add_index "current_segments", ["id", "visible"], :name => "current_segments_id_visible_idx"
remove_primary_key "current_segments"
change_column "current_segments", "timestamp", :datetime
change_column "current_segments", "visible", :boolean
change_column "current_segments", "user_id", :bigint, :limit => 20
change_column "current_segments", "node_b", :bigint, :limit => 64
change_column "current_segments", "node_a", :bigint, :limit => 64
change_column "current_segments", "user_id", :bigint
change_column "current_segments", "node_b", :bigint
change_column "current_segments", "node_a", :bigint
add_index "current_nodes", ["id"], :name => "current_nodes_id_idx"
remove_primary_key "current_nodes"
change_column "current_nodes", "timestamp", :datetime
change_column "current_nodes", "visible", :boolean
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_auto_64
change_column "current_nodes", "user_id", :bigint
change_column "current_nodes", "longitude", :float, :limit => 53
change_column "current_nodes", "latitude", :float, :limit => 53
end
end

View file

@ -2,7 +2,7 @@ require 'migrate'
class SqlSessionStoreSetup < ActiveRecord::Migration
def self.up
create_table "sessions", :options => innodb_option do |t|
create_table "sessions" do |t|
t.column "session_id", :string
t.column "data", :text
t.column "created_at", :timestamp

View file

@ -2,23 +2,23 @@ require 'migrate'
class UserEnhancements < ActiveRecord::Migration
def self.up
add_column "diary_entries", "latitude", :double
add_column "diary_entries", "longitude", :double
add_column "diary_entries", "latitude", :float, :limit => 53
add_column "diary_entries", "longitude", :float, :limit => 53
add_column "diary_entries", "language", :string, :limit => 3
create_table "user_preferences", innodb_table do |t|
t.column "user_id", :bigint, :limit => 20, :null => false
t.column "k", :string, :null => false
t.column "v", :string, :null => false
create_table "user_preferences", :id => false do |t|
t.column "user_id", :bigint, :null => false
t.column "k", :string, :null => false
t.column "v", :string, :null => false
end
add_primary_key "user_preferences", ["user_id", "k"]
create_table "user_tokens", innodb_table do |t|
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
create_table "user_tokens", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint, :null => false
t.column "token", :string, :null => false
t.column "expiry", :datetime, :null => false
end
add_index "user_tokens", ["token"], :name => "user_tokens_token_idx", :unique => true
@ -41,8 +41,8 @@ class UserEnhancements < ActiveRecord::Migration
def self.down
remove_column "users", "pass_salt"
remove_column "users", "nearby"
add_column "users", "within_lat", :double
add_column "users", "within_lon", :double
add_column "users", "within_lat", :float, :limit => 53
add_column "users", "within_lon", :float, :limit => 53
add_column "users", "timeout", :datetime
add_column "users", "token", :string

View file

@ -2,7 +2,7 @@ require 'migrate'
class TileTracepoints < ActiveRecord::Migration
def self.up
add_column "gps_points", "tile", :four_byte_unsigned
add_column "gps_points", "tile", :bigint
add_index "gps_points", ["tile"], :name => "points_tile_idx"
remove_index "gps_points", :name => "points_idx"

View file

@ -39,21 +39,21 @@ class TileNodes < ActiveRecord::Migration
rename_table "current_nodes", "current_nodes_v5"
create_table "current_nodes", innodb_table do |t|
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
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
t.column "tile", :integer, :null => false
create_table "current_nodes", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "latitude", :integer, :null => false
t.column "longitude", :integer, :null => false
t.column "user_id", :bigint, :null => false
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
t.column "tile", :integer, :null => false
end
add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
change_column "current_nodes", "tile", :four_byte_unsigned
change_column "current_nodes", "tile", :bigint
upgrade_table "current_nodes_v5", "current_nodes", Node
@ -63,22 +63,22 @@ class TileNodes < ActiveRecord::Migration
remove_index "nodes", :name=> "nodes_timestamp_idx"
rename_table "nodes", "nodes_v5"
create_table "nodes", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
t.column "latitude", :integer, :null => false
t.column "longitude", :integer, :null => false
t.column "user_id", :bigint, :limit => 20, :null => false
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
t.column "tile", :integer, :null => false
create_table "nodes", :id => false do |t|
t.column "id", :bigint, :null => false
t.column "latitude", :integer, :null => false
t.column "longitude", :integer, :null => false
t.column "user_id", :bigint, :null => false
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
t.column "tile", :integer, :null => false
end
add_index "nodes", ["id"], :name => "nodes_uid_idx"
add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
add_index "nodes", ["tile"], :name => "nodes_tile_idx"
change_column "nodes", "tile", :four_byte_unsigned
change_column "nodes", "tile", :bigint
upgrade_table "nodes_v5", "nodes", OldNode
@ -88,14 +88,14 @@ class TileNodes < ActiveRecord::Migration
def self.down
rename_table "current_nodes", "current_nodes_v6"
create_table "current_nodes", innodb_table do |t|
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
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
create_table "current_nodes", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "latitude", :float, :limit => 53, :null => false
t.column "longitude", :float, :limit => 53, :null => false
t.column "user_id", :bigint, :null => false
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
end
add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
@ -107,14 +107,14 @@ class TileNodes < ActiveRecord::Migration
rename_table "nodes", "nodes_v6"
create_table "nodes", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
t.column "latitude", :double, :null => false
t.column "longitude", :double, :null => false
t.column "user_id", :bigint, :limit => 20, :null => false
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
create_table "nodes", :id => false do |t|
t.column "id", :bigint, :null => false
t.column "latitude", :float, :limit => 53, :null => false
t.column "longitude", :float, :limit => 53, :null => false
t.column "user_id", :bigint, :null => false
t.column "visible", :boolean, :null => false
t.column "tags", :text, :default => "", :null => false
t.column "timestamp", :datetime, :null => false
end
add_index "nodes", ["id"], :name => "nodes_uid_idx"

View file

@ -9,10 +9,10 @@ class AddRelations < ActiveRecord::Migration
# differences:
# way: only nodes / relation: any kind of member
# way: ordered sequence of nodes / relation: free-form "role" string
create_table "current_relation_members", innodb_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
create_table "current_relation_members", :id => false do |t|
t.column "id", :bigint, :null => false
t.column "member_type", :nwr_enum, :null => false
t.column "member_id", :bigint, :limit => 11, :null => false
t.column "member_id", :bigint, :null => false
t.column "member_role", :string
end
@ -20,57 +20,54 @@ class AddRelations < ActiveRecord::Migration
add_index "current_relation_members", ["member_type", "member_id"], :name => "current_relation_members_member_idx"
# the following is obsolete given the primary key, is it not?
# add_index "current_relation_members", ["id"], :name => "current_relation_members_id_idx"
create_table "current_relation_tags", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
create_table "current_relation_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
add_index "current_relation_tags", ["id"], :name => "current_relation_tags_id_idx"
add_fulltext_index "current_relation_tags", "v"
add_index "current_relation_tags", "v", :name => "current_relation_tags_v_idx"
create_table "current_relations", innodb_table do |t|
t.column "id", :bigint_pk_64, :null => false
t.column "user_id", :bigint, :limit => 20, :null => false
create_table "current_relations", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint, :null => false
t.column "timestamp", :datetime, :null => false
t.column "visible", :boolean, :null => false
t.column "visible", :boolean, :null => false
end
create_table "relation_members", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :default => 0, :null => false
create_table "relation_members", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "member_type", :nwr_enum, :null => false
t.column "member_id", :bigint, :limit => 11, :null => false
t.column "member_id", :bigint, :null => false
t.column "member_role", :string
t.column "version", :bigint, :limit => 20, :default => 0, :null => false
t.column "version", :bigint, :default => 0, :null => false
end
add_primary_key "relation_members", ["id", "version", "member_type", "member_id", "member_role"]
add_index "relation_members", ["member_type", "member_id"], :name => "relation_members_member_idx"
create_table "relation_tags", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :default => 0, :null => false
create_table "relation_tags", :id => false do |t|
t.column "id", :bigint, :default => 0, :null => false
t.column "k", :string, :null => false, :default => ""
t.column "v", :string, :null => false, :default => ""
t.column "version", :bigint, :limit => 20, :null => false
t.column "version", :bigint, :null => false
end
add_index "relation_tags", ["id", "version"], :name => "relation_tags_id_version_idx"
create_table "relations", myisam_table do |t|
t.column "id", :bigint, :limit => 64, :null => false, :default => 0
t.column "user_id", :bigint, :limit => 20, :null => false
t.column "timestamp", :datetime, :null => false
t.column "version", :bigint, :limit => 20, :null => false
t.column "visible", :boolean, :null => false, :default => true
create_table "relations", :id => false do |t|
t.column "id", :bigint, :null => false, :default => 0
t.column "user_id", :bigint, :null => false
t.column "timestamp", :datetime, :null => false
t.column "version", :bigint, :null => false
t.column "visible", :boolean, :null => false, :default => true
end
add_primary_key "relations", ["id", "version"]
add_index "relations", ["timestamp"], :name => "relations_timestamp_idx"
change_column "relations", "version", :bigint_auto_20
end
def self.down
drop_table :relations
drop_table :current_relations

View file

@ -28,20 +28,20 @@ class RemoveSegments < ActiveRecord::Migration
drop_table :segments
drop_table :way_segments
create_table :way_nodes, myisam_table do |t|
t.column :id, :bigint, :limit => 64, :null => false
t.column :node_id, :bigint, :limit => 64, :null => false
t.column :version, :bigint, :limit => 20, :null => false
t.column :sequence_id, :bigint, :limit => 11, :null => false
create_table :way_nodes, :id => false do |t|
t.column :id, :bigint, :null => false
t.column :node_id, :bigint, :null => false
t.column :version, :bigint, :null => false
t.column :sequence_id, :bigint, :null => false
end
add_primary_key :way_nodes, [:id, :version, :sequence_id]
drop_table :current_segments
drop_table :current_way_segments
create_table :current_way_nodes, innodb_table do |t|
t.column :id, :bigint, :limit => 64, :null => false
t.column :node_id, :bigint, :limit => 64, :null => false
t.column :sequence_id, :bigint, :limit => 11, :null => false
create_table :current_way_nodes, :id => false do |t|
t.column :id, :bigint, :null => false
t.column :node_id, :bigint, :null => false
t.column :sequence_id, :bigint, :null => false
end
add_primary_key :current_way_nodes, [:id, :sequence_id]
add_index :current_way_nodes, [:node_id], :name => "current_way_nodes_node_idx"

View file

@ -2,13 +2,13 @@ require 'migrate'
class DiaryComments < ActiveRecord::Migration
def self.up
create_table "diary_comments", myisam_table do |t|
t.column "id", :bigint_pk, :null => false
t.column "diary_entry_id", :bigint, :limit => 20, :null => false
t.column "user_id", :bigint, :limit => 20, :null => false
t.column "body", :text, :null => false
t.column "created_at", :datetime, :null => false
t.column "updated_at", :datetime, :null => false
create_table "diary_comments", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "diary_entry_id", :bigint, :null => false
t.column "user_id", :bigint, :null => false
t.column "body", :text, :null => false
t.column "created_at", :datetime, :null => false
t.column "updated_at", :datetime, :null => false
end
add_index "diary_comments", ["diary_entry_id", "id"], :name => "diary_comments_entry_id_idx", :unique => true

View file

@ -2,11 +2,11 @@ require 'migrate'
class CreateAcls < ActiveRecord::Migration
def self.up
create_table "acls", myisam_table do |t|
t.column "id", :integer_pk, :null => false
t.column "address", :inet, :null => false
t.column "netmask", :inet, :null => false
t.column "k", :string, :null => false
create_table "acls", :id => false do |t|
t.column "id", :primary_key, :null => false
t.column "address", :inet, :null => false
t.column "netmask", :inet, :null => false
t.column "k", :string, :null => false
t.column "v", :string
end

View file

@ -27,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

View file

@ -12,15 +12,11 @@ class MoveToInnodb < ActiveRecord::Migration
remove_index :current_relation_tags, :name=> :current_relation_tags_v_idx
@@ver_tbl.each { |tbl|
change_column tbl, "version", :bigint, :limit => 20, :null => false
}
@@conv_tables.each { |tbl|
change_engine tbl, "InnoDB"
change_column tbl, "version", :bigint, :null => false
}
@@ver_tbl.each { |tbl|
add_column "current_#{tbl}", "version", :bigint, :limit => 20, :null => false
add_column "current_#{tbl}", "version", :bigint, :null => false
# As the initial version of all nodes, ways and relations is 0, we set the
# current version to something less so that we can update the version in
# batches of 10000

View file

@ -23,21 +23,21 @@ class KeyConstraints < ActiveRecord::Migration
remove_index :nodes, :name => :nodes_uid_idx
# Foreign keys (between ways, way_tags, way_nodes, etc.)
add_foreign_key :current_node_tags, [:id], :current_nodes
add_foreign_key :node_tags, [:id, :version], :nodes
add_foreign_key :current_node_tags, :current_nodes, :column => :id, :name => "current_node_tags_id_fkey"
add_foreign_key :node_tags, :nodes, :column => [:id, :version], :primary_key => [:id, :version], :name => "node_tags_id_fkey"
add_foreign_key :current_way_tags, [:id], :current_ways
add_foreign_key :current_way_nodes, [:id], :current_ways
add_foreign_key :way_tags, [:id, :version], :ways
add_foreign_key :way_nodes, [:id, :version], :ways
add_foreign_key :current_way_tags, :current_ways, :column => :id, :name => "current_way_tags_id_fkey"
add_foreign_key :current_way_nodes, :current_ways, :column => :id, :name => "current_way_nodes_id_fkey"
add_foreign_key :way_tags, :ways, :column => [:id, :version], :primary_key => [:id, :version], :name => "way_tags_id_fkey"
add_foreign_key :way_nodes, :ways, :column => [:id, :version], :primary_key => [:id, :version], :name => "way_nodes_id_fkey"
add_foreign_key :current_relation_tags, [:id], :current_relations
add_foreign_key :current_relation_members, [:id], :current_relations
add_foreign_key :relation_tags, [:id, :version], :relations
add_foreign_key :relation_members, [:id, :version], :relations
add_foreign_key :current_relation_tags, :current_relations, :column => :id, :name => "current_relation_tags_id_fkey"
add_foreign_key :current_relation_members, :current_relations, :column => :id, :name => "current_relation_members_id_fkey"
add_foreign_key :relation_tags, :relations, :column => [:id, :version], :primary_key => [:id, :version], :name => "relation_tags_id_fkey"
add_foreign_key :relation_members, :relations, :column => [:id, :version], :primary_key => [:id, :version], :name => "relation_members_id_fkey"
# Foreign keys (between different types of primitives)
add_foreign_key :current_way_nodes, [:node_id], :current_nodes, [:id]
add_foreign_key :current_way_nodes, :current_nodes, :column => :node_id, :name => "current_way_nodes_node_id_fkey"
# FIXME: We don't have foreign keys for relation members since the id
# might point to a different table depending on the `type' column.

View file

@ -5,19 +5,19 @@ class AddChangesets < ActiveRecord::Migration
'current_relations', 'current_ways', 'nodes', 'relations', 'ways' ]
def self.up
create_table "changesets", innodb_table do |t|
t.column "id", :bigint_pk, :null => false
t.column "user_id", :bigint, :limit => 20, :null => false
t.column "created_at", :datetime, :null => false
t.column "open", :boolean, :null => false, :default => true
t.column "min_lat", :integer, :null => true
t.column "max_lat", :integer, :null => true
t.column "min_lon", :integer, :null => true
t.column "max_lon", :integer, :null => true
create_table "changesets", :id => false do |t|
t.column "id", :bigserial, :primary_key => true, :null => false
t.column "user_id", :bigint, :null => false
t.column "created_at", :datetime, :null => false
t.column "open", :boolean, :null => false, :default => true
t.column "min_lat", :integer, :null => true
t.column "max_lat", :integer, :null => true
t.column "min_lon", :integer, :null => true
t.column "max_lon", :integer, :null => true
end
create_table "changeset_tags", innodb_table do |t|
t.column "id", :bigint, :limit => 64, :null => false
create_table "changeset_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
@ -35,7 +35,7 @@ class AddChangesets < ActiveRecord::Migration
@@conv_user_tables.each { |tbl|
rename_column tbl, :user_id, :changeset_id
#foreign keys too
add_foreign_key tbl, [:changeset_id], :changesets, [:id]
add_foreign_key tbl, :changesets, :name => "#{tbl}_changeset_id_fkey"
}
end

View file

@ -9,8 +9,8 @@ class AddEndTimeToChangesets < ActiveRecord::Migration
# it appears that execute will only accept string arguments, so
# this is an ugly, ugly hack to get some sort of mysql/postgres
# independence. now i have to go wash my brain with bleach.
execute("update changesets set closed_at=(now()-#{interval_constant('1 hour')}) where open=(1=0)")
execute("update changesets set closed_at=(now()+#{interval_constant('1 hour')}) where open=(1=1)")
execute("update changesets set closed_at=(now()-'1 hour'::interval) where open=(1=0)")
execute("update changesets set closed_at=(now()+'1 hour'::interval) where open=(1=1)")
# remove the open column as it is unnecessary now and denormalises
# the table.

View file

@ -4,7 +4,7 @@ class AddMoreChangesetIndexes < ActiveRecord::Migration
def self.up
add_index "changesets", ["created_at"], :name => "changesets_created_at_idx"
add_index "changesets", ["closed_at"], :name => "changesets_closed_at_idx"
add_index "changesets", ["min_lat","max_lat","min_lon","max_lon"], :name => "changesets_bbox_idx", :method => "GIST"
add_index "changesets", ["min_lat","max_lat","min_lon","max_lon"], :name => "changesets_bbox_idx", :using => "GIST"
end
def self.down

View file

@ -1,20 +1,16 @@
require 'migrate'
class AddUserForeignKeys < ActiveRecord::Migration
def self.up
add_foreign_key :changesets, [:user_id], :users, [:id]
add_foreign_key :diary_comments, [:user_id], :users, [:id]
add_foreign_key :diary_entries, [:user_id], :users, [:id]
add_foreign_key :friends, [:user_id], :users, [:id]
add_foreign_key :friends, [:friend_user_id], :users, [:id]
add_foreign_key :gpx_files, [:user_id], :users, [:id]
add_foreign_key :messages, [:from_user_id], :users, [:id]
add_foreign_key :messages, [:to_user_id], :users, [:id]
add_foreign_key :user_preferences, [:user_id], :users, [:id]
add_foreign_key :user_tokens, [:user_id], :users, [:id]
end
def self.down
raise ActiveRecord::IrreversibleMigration
def change
add_foreign_key :changesets, :users, :name => "changesets_user_id_fkey"
add_foreign_key :diary_comments, :users, :name => "diary_comments_user_id_fkey"
add_foreign_key :diary_entries, :users, :name => "diary_entries_user_id_fkey"
add_foreign_key :friends, :users, :name => "friends_user_id_fkey"
add_foreign_key :friends, :users, :column => :friend_user_id, :name => "friends_friend_user_id_fkey"
add_foreign_key :gpx_files, :users, :name => "gpx_files_user_id_fkey"
add_foreign_key :messages, :users, :column => :from_user_id, :name => "messages_from_user_id_fkey"
add_foreign_key :messages, :users, :column => :to_user_id, :name => "messages_to_user_id_fkey"
add_foreign_key :user_preferences, :users, :name => "user_preferences_user_id_fkey"
add_foreign_key :user_tokens, :users, :name => "user_tokens_user_id_fkey"
end
end

View file

@ -2,10 +2,10 @@ require 'migrate'
class AddForeignKeys < ActiveRecord::Migration
def self.up
add_foreign_key :changeset_tags, [:id], :changesets
add_foreign_key :diary_comments, [:diary_entry_id], :diary_entries, [:id]
add_foreign_key :gps_points, [:gpx_id], :gpx_files, [:id]
add_foreign_key :gpx_file_tags, [:gpx_id], :gpx_files, [:id]
add_foreign_key :changeset_tags, :changesets, :column => :id, :name => "changeset_tags_id_fkey"
add_foreign_key :diary_comments, :diary_entries, :name => "diary_comments_diary_entry_id_fkey"
add_foreign_key :gps_points, :gpx_files, :column => :gpx_id, :name => "gps_points_gpx_id_fkey"
add_foreign_key :gpx_file_tags, :gpx_files, :column => :gpx_id, :name => "gpx_file_tags_gpx_id_fkey"
end
def self.down

View file

@ -3,13 +3,13 @@ require 'rexml/document'
class CreateCountries < ActiveRecord::Migration
def self.up
create_table :countries, innodb_table do |t|
t.column :id, :integer_pk, :null => false
t.column :code, :string, :limit => 2, :null => false
t.column :min_lat, :double, :null => false
t.column :max_lat, :double, :null => false
t.column :min_lon, :double, :null => false
t.column :max_lon, :double, :null => false
create_table :countries, :id => false do |t|
t.column :id, :primary_key, :null => false
t.column :code, :string, :limit => 2, :null => false
t.column :min_lat, :float, :limit => 53, :null => false
t.column :max_lat, :float, :limit => 53, :null => false
t.column :min_lon, :float, :limit => 53, :null => false
t.column :max_lon, :float, :limit => 53, :null => false
end
add_index :countries, [:code], :name => "countries_code_idx", :unique => true

View file

@ -1,8 +1,8 @@
require 'migrate'
class CreateLanguages < ActiveRecord::Migration
def self.up
create_table :languages, innodb_table do |t|
def change
create_table :languages, :id => false do |t|
t.string :code, :null => false
t.string :english_name, :null => false
t.string :native_name
@ -12,11 +12,7 @@ class CreateLanguages < ActiveRecord::Migration
Language.load("#{Rails.root}/config/languages.yml")
add_foreign_key :users, [:locale], :languages, [:code]
add_foreign_key :diary_entries, [:language_code], :languages, [:code]
end
def self.down
raise ActiveRecord::IrreversibleMigration
add_foreign_key :users, :languages, :column => :locale, :primary_key => :code, :name => "users_locale_fkey"
add_foreign_key :diary_entries, :languages, :column => :language_code , :primary_key => :code, :name => "diary_entries_language_code_fkey"
end
end

View file

@ -2,7 +2,7 @@ require 'migrate'
class ChangeUserLocale < ActiveRecord::Migration
def self.up
remove_foreign_key :users, [:locale], :languages, [:code]
remove_foreign_key :users, :column => :locale, :name => "users_locale_fkey"
rename_column :users, :locale, :languages
end
@ -10,6 +10,6 @@ class ChangeUserLocale < ActiveRecord::Migration
def self.down
rename_column :users, :languages, :locale
add_foreign_key :users, [:locale], :languages, [:code]
add_foreign_key :users, :languages, :column => :locale, :primary_key => :code, :name => "users_locale_fkey"
end
end

View file

@ -1,15 +1,9 @@
require 'migrate'
class AddForeignKeysToOauthTables < ActiveRecord::Migration
def self.up
add_foreign_key :oauth_tokens, [:user_id], :users, [:id]
add_foreign_key :oauth_tokens, [:client_application_id], :client_applications, [:id]
add_foreign_key :client_applications, [:user_id], :users, [:id]
end
def self.down
remove_foreign_key :oauth_tokens, [:user_id], :users
remove_foreign_key :oauth_tokens, [:client_application_id], :client_applications
remove_foreign_key :client_applications, [:user_id], :users
def change
add_foreign_key :oauth_tokens, :users, :name => "oauth_tokens_user_id_fkey"
add_foreign_key :oauth_tokens, :client_applications, :name => "oauth_tokens_client_application_id_fkey"
add_foreign_key :client_applications, :users, :name => "client_applications_user_id_fkey"
end
end

View file

@ -6,26 +6,29 @@ class CreateUserRoles < ActiveRecord::Migration
create_table :user_roles do |t|
t.column :user_id, :bigint, :null => false
t.column :role, :user_role_enum, :null => false
t.timestamps
end
add_column :user_roles, :role, :user_role_enum, :null => false
User.where(:administrator => true).each do |user|
UserRole.create(:user_id => user.id, :role => "administrator")
end
remove_column :users, :administrator
add_foreign_key :user_roles, [:user_id], :users, [:id]
add_foreign_key :user_roles, :users, :name => "user_roles_user_id_fkey"
end
def self.down
add_column :users, :administrator, :boolean, :default => false, :null => false
UserRole.where(:role => "administrator").each do |role|
user = User.find(role.user_id)
user.administrator = true
user.save!
end
drop_table :user_roles
drop_enumeration :user_role_enum
end

View file

@ -1,7 +1,7 @@
require 'migrate'
class CreateUserBlocks < ActiveRecord::Migration
def self.up
def change
create_table :user_blocks do |t|
t.column :user_id, :bigint, :null => false
t.column :moderator_id, :bigint, :null => false
@ -13,14 +13,10 @@ class CreateUserBlocks < ActiveRecord::Migration
t.timestamps
end
add_foreign_key :user_blocks, [:user_id], :users, [:id]
add_foreign_key :user_blocks, [:moderator_id], :users, [:id]
add_foreign_key :user_blocks, [:revoker_id], :users, [:id]
add_foreign_key :user_blocks, :users, :name => "user_blocks_user_id_fkey"
add_foreign_key :user_blocks, :users, :column => :moderator_id, :name => "user_blocks_moderator_id_fkey"
add_foreign_key :user_blocks, :users, :column => :revoker_id, :name => "user_blocks_revoker_id_fkey"
add_index :user_blocks, [:user_id]
end
def self.down
drop_table :user_blocks
end
end

View file

@ -8,7 +8,7 @@ class AlterUserRolesAndBlocks < ActiveRecord::Migration
add_column :user_roles, :granter_id, :bigint
UserRole.update_all("granter_id = user_id")
change_column :user_roles, :granter_id, :bigint, :null => false
add_foreign_key :user_roles, [:granter_id], :users, [:id]
add_foreign_key :user_roles, :users, :column => :granter_id, :name => "user_roles_granter_id_fkey"
# make sure that [user_id, role] is unique
add_index :user_roles, [:user_id, :role], :name => "user_roles_id_role_unique", :unique => true
@ -21,9 +21,9 @@ class AlterUserRolesAndBlocks < ActiveRecord::Migration
end
def self.down
remove_column :user_roles, :granter_id
remove_index :user_roles, :name => "user_roles_id_role_unique"
rename_column :user_blocks, :creator_id, :moderator_id
rename_column :user_blocks, :ends_at, :end_at
rename_column :user_blocks, :creator_id, :moderator_id
remove_index :user_roles, :name => "user_roles_id_role_unique"
remove_column :user_roles, :granter_id
end
end

View file

@ -18,13 +18,13 @@ class RefactorMapBugTables < ActiveRecord::Migration
add_index :map_bug_comment, [:bug_id], :name => "map_bug_comment_id_idx"
add_foreign_key :map_bug_comment, [:bug_id], :map_bugs, [:id]
add_foreign_key :map_bug_comment, [:commenter_id], :users, [:id]
add_foreign_key :map_bug_comment, :map_bugs, :column => :bug_id, :name => "note_comments_note_id_fkey"
add_foreign_key :map_bug_comment, :users, :column => :commenter_id, :name => "note_comments_author_id_fkey"
end
def self.down
remove_foreign_key :map_bug_comment, [:commenter_id]
remove_foreign_key :map_bug_comment, [:bug_id]
remove_foreign_key :map_bug_comment, :users, :column => :commenter_id, :name => "note_comments_author_id_fkey"
remove_foreign_key :map_bug_comment, :map_bugs, :column => :bug_id, :name => "note_comments_note_id_fkey"
remove_index :map_bugs, :name => "map_bug_comment_id_idx"

View file

@ -6,43 +6,23 @@ class RenameBugsToNotes < ActiveRecord::Migration
rename_enumeration "map_bug_event_enum", "note_event_enum"
rename_table :map_bugs, :notes
rename_index :notes, "map_bugs_pkey", "notes_pkey"
rename_index :notes, "map_bugs_changed_idx", "notes_updated_at_idx"
rename_index :notes, "map_bugs_created_idx", "notes_created_at_idx"
rename_index :notes, "map_bugs_tile_idx", "notes_tile_status_idx"
remove_foreign_key :map_bug_comment, [:bug_id], :map_bugs, [:id]
rename_column :map_bug_comment, :author_id, :commenter_id
remove_foreign_key :map_bug_comment, [:commenter_id], :users, [:id]
rename_column :map_bug_comment, :commenter_id, :author_id
rename_table :map_bug_comment, :note_comments
rename_column :note_comments, :bug_id, :note_id
rename_index :note_comments, "map_bug_comment_pkey", "note_comments_pkey"
rename_index :note_comments, "map_bug_comment_id_idx", "note_comments_note_id_idx"
add_foreign_key :note_comments, [:note_id], :notes, [:id]
add_foreign_key :note_comments, [:author_id], :users, [:id]
end
def self.down
remove_foreign_key :note_comments, [:author_id], :users, [:id]
remove_foreign_key :note_comments, [:note_id], :notes, [:id]
rename_index :note_comments, "note_comments_note_id_idx", "map_bug_comment_id_idx"
rename_index :notes, "note_comments_pkey", "map_bug_comment_pkey"
rename_column :note_comments, :note_id, :bug_id
rename_table :note_comments, :map_bug_comment
rename_column :map_bug_comment, :author_id, :commenter_id
add_foreign_key :map_bug_comment, [:commenter_id], :users, [:id]
rename_column :map_bug_comment, :commenter_id, :author_id
add_foreign_key :map_bug_comment, [:bug_id], :notes, [:id]
rename_index :notes, "notes_tile_status_idx", "map_bugs_tile_idx"
rename_index :notes, "notes_created_at_idx", "map_bugs_created_idx"
rename_index :notes, "notes_updated_at_idx", "map_bugs_changed_idx"
rename_index :notes, "notes_pkey", "map_bugs_pkey"
rename_table :notes, :map_bugs
rename_enumeration "note_event_enum", "map_bug_event_enum"

View file

@ -2,8 +2,8 @@ require 'migrate'
class AddLowercaseUserIndexes < ActiveRecord::Migration
def up
add_index :users, :display_name, :lowercase => true, :name => "users_display_name_lower_idx"
add_index :users, :email, :lowercase => true, :name => "users_email_lower_idx"
add_index :users, [], :columns => "LOWER(display_name)", :name => "users_display_name_lower_idx"
add_index :users, [], :columns => "LOWER(email)", :name => "users_email_lower_idx"
end
def down

View file

@ -1,7 +1,7 @@
require 'migrate'
class CreateRedactions < ActiveRecord::Migration
def up
def change
create_table :redactions do |t|
t.string :title
t.text :description
@ -11,16 +11,7 @@ class CreateRedactions < ActiveRecord::Migration
[:nodes, :ways, :relations].each do |tbl|
add_column tbl, :redaction_id, :integer, :null => true
add_foreign_key tbl, [:redaction_id], :redactions, [:id]
add_foreign_key tbl, :redactions, :name => "#{tbl}_redaction_id_fkey"
end
end
def down
[:nodes, :ways, :relations].each do |tbl|
remove_foreign_key tbl, [:redaction_id], :redactions, [:id]
remove_column tbl, :redaction_id
end
drop_table :redactions
end
end

View file

@ -6,7 +6,7 @@ class DropSessionTable < ActiveRecord::Migration
end
def down
create_table "sessions", :options => innodb_option do |t|
create_table "sessions" do |t|
t.column "session_id", :string
t.column "data", :text
t.column "created_at", :timestamp

View file

@ -1,17 +1,10 @@
require 'migrate'
class AddUserAndDescriptionToRedaction < ActiveRecord::Migration
def up
def change
add_column :redactions, :user_id, :bigint, :null => false
add_column :redactions, :description_format, :format_enum, :null => false, :default => "markdown"
add_foreign_key :redactions, [:user_id], :users, [:id]
end
def down
remove_foreign_key :redactions, [:user_id], :users, [:id]
remove_column :redactions, :description_format
remove_column :redactions, :user_id
add_foreign_key :redactions, :users, :name => "redactions_user_id_fkey"
end
end

View file

@ -2,7 +2,7 @@ require 'migrate'
class AddTextIndexToNoteComments < ActiveRecord::Migration
def up
add_index :note_comments, [], :columns => "to_tsvector('english', body)", :method => "GIN", :name => "index_note_comments_on_body"
add_index :note_comments, [], :columns => "to_tsvector('english', body)", :using => "GIN", :name => "index_note_comments_on_body"
end
def down

View file

@ -10,8 +10,8 @@ class CreateChangesetComments < ActiveRecord::Migration
t.boolean :visible, :null => false
end
add_foreign_key :changeset_comments, [:changeset_id], :changesets, [:id]
add_foreign_key :changeset_comments, [:author_id], :users, [:id]
add_foreign_key :changeset_comments, :changesets, :name => "changeset_comments_changeset_id_fkey"
add_foreign_key :changeset_comments, :users, :column => :author_id, :name => "changeset_comments_author_id_fkey"
add_index :changeset_comments, :created_at
end

View file

@ -7,8 +7,8 @@ class AddJoinTableBetweenUsersAndChangesets < ActiveRecord::Migration
t.column :changeset_id, :bigint, null: false
end
add_foreign_key :changesets_subscribers, [:subscriber_id], :users, [:id]
add_foreign_key :changesets_subscribers, [:changeset_id], :changesets, [:id]
add_foreign_key :changesets_subscribers, :users, :column => :subscriber_id, :name => "changesets_subscribers_subscriber_id_fkey"
add_foreign_key :changesets_subscribers, :changesets, :name => "changesets_subscribers_changeset_id_fkey"
add_index :changesets_subscribers, [:subscriber_id, :changeset_id], :unique => true
add_index :changesets_subscribers, [:changeset_id]

View file

@ -126,7 +126,7 @@ CREATE TYPE user_status_enum AS ENUM (
CREATE FUNCTION maptile_for_point(bigint, bigint, integer) RETURNS integer
LANGUAGE c STRICT
AS '/srv/www/overpass.osm.compton.nu/db/functions/libpgosm.so', 'maptile_for_point';
AS '/srv/www/master.osm.compton.nu/db/functions/libpgosm.so', 'maptile_for_point';
--
@ -135,7 +135,7 @@ CREATE FUNCTION maptile_for_point(bigint, bigint, integer) RETURNS integer
CREATE FUNCTION tile_for_point(integer, integer) RETURNS bigint
LANGUAGE c STRICT
AS '/srv/www/overpass.osm.compton.nu/db/functions/libpgosm.so', 'tile_for_point';
AS '/srv/www/master.osm.compton.nu/db/functions/libpgosm.so', 'tile_for_point';
--
@ -144,7 +144,7 @@ CREATE FUNCTION tile_for_point(integer, integer) RETURNS bigint
CREATE FUNCTION xid_to_int4(xid) RETURNS integer
LANGUAGE c IMMUTABLE STRICT
AS '/srv/www/overpass.osm.compton.nu/db/functions/libpgosm.so', 'xid_to_int4';
AS '/srv/www/master.osm.compton.nu/db/functions/libpgosm.so', 'xid_to_int4';
SET default_tablespace = '';
@ -158,9 +158,9 @@ SET default_with_oids = false;
CREATE TABLE acls (
id integer NOT NULL,
address inet,
k character varying(255) NOT NULL,
v character varying(255),
domain character varying(255)
k character varying NOT NULL,
v character varying,
domain character varying
);
@ -222,8 +222,8 @@ ALTER SEQUENCE changeset_comments_id_seq OWNED BY changeset_comments.id;
CREATE TABLE changeset_tags (
changeset_id bigint NOT NULL,
k character varying(255) DEFAULT ''::character varying NOT NULL,
v character varying(255) DEFAULT ''::character varying NOT NULL
k character varying DEFAULT ''::character varying NOT NULL,
v character varying DEFAULT ''::character varying NOT NULL
);
@ -279,10 +279,10 @@ CREATE TABLE changesets_subscribers (
CREATE TABLE client_applications (
id integer NOT NULL,
name character varying(255),
url character varying(255),
support_url character varying(255),
callback_url character varying(255),
name character varying,
url character varying,
support_url character varying,
callback_url character varying,
key character varying(50),
secret character varying(50),
user_id integer,
@ -323,8 +323,8 @@ ALTER SEQUENCE client_applications_id_seq OWNED BY client_applications.id;
CREATE TABLE current_node_tags (
node_id bigint NOT NULL,
k character varying(255) DEFAULT ''::character varying NOT NULL,
v character varying(255) DEFAULT ''::character varying NOT NULL
k character varying DEFAULT ''::character varying NOT NULL,
v character varying DEFAULT ''::character varying NOT NULL
);
@ -371,7 +371,7 @@ CREATE TABLE current_relation_members (
relation_id bigint NOT NULL,
member_type nwr_enum NOT NULL,
member_id bigint NOT NULL,
member_role character varying(255) NOT NULL,
member_role character varying NOT NULL,
sequence_id integer DEFAULT 0 NOT NULL
);
@ -382,8 +382,8 @@ CREATE TABLE current_relation_members (
CREATE TABLE current_relation_tags (
relation_id bigint NOT NULL,
k character varying(255) DEFAULT ''::character varying NOT NULL,
v character varying(255) DEFAULT ''::character varying NOT NULL
k character varying DEFAULT ''::character varying NOT NULL,
v character varying DEFAULT ''::character varying NOT NULL
);
@ -436,8 +436,8 @@ CREATE TABLE current_way_nodes (
CREATE TABLE current_way_tags (
way_id bigint NOT NULL,
k character varying(255) DEFAULT ''::character varying NOT NULL,
v character varying(255) DEFAULT ''::character varying NOT NULL
k character varying DEFAULT ''::character varying NOT NULL,
v character varying DEFAULT ''::character varying NOT NULL
);
@ -515,13 +515,13 @@ ALTER SEQUENCE diary_comments_id_seq OWNED BY diary_comments.id;
CREATE TABLE diary_entries (
id bigint NOT NULL,
user_id bigint NOT NULL,
title character varying(255) NOT NULL,
title character varying NOT NULL,
body text NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
latitude double precision,
longitude double precision,
language_code character varying(255) DEFAULT 'en'::character varying NOT NULL,
language_code character varying DEFAULT 'en'::character varying NOT NULL,
visible boolean DEFAULT true NOT NULL,
body_format format_enum DEFAULT 'html'::format_enum NOT NULL
);
@ -597,7 +597,7 @@ CREATE TABLE gps_points (
CREATE TABLE gpx_file_tags (
gpx_id bigint DEFAULT 0 NOT NULL,
tag character varying(255) NOT NULL,
tag character varying NOT NULL,
id bigint NOT NULL
);
@ -629,12 +629,12 @@ CREATE TABLE gpx_files (
id bigint NOT NULL,
user_id bigint NOT NULL,
visible boolean DEFAULT true NOT NULL,
name character varying(255) DEFAULT ''::character varying NOT NULL,
name character varying DEFAULT ''::character varying NOT NULL,
size bigint,
latitude double precision,
longitude double precision,
"timestamp" timestamp without time zone NOT NULL,
description character varying(255) DEFAULT ''::character varying NOT NULL,
description character varying DEFAULT ''::character varying NOT NULL,
inserted boolean NOT NULL,
visibility gpx_visibility_enum DEFAULT 'public'::gpx_visibility_enum NOT NULL
);
@ -664,9 +664,9 @@ ALTER SEQUENCE gpx_files_id_seq OWNED BY gpx_files.id;
--
CREATE TABLE languages (
code character varying(255) NOT NULL,
english_name character varying(255) NOT NULL,
native_name character varying(255)
code character varying NOT NULL,
english_name character varying NOT NULL,
native_name character varying
);
@ -677,7 +677,7 @@ CREATE TABLE languages (
CREATE TABLE messages (
id bigint NOT NULL,
from_user_id bigint NOT NULL,
title character varying(255) NOT NULL,
title character varying NOT NULL,
body text NOT NULL,
sent_on timestamp without time zone NOT NULL,
message_read boolean DEFAULT false NOT NULL,
@ -714,8 +714,8 @@ ALTER SEQUENCE messages_id_seq OWNED BY messages.id;
CREATE TABLE node_tags (
node_id bigint NOT NULL,
version bigint NOT NULL,
k character varying(255) DEFAULT ''::character varying NOT NULL,
v character varying(255) DEFAULT ''::character varying NOT NULL
k character varying DEFAULT ''::character varying NOT NULL,
v character varying DEFAULT ''::character varying NOT NULL
);
@ -812,7 +812,7 @@ ALTER SEQUENCE notes_id_seq OWNED BY notes.id;
CREATE TABLE oauth_nonces (
id integer NOT NULL,
nonce character varying(255),
nonce character varying,
"timestamp" integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
@ -859,9 +859,9 @@ CREATE TABLE oauth_tokens (
allow_write_api boolean DEFAULT false NOT NULL,
allow_read_gpx boolean DEFAULT false NOT NULL,
allow_write_gpx boolean DEFAULT false NOT NULL,
callback_url character varying(255),
callback_url character varying,
verifier character varying(20),
scope character varying(255),
scope character varying,
valid_to timestamp without time zone,
allow_write_notes boolean DEFAULT false NOT NULL
);
@ -892,7 +892,7 @@ ALTER SEQUENCE oauth_tokens_id_seq OWNED BY oauth_tokens.id;
CREATE TABLE redactions (
id integer NOT NULL,
title character varying(255),
title character varying,
description text,
created_at timestamp without time zone,
updated_at timestamp without time zone,
@ -928,7 +928,7 @@ CREATE TABLE relation_members (
relation_id bigint DEFAULT 0 NOT NULL,
member_type nwr_enum NOT NULL,
member_id bigint NOT NULL,
member_role character varying(255) NOT NULL,
member_role character varying NOT NULL,
version bigint DEFAULT 0 NOT NULL,
sequence_id integer DEFAULT 0 NOT NULL
);
@ -940,8 +940,8 @@ CREATE TABLE relation_members (
CREATE TABLE relation_tags (
relation_id bigint DEFAULT 0 NOT NULL,
k character varying(255) DEFAULT ''::character varying NOT NULL,
v character varying(255) DEFAULT ''::character varying NOT NULL,
k character varying DEFAULT ''::character varying NOT NULL,
v character varying DEFAULT ''::character varying NOT NULL,
version bigint NOT NULL
);
@ -965,7 +965,7 @@ CREATE TABLE relations (
--
CREATE TABLE schema_migrations (
version character varying(255) NOT NULL
version character varying NOT NULL
);
@ -1012,8 +1012,8 @@ ALTER SEQUENCE user_blocks_id_seq OWNED BY user_blocks.id;
CREATE TABLE user_preferences (
user_id bigint NOT NULL,
k character varying(255) NOT NULL,
v character varying(255) NOT NULL
k character varying NOT NULL,
v character varying NOT NULL
);
@ -1024,9 +1024,9 @@ CREATE TABLE user_preferences (
CREATE TABLE user_roles (
id integer NOT NULL,
user_id bigint NOT NULL,
role user_role_enum NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
role user_role_enum NOT NULL,
granter_id bigint NOT NULL
);
@ -1057,7 +1057,7 @@ ALTER SEQUENCE user_roles_id_seq OWNED BY user_roles.id;
CREATE TABLE user_tokens (
id bigint NOT NULL,
user_id bigint NOT NULL,
token character varying(255) NOT NULL,
token character varying NOT NULL,
expiry timestamp without time zone NOT NULL,
referer text
);
@ -1087,36 +1087,36 @@ ALTER SEQUENCE user_tokens_id_seq OWNED BY user_tokens.id;
--
CREATE TABLE users (
email character varying(255) NOT NULL,
email character varying NOT NULL,
id bigint NOT NULL,
pass_crypt character varying(255) NOT NULL,
pass_crypt character varying NOT NULL,
creation_time timestamp without time zone NOT NULL,
display_name character varying(255) DEFAULT ''::character varying NOT NULL,
display_name character varying DEFAULT ''::character varying NOT NULL,
data_public boolean DEFAULT false NOT NULL,
description text DEFAULT ''::text NOT NULL,
home_lat double precision,
home_lon double precision,
home_zoom smallint DEFAULT 3,
nearby integer DEFAULT 50,
pass_salt character varying(255),
pass_salt character varying,
image_file_name text,
email_valid boolean DEFAULT false NOT NULL,
new_email character varying(255),
creation_ip character varying(255),
languages character varying(255),
new_email character varying,
creation_ip character varying,
languages character varying,
status user_status_enum DEFAULT 'pending'::user_status_enum NOT NULL,
terms_agreed timestamp without time zone,
consider_pd boolean DEFAULT false NOT NULL,
openid_url character varying(255),
preferred_editor character varying(255),
openid_url character varying,
preferred_editor character varying,
terms_seen boolean DEFAULT false NOT NULL,
description_format format_enum DEFAULT 'html'::format_enum NOT NULL,
image_fingerprint character varying(255),
image_fingerprint character varying,
changesets_count integer DEFAULT 0 NOT NULL,
traces_count integer DEFAULT 0 NOT NULL,
diary_entries_count integer DEFAULT 0 NOT NULL,
image_use_gravatar boolean DEFAULT true NOT NULL,
image_content_type character varying(255)
image_content_type character varying
);
@ -1157,8 +1157,8 @@ CREATE TABLE way_nodes (
CREATE TABLE way_tags (
way_id bigint DEFAULT 0 NOT NULL,
k character varying(255) NOT NULL,
v character varying(255) NOT NULL,
k character varying NOT NULL,
v character varying NOT NULL,
version bigint NOT NULL
);

View file

@ -1,143 +1,49 @@
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
class SchemaCreation
alias_method :old_add_column_options!, :add_column_options!
module SchemaStatements
def add_index_options_with_columns(table_name, column_name, options = {})
columns = options.delete(:columns)
index_name, index_type, index_columns, index_options, algorithm, using = add_index_options_without_columns(table_name, column_name, options)
[index_name, index_type, columns || index_columns, index_options, algorithm, using]
end
def add_column_options!(sql, options)
sql << " UNSIGNED" if options[:unsigned]
old_add_column_options!(sql, options)
sql << " #{options[:options]}"
alias_method_chain :add_index_options, :columns
end
module PostgreSQL
module Quoting
def quote_column_name_with_arrays(name)
Array(name).map { |n| quote_column_name_without_arrays(n) }.join(", ")
end
alias_method_chain :quote_column_name, :arrays
end
module SchemaStatements
def quote_column_names(column_name)
Array(column_name).map { |e| quote_column_name(e) }.join(", ")
end
def add_primary_key(table_name, column_name, options = {})
column_names = Array(column_name)
quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{quoted_column_names})"
execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
end
def remove_primary_key(table_name)
execute "ALTER TABLE #{table_name} DROP PRIMARY KEY"
execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
end
def add_foreign_key(table_name, column_name, reftbl, refcol = nil)
execute "ALTER TABLE #{table_name} ADD " +
"FOREIGN KEY (#{quote_column_names(column_name)}) " +
"REFERENCES #{reftbl} (#{quote_column_names(refcol || column_name)})"
def alter_primary_key(table_name, new_columns)
execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + "_pkey")}"
execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
end
def remove_foreign_key(table_name, column_name, reftbl, refcol = nil)
execute "ALTER TABLE #{table_name} DROP " +
"CONSTRAINT #{table_name}_#{column_name[0]}_fkey"
def create_enumeration(enumeration_name, values)
execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
end
# alias_method :old_options_include_default?, :options_include_default?
#
# def options_include_default?(options)
# return false if options[:options] =~ /AUTO_INCREMENT/i
# return old_options_include_default?(options)
# end
end
alias_method :old_native_database_types, :native_database_types
def native_database_types
types = old_native_database_types
types[:double] = { :name => "double precision" }
types[:integer_pk] = { :name => "serial PRIMARY KEY" }
types[:bigint_pk] = { :name => "bigserial PRIMARY KEY" }
types[:bigint_pk_64] = { :name => "bigserial PRIMARY KEY" }
types[:bigint_auto_64] = { :name => "bigint" } #fixme: need autoincrement?
types[:bigint_auto_11] = { :name => "bigint" } #fixme: need autoincrement?
types[:bigint_auto_20] = { :name => "bigint" } #fixme: need autoincrement?
types[:four_byte_unsigned] = { :name => "bigint" } # meh
types[:inet] = { :name=> "inet" }
enumerations.each_key do |e|
types[e.to_sym]= { :name => e }
def drop_enumeration(enumeration_name)
execute "DROP TYPE #{enumeration_name}"
end
types
end
def myisam_table
return { :id => false, :force => true, :options => ""}
end
def innodb_table
return { :id => false, :force => true, :options => ""}
end
def innodb_option
return ""
end
def change_engine (table_name, engine)
end
def add_fulltext_index (table_name, column)
execute "CREATE INDEX #{table_name}_#{column}_idx on #{table_name} (#{column})"
end
def enumerations
@enumerations ||= Hash.new
end
def create_enumeration(enumeration_name, values)
enumerations[enumeration_name] = values
execute "CREATE TYPE #{enumeration_name} AS ENUM ('#{values.join '\',\''}')"
end
def drop_enumeration(enumeration_name)
execute "DROP TYPE #{enumeration_name}"
enumerations.delete(enumeration_name)
end
def rename_enumeration(old_name, new_name)
execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
end
def alter_primary_key(table_name, new_columns)
execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{table_name}_pkey"
execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns.join(',')})"
end
def interval_constant(interval)
"'#{interval}'::interval"
end
def add_index(table_name, column_name, options = {})
column_names = Array(column_name)
index_name = index_name(table_name, :column => column_names)
if Hash === options # legacy support, since this param was a string
index_type = options[:unique] ? "UNIQUE" : ""
index_name = options[:name] || index_name
index_method = options[:method] || "BTREE"
else
index_type = options
def rename_enumeration(old_name, new_name)
execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
end
quoted_column_names = column_names.map { |e| quote_column_name(e) }
if Hash === options and options[:lowercase]
quoted_column_names = quoted_column_names.map { |e| "LOWER(#{e})" }
end
if Hash === options and options[:columns]
quoted_column_names = quoted_column_names + Array[options[:columns]]
end
quoted_column_names = quoted_column_names.join(", ")
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} USING #{index_method} (#{quoted_column_names})"
end
def rename_index(table_name, old_name, new_name)
execute "ALTER INDEX #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
end
end
end