diff options
author | Raphael Sofaer <raphael@joindiaspora.com> | 2011-06-29 04:13:38 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-06-29 04:13:38 +0400 |
commit | 1af945de11739eeda625164290867138e9416610 (patch) | |
tree | cba0753a4f5c5947b03c2270a34c8bb5c3adbf5f /db | |
parent | 7fd9b81e555ff2baa5019ca3ae3d4bb340bd2e64 (diff) | |
parent | 7ba80ce7992064956b57df7b4bfe3e53100394a5 (diff) |
Merge branch 'master' into oauth
Conflicts:
Gemfile
Gemfile.lock
app/models/app_config.rb
app/models/post.rb
db/schema.rb
public/stylesheets/sass/application.sass
spec/lib/webfinger_spec.rb
Diffstat (limited to 'db')
16 files changed, 133 insertions, 75 deletions
diff --git a/db/migrate/20110125190034_unique_index_on_profile.rb b/db/migrate/20110125190034_unique_index_on_profile.rb index aff7cf70f..de27e44d3 100644 --- a/db/migrate/20110125190034_unique_index_on_profile.rb +++ b/db/migrate/20110125190034_unique_index_on_profile.rb @@ -1,27 +1,30 @@ class UniqueIndexOnProfile < ActiveRecord::Migration + class Profile < ActiveRecord::Base; end def self.up - conn = ActiveRecord::Base.connection - columns = conn.columns("profiles").map{|c| c.name} - ["id", "created_at", "updated_at"].each{|n| columns.delete(n)} + if Profile.count > 0 + conn = ActiveRecord::Base.connection + columns = conn.columns("profiles").map{|c| c.name} + ["id", "created_at", "updated_at"].each{|n| columns.delete(n)} - sql = <<-SQL - SELECT profiles.person_id FROM profiles - GROUP BY #{columns.join(',')} - HAVING COUNT(*)>1 AND profiles.person_id IS NOT NULL; - SQL - result = conn.execute(sql) - duplicate_person_ids = result.to_a.flatten + sql = <<-SQL + SELECT profiles.person_id FROM profiles + GROUP BY #{columns.join(',')} + HAVING COUNT(*)>1 AND profiles.person_id IS NOT NULL; + SQL + result = conn.execute(sql) + duplicate_person_ids = result.to_a.flatten - undesired_profile_ids = [] - duplicate_person_ids.each do |person_id| - profile_ids = conn.execute(" - SELECT profiles.id FROM profiles - WHERE profiles.person_id = #{person_id};").to_a.flatten - profile_ids.pop - undesired_profile_ids.concat(profile_ids) + undesired_profile_ids = [] + duplicate_person_ids.each do |person_id| + profile_ids = conn.execute(" + SELECT profiles.id FROM profiles + WHERE profiles.person_id = #{person_id};").to_a.flatten + profile_ids.pop + undesired_profile_ids.concat(profile_ids) + end + conn.execute("DELETE FROM profiles + WHERE profiles.id IN (#{undesired_profile_ids.join(",")});") unless undesired_profile_ids.empty? end - conn.execute("DELETE FROM profiles - WHERE profiles.id IN (#{undesired_profile_ids.join(",")});") unless undesired_profile_ids.empty? remove_index :profiles, :person_id add_index :profiles, :person_id, :unique => true @@ -29,5 +32,6 @@ class UniqueIndexOnProfile < ActiveRecord::Migration def self.down remove_index :profiles, :person_id + add_index :profiles, :person_id end end diff --git a/db/migrate/20110328202414_post_visibilities_on_contacts.rb b/db/migrate/20110328202414_post_visibilities_on_contacts.rb index c173ea2c1..1445f3a9f 100644 --- a/db/migrate/20110328202414_post_visibilities_on_contacts.rb +++ b/db/migrate/20110328202414_post_visibilities_on_contacts.rb @@ -1,4 +1,5 @@ class PostVisibilitiesOnContacts < ActiveRecord::Migration + class PostVisibility < ActiveRecord::Base; end def self.move_author_pvs_to_aspect_pvs where_clause = <<SQL FROM post_visibilities as pv @@ -57,7 +58,7 @@ SQL end def self.pv_count - @pv_count ||= execute('SELECT count(*) FROM post_visibilities').to_a.first.first + @pv_count ||= PostVisibility.count end def self.up diff --git a/db/migrate/20110330230206_pm_foreign_keys.rb b/db/migrate/20110330230206_pm_foreign_keys.rb index d70e4ab8a..a9218eb83 100644 --- a/db/migrate/20110330230206_pm_foreign_keys.rb +++ b/db/migrate/20110330230206_pm_foreign_keys.rb @@ -1,4 +1,7 @@ class PmForeignKeys < ActiveRecord::Migration + class Message < ActiveRecord::Base + end + def self.delete_disconnected_cvs execute <<SQL DELETE conversation_visibilities FROM conversation_visibilities @@ -23,7 +26,7 @@ SQL SQL end def self.up - if execute('SELECT COUNT(*) FROM messages').to_a.first.first > 0 + if Message.count > 0 delete_disconnected_conversations delete_disconnected_messages delete_disconnected_cvs diff --git a/db/migrate/20110405171412_contact_remove_pending_add_sharing_and_receiving.rb b/db/migrate/20110405171412_contact_remove_pending_add_sharing_and_receiving.rb index a3cc57b59..4a18d85ef 100644 --- a/db/migrate/20110405171412_contact_remove_pending_add_sharing_and_receiving.rb +++ b/db/migrate/20110405171412_contact_remove_pending_add_sharing_and_receiving.rb @@ -1,21 +1,25 @@ class ContactRemovePendingAddSharingAndReceiving < ActiveRecord::Migration + class Contact < ActiveRecord::Base; end + def self.up add_column :contacts, :sharing, :boolean, :default => false, :null => false add_column :contacts, :receiving, :boolean, :default => false, :null => false - execute( <<SQL - UPDATE contacts - SET contacts.sharing = true, contacts.receiving = true - WHERE contacts.pending = false + if Contact.count > 0 + execute( <<SQL + UPDATE contacts + SET contacts.sharing = true, contacts.receiving = true + WHERE contacts.pending = false SQL ) - execute( <<SQL - DELETE user_preferences.* FROM user_preferences - WHERE user_preferences.email_type = 'request_acceptance' - OR user_preferences.email_type = 'request_received' + execute( <<SQL + DELETE user_preferences.* FROM user_preferences + WHERE user_preferences.email_type = 'request_acceptance' + OR user_preferences.email_type = 'request_received' SQL ) + end remove_foreign_key "contacts", "people" remove_index :contacts, [:person_id, :pending] diff --git a/db/migrate/20110406202932_drop_requests_table.rb b/db/migrate/20110406202932_drop_requests_table.rb index bff8df042..96a9b1d4d 100644 --- a/db/migrate/20110406202932_drop_requests_table.rb +++ b/db/migrate/20110406202932_drop_requests_table.rb @@ -1,4 +1,6 @@ class DropRequestsTable < ActiveRecord::Migration + class Contact < ActiveRecord::Base; end + def self.up remove_foreign_key :requests, :column => :recipient_id remove_foreign_key :requests, :column => :sender_id @@ -14,7 +16,7 @@ class DropRequestsTable < ActiveRecord::Migration DELETE contacts.* FROM contacts WHERE contacts.sharing = false SQL -) + ) if Contact.count > 0 end def self.down diff --git a/db/migrate/20110406203720_tag_name_uniqueness.rb b/db/migrate/20110406203720_tag_name_uniqueness.rb index 4e07f2060..7b3ed72d5 100644 --- a/db/migrate/20110406203720_tag_name_uniqueness.rb +++ b/db/migrate/20110406203720_tag_name_uniqueness.rb @@ -1,4 +1,6 @@ class TagNameUniqueness < ActiveRecord::Migration + class Tag < ActiveRecord::Base; end + def self.downcase_tags execute <<SQL UPDATE tags @@ -30,8 +32,10 @@ SQL end def self.up - downcase_tags - consolidate_duplicate_tags + if Tag.count > 0 + downcase_tags + consolidate_duplicate_tags + end add_index :tags, :name, :unique => true end diff --git a/db/migrate/20110421120744_downcase_usernames.rb b/db/migrate/20110421120744_downcase_usernames.rb index a4d24d1ab..34582eb63 100644 --- a/db/migrate/20110421120744_downcase_usernames.rb +++ b/db/migrate/20110421120744_downcase_usernames.rb @@ -1,6 +1,8 @@ class DowncaseUsernames < ActiveRecord::Migration + class User < ActiveRecord::Base; end + def self.up - execute <<SQL + execute <<SQL if User.count > 0 UPDATE users SET users.username = LOWER(users.username) WHERE users.username != LOWER(users.username) diff --git a/db/migrate/20110513175000_eliminate_stray_user_records.rb b/db/migrate/20110513175000_eliminate_stray_user_records.rb index 7bd1ee00a..c06d325cb 100644 --- a/db/migrate/20110513175000_eliminate_stray_user_records.rb +++ b/db/migrate/20110513175000_eliminate_stray_user_records.rb @@ -1,5 +1,8 @@ class EliminateStrayUserRecords < ActiveRecord::Migration + class User < ActiveRecord::Base; end + def self.up + return unless User.count > 0 duplicated_emails = execute("SELECT LOWER(email) from users WHERE users.email != '' GROUP BY LOWER(email) HAVING COUNT(*) > 1").to_a duplicated_emails.each do |email| records = execute("SELECT users.id, users.username, users.created_at from users WHERE LOWER(users.email) = '#{email}'").to_a diff --git a/db/migrate/20110517180148_delete_all_new_request_notifications.rb b/db/migrate/20110517180148_delete_all_new_request_notifications.rb index 971e992a9..857f23070 100644 --- a/db/migrate/20110517180148_delete_all_new_request_notifications.rb +++ b/db/migrate/20110517180148_delete_all_new_request_notifications.rb @@ -1,6 +1,7 @@ class DeleteAllNewRequestNotifications < ActiveRecord::Migration + class Notification < ActiveRecord::Base; end def self.up - execute <<SQL + execute <<SQL if Notification.count > 0 DELETE notifications.* FROM notifications WHERE notifications.type = 'Notifications::NewRequest' OR notifications.type = 'Notifications::RequestAccepted' diff --git a/db/migrate/20110518010050_disable_password_reset_for_accounts_without_usernames.rb b/db/migrate/20110518010050_disable_password_reset_for_accounts_without_usernames.rb index fca3c53d0..d8dce2ba3 100644 --- a/db/migrate/20110518010050_disable_password_reset_for_accounts_without_usernames.rb +++ b/db/migrate/20110518010050_disable_password_reset_for_accounts_without_usernames.rb @@ -1,6 +1,7 @@ class DisablePasswordResetForAccountsWithoutUsernames < ActiveRecord::Migration + class User < ActiveRecord::Base; end def self.up - execute <<SQL + execute <<SQL if User.count > 0 UPDATE users SET email = "" WHERE username IS NULL diff --git a/db/migrate/20110524184202_add_object_id_to_post.rb b/db/migrate/20110524184202_add_object_id_to_post.rb index 77a707c79..5245032da 100644 --- a/db/migrate/20110524184202_add_object_id_to_post.rb +++ b/db/migrate/20110524184202_add_object_id_to_post.rb @@ -1,10 +1,11 @@ class AddObjectIdToPost < ActiveRecord::Migration + class Post < ActiveRecord::Base; end def self.up add_column(:posts, :objectId, :integer) - execute("UPDATE posts SET objectId = object_url") + execute("UPDATE posts SET objectId = object_url") if Post.count > 0 end def self.down - add_column(:posts, :objectId, :integer) + remove_column(:posts, :objectId, :integer) end end diff --git a/db/migrate/20110603233202_drop_aspects_open.rb b/db/migrate/20110603233202_drop_aspects_open.rb new file mode 100644 index 000000000..6bf015561 --- /dev/null +++ b/db/migrate/20110603233202_drop_aspects_open.rb @@ -0,0 +1,10 @@ +class DropAspectsOpen < ActiveRecord::Migration + require File.join(Rails.root, "db", "migrate", "20110202015222_add_open_to_aspects") + def self.up + AddOpenToAspects.down + end + + def self.down + AddOpenToAspects.up + end +end diff --git a/db/migrate/20110604012703_drop_mongo_remains.rb b/db/migrate/20110604012703_drop_mongo_remains.rb new file mode 100644 index 000000000..70a812d17 --- /dev/null +++ b/db/migrate/20110604012703_drop_mongo_remains.rb @@ -0,0 +1,18 @@ +class DropMongoRemains < ActiveRecord::Migration + def self.up + remove_index :aspects, :mongo_id + remove_index :comments, :mongo_id + remove_index :contacts, :mongo_id + remove_index :invitations, :mongo_id + remove_index :people, :mongo_id + remove_index :posts, :mongo_id + remove_index :profiles, :mongo_id + remove_index :services, :mongo_id + remove_index :users, :mongo_id + + drop_table :mongo_notifications + end + + def self.down + end +end diff --git a/db/migrate/20110604204533_index_on_remember_token.rb b/db/migrate/20110604204533_index_on_remember_token.rb new file mode 100644 index 000000000..6351a6a99 --- /dev/null +++ b/db/migrate/20110604204533_index_on_remember_token.rb @@ -0,0 +1,9 @@ +class IndexOnRememberToken < ActiveRecord::Migration + def self.up + add_index :users, :remember_token, :unique => true + end + + def self.down + remove_index :users, :column => :remember_token + end +end diff --git a/db/migrate/20110606192307_drop_mongo_ids.rb b/db/migrate/20110606192307_drop_mongo_ids.rb new file mode 100644 index 000000000..159a1f07e --- /dev/null +++ b/db/migrate/20110606192307_drop_mongo_ids.rb @@ -0,0 +1,29 @@ +class DropMongoIds < ActiveRecord::Migration + def self.up + remove_column :aspects, :mongo_id + remove_column :aspects, :user_mongo_id + remove_column :comments, :mongo_id + remove_column :contacts, :mongo_id + remove_column :invitations, :mongo_id + remove_column :people, :mongo_id + remove_column :posts, :mongo_id + remove_column :profiles, :mongo_id + remove_column :services, :mongo_id + remove_column :services, :user_mongo_id + remove_column :users, :mongo_id + end + + def self.down + add_column :users, :mongo_id + add_column :services, :user_mongo_id + add_column :services, :mongo_id + add_column :profiles, :mongo_id + add_column :posts, :mongo_id + add_column :people, :mongo_id + add_column :invitations, :mongo_id + add_column :contacts, :mongo_id + add_column :comments, :mongo_id + add_column :aspects, :user_mongo_id + add_column :aspects, :mongo_id + end +end diff --git a/db/schema.rb b/db/schema.rb index fe05befad..921cabc24 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -35,17 +35,13 @@ ActiveRecord::Schema.define(:version => 20110623210918) do add_index "aspect_visibilities", ["post_id"], :name => "index_aspect_visibilities_on_post_id" create_table "aspects", :force => true do |t| - t.string "name", :null => false - t.integer "user_id", :null => false + t.string "name", :null => false + t.integer "user_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" - t.string "user_mongo_id" - t.boolean "contacts_visible", :default => true, :null => false - t.boolean "open", :default => false + t.boolean "contacts_visible", :default => true, :null => false end - add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id" add_index "aspects", ["user_id", "contacts_visible"], :name => "index_aspects_on_user_id_and_contacts_visible" add_index "aspects", ["user_id"], :name => "index_aspects_on_user_id" @@ -59,12 +55,10 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.text "youtube_titles" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "comments", ["author_id"], :name => "index_comments_on_person_id" add_index "comments", ["guid"], :name => "index_comments_on_guid", :unique => true - add_index "comments", ["mongo_id"], :name => "index_comments_on_mongo_id" add_index "comments", ["post_id"], :name => "index_comments_on_post_id" create_table "contacts", :force => true do |t| @@ -72,12 +66,10 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.integer "person_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" t.boolean "sharing", :default => false, :null => false t.boolean "receiving", :default => false, :null => false end - add_index "contacts", ["mongo_id"], :name => "index_contacts_on_mongo_id" add_index "contacts", ["person_id"], :name => "index_contacts_on_person_id" add_index "contacts", ["user_id", "person_id"], :name => "index_contacts_on_user_id_and_person_id", :unique => true @@ -110,11 +102,9 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.integer "aspect_id" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "invitations", ["aspect_id"], :name => "index_invitations_on_aspect_id" - add_index "invitations", ["mongo_id"], :name => "index_invitations_on_mongo_id" add_index "invitations", ["recipient_id"], :name => "index_invitations_on_recipient_id" add_index "invitations", ["sender_id"], :name => "index_invitations_on_sender_id" @@ -156,20 +146,6 @@ ActiveRecord::Schema.define(:version => 20110623210918) do add_index "messages", ["author_id"], :name => "index_messages_on_author_id" add_index "messages", ["conversation_id"], :name => "messages_conversation_id_fk" - create_table "mongo_notifications", :force => true do |t| - t.string "mongo_id" - t.string "target_type", :limit => 127 - t.string "target_mongo_id", :limit => 127 - t.string "recipient_mongo_id" - t.string "actor_mongo_id" - t.string "action" - t.boolean "unread", :default => true - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "mongo_notifications", ["target_type", "target_mongo_id"], :name => "index_mongo_notifications_on_target_type_and_target_mongo_id" - create_table "notification_actors", :force => true do |t| t.integer "notification_id" t.integer "person_id" @@ -247,12 +223,10 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.integer "owner_id" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "people", ["diaspora_handle"], :name => "index_people_on_diaspora_handle", :unique => true add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true - add_index "people", ["mongo_id"], :name => "index_people_on_mongo_id" add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true create_table "post_visibilities", :force => true do |t| @@ -283,7 +257,6 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.text "youtube_titles" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" t.string "unprocessed_image" t.string "object_url" t.string "image_url" @@ -297,7 +270,6 @@ ActiveRecord::Schema.define(:version => 20110623210918) do add_index "posts", ["author_id"], :name => "index_posts_on_person_id" add_index "posts", ["guid"], :name => "index_posts_on_guid", :unique => true - add_index "posts", ["mongo_id"], :name => "index_posts_on_mongo_id" add_index "posts", ["status_message_guid", "pending"], :name => "index_posts_on_status_message_guid_and_pending" add_index "posts", ["status_message_guid"], :name => "index_posts_on_status_message_guid" add_index "posts", ["type", "pending", "id"], :name => "index_posts_on_type_and_pending_and_id" @@ -316,14 +288,12 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.integer "person_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" t.string "location" end add_index "profiles", ["first_name", "last_name", "searchable"], :name => "index_profiles_on_first_name_and_last_name_and_searchable" add_index "profiles", ["first_name", "searchable"], :name => "index_profiles_on_first_name_and_searchable" add_index "profiles", ["last_name", "searchable"], :name => "index_profiles_on_last_name_and_searchable" - add_index "profiles", ["mongo_id"], :name => "index_profiles_on_mongo_id" add_index "profiles", ["person_id"], :name => "index_profiles_on_person_id" create_table "service_users", :force => true do |t| @@ -351,11 +321,8 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.string "nickname" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" - t.string "user_mongo_id" end - add_index "services", ["mongo_id"], :name => "index_services_on_mongo_id" add_index "services", ["user_id"], :name => "index_services_on_user_id" create_table "taggings", :force => true do |t| @@ -406,7 +373,6 @@ ActiveRecord::Schema.define(:version => 20110623210918) do t.string "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" t.string "invitation_service", :limit => 127 t.string "invitation_identifier", :limit => 127 t.integer "invitation_limit" @@ -420,7 +386,7 @@ ActiveRecord::Schema.define(:version => 20110623210918) do add_index "users", ["email"], :name => "index_users_on_email" add_index "users", ["invitation_service", "invitation_identifier"], :name => "index_users_on_invitation_service_and_invitation_identifier", :unique => true add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token" - add_index "users", ["mongo_id"], :name => "index_users_on_mongo_id" + add_index "users", ["remember_token"], :name => "index_users_on_remember_token", :unique => true add_index "users", ["username"], :name => "index_users_on_username", :unique => true add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk", :dependent => :delete |