Don't run non pg compatible migrations on empty tables
This commit is contained in:
parent
cb59930749
commit
9309456c41
11 changed files with 44 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue