diff options
author | Raphael Sofaer <raphael@joindiaspora.com> | 2011-06-16 02:59:08 +0400 |
---|---|---|
committer | Raphael Sofaer <raphael@joindiaspora.com> | 2011-06-19 18:16:30 +0400 |
commit | 9309456c414e6ac8ead13d774e5b6b60308e60f6 (patch) | |
tree | 62bbbf4537484db9b6e1107383101333316b418f /db | |
parent | cb59930749a0f93636ed7c803fda61333e668f31 (diff) |
Don't run non pg compatible migrations on empty tables
Diffstat (limited to 'db')
11 files changed, 44 insertions, 23 deletions
diff --git a/db/migrate/20110328202414_post_visibilities_on_contacts.rb b/db/migrate/20110328202414_post_visibilities_on_contacts.rb index c173ea2c1..26a3c0b26 100644 --- a/db/migrate/20110328202414_post_visibilities_on_contacts.rb +++ b/db/migrate/20110328202414_post_visibilities_on_contacts.rb @@ -57,7 +57,11 @@ SQL end def self.pv_count - @pv_count ||= execute('SELECT count(*) FROM post_visibilities').to_a.first.first + @pv_count ||= lambda { + count = execute('SELECT count(*) FROM post_visibilities').to_a.first.first + count = count.last.to_i if self.connection.class == ActiveRecord::ConnectionAdapters::PostgreSQLAdapter + count + }.call 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/schema.rb b/db/schema.rb index 64324d449..d7e34da15 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -81,7 +81,7 @@ ActiveRecord::Schema.define(:version => 20110606192307) do t.datetime "updated_at" end - add_index "conversation_visibilities", ["conversation_id", "person_id"], :name => "index_conversation_visibilities_on_conversation_id_and_person_id", :unique => true + add_index "conversation_visibilities", ["conversation_id", "person_id"], :name => "index_conversation_visibilities_on_everything", :unique => true add_index "conversation_visibilities", ["conversation_id"], :name => "index_conversation_visibilities_on_conversation_id" add_index "conversation_visibilities", ["person_id"], :name => "index_conversation_visibilities_on_person_id" @@ -93,8 +93,6 @@ ActiveRecord::Schema.define(:version => 20110606192307) do t.datetime "updated_at" end - add_index "conversations", ["author_id"], :name => "conversations_author_id_fk" - create_table "invitations", :force => true do |t| t.text "message" t.integer "sender_id", :null => false @@ -119,7 +117,6 @@ ActiveRecord::Schema.define(:version => 20110606192307) do t.datetime "updated_at" end - add_index "likes", ["author_id"], :name => "likes_author_id_fk" add_index "likes", ["guid"], :name => "index_likes_on_guid", :unique => true add_index "likes", ["post_id"], :name => "index_likes_on_post_id" @@ -144,7 +141,6 @@ ActiveRecord::Schema.define(:version => 20110606192307) do end add_index "messages", ["author_id"], :name => "index_messages_on_author_id" - add_index "messages", ["conversation_id"], :name => "messages_conversation_id_fk" create_table "notification_actors", :force => true do |t| t.integer "notification_id" |