about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorpluralcafe-docker <git@plural.cafe>2018-10-30 05:54:55 +0000
committerpluralcafe-docker <git@plural.cafe>2018-10-30 05:54:55 +0000
commit431c09bfbe07715a2a88846864179a419d72ab59 (patch)
tree8b7772f64ea23cdf5e55dda9f92ff57a41adf3a4 /db
parent7c96ee7815c216d6ac3b748d7dd6959376d3914e (diff)
parent7ec3f6022d5c991bb584c481a29c416e9f1c5438 (diff)
Merge branch 'glitch'
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20181010141500_add_silent_to_mentions.rb23
-rw-r--r--db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb17
-rw-r--r--db/migrate/20181018205649_add_unread_to_account_conversations.rb23
-rw-r--r--db/migrate/20181024224956_migrate_account_conversations.rb75
-rw-r--r--db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb16
-rw-r--r--db/schema.rb5
6 files changed, 158 insertions, 1 deletions
diff --git a/db/migrate/20181010141500_add_silent_to_mentions.rb b/db/migrate/20181010141500_add_silent_to_mentions.rb
new file mode 100644
index 000000000..dbb4fba26
--- /dev/null
+++ b/db/migrate/20181010141500_add_silent_to_mentions.rb
@@ -0,0 +1,23 @@
+require Rails.root.join('lib', 'mastodon', 'migration_helpers')
+
+class AddSilentToMentions < ActiveRecord::Migration[5.2]
+  include Mastodon::MigrationHelpers
+
+  disable_ddl_transaction!
+
+  def up
+    safety_assured do
+      add_column_with_default(
+        :mentions,
+        :silent,
+        :boolean,
+        allow_null: false,
+        default: false
+      )
+    end
+  end
+
+  def down
+    remove_column :mentions, :silent
+  end
+end
diff --git a/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb b/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb
new file mode 100644
index 000000000..f05d50fcd
--- /dev/null
+++ b/db/migrate/20181017170937_add_reject_reports_to_domain_blocks.rb
@@ -0,0 +1,17 @@
+require Rails.root.join('lib', 'mastodon', 'migration_helpers')
+
+class AddRejectReportsToDomainBlocks < ActiveRecord::Migration[5.2]
+  include Mastodon::MigrationHelpers
+
+  disable_ddl_transaction!
+
+  def up
+    safety_assured do
+      add_column_with_default :domain_blocks, :reject_reports, :boolean, default: false, allow_null: false
+    end
+  end
+
+  def down
+    remove_column :domain_blocks, :reject_reports
+  end
+end
diff --git a/db/migrate/20181018205649_add_unread_to_account_conversations.rb b/db/migrate/20181018205649_add_unread_to_account_conversations.rb
new file mode 100644
index 000000000..3c28b9a64
--- /dev/null
+++ b/db/migrate/20181018205649_add_unread_to_account_conversations.rb
@@ -0,0 +1,23 @@
+require Rails.root.join('lib', 'mastodon', 'migration_helpers')
+
+class AddUnreadToAccountConversations < ActiveRecord::Migration[5.2]
+  include Mastodon::MigrationHelpers
+
+  disable_ddl_transaction!
+
+  def up
+    safety_assured do
+      add_column_with_default(
+        :account_conversations,
+        :unread,
+        :boolean,
+        allow_null: false,
+        default: false
+      )
+    end
+  end
+
+  def down
+    remove_column :account_conversations, :unread, :boolean
+  end
+end
diff --git a/db/migrate/20181024224956_migrate_account_conversations.rb b/db/migrate/20181024224956_migrate_account_conversations.rb
new file mode 100644
index 000000000..47f7375ba
--- /dev/null
+++ b/db/migrate/20181024224956_migrate_account_conversations.rb
@@ -0,0 +1,75 @@
+class MigrateAccountConversations < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    say ''
+    say 'WARNING: This migration may take a *long* time for large instances'
+    say 'It will *not* lock tables for any significant time, but it may run'
+    say 'for a very long time. We will pause for 10 seconds to allow you to'
+    say 'interrupt this migration if you are not ready.'
+    say ''
+
+    10.downto(1) do |i|
+      say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true
+      sleep 1
+    end
+
+    total        = estimate_rows(local_direct_statuses) + estimate_rows(notifications_about_direct_statuses)
+    migrated     = 0
+    started_time = Time.zone.now
+    last_time    = Time.zone.now
+
+    local_direct_statuses.includes(:account, mentions: :account).find_each do |status|
+      AccountConversation.add_status(status.account, status)
+      migrated += 1
+
+      if Time.zone.now - last_time > 1
+        say_progress(migrated, total, started_time)
+        last_time = Time.zone.now
+      end
+    end
+
+    notifications_about_direct_statuses.includes(:account, mention: { status: [:account, mentions: :account] }).find_each do |notification|
+      AccountConversation.add_status(notification.account, notification.target_status)
+      migrated += 1
+
+      if Time.zone.now - last_time > 1
+        say_progress(migrated, total, started_time)
+        last_time = Time.zone.now
+      end
+    end
+  end
+
+  def down
+  end
+
+  private
+
+  def estimate_rows(query)
+    result = exec_query("EXPLAIN #{query.to_sql}").first
+    result['QUERY PLAN'].scan(/ rows=([\d]+)/).first&.first&.to_i || 0
+  end
+
+  def say_progress(migrated, total, started_time)
+    status = "Migrated #{migrated} rows"
+
+    percentage = 100.0 * migrated / total
+    status += " (~#{sprintf('%.2f', percentage)}%, "
+
+    remaining_time = (100.0 - percentage) * (Time.zone.now - started_time) / percentage
+
+    status += "#{(remaining_time / 60).to_i}:"
+    status += sprintf('%02d', remaining_time.to_i % 60)
+    status += ' remaining)'
+
+    say status, true
+  end
+
+  def local_direct_statuses
+    Status.unscoped.local.where(visibility: :direct)
+  end
+
+  def notifications_about_direct_statuses
+    Notification.joins(mention: :status).where(activity_type: 'Mention', statuses: { visibility: :direct })
+  end
+end
diff --git a/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb b/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb
new file mode 100644
index 000000000..bd4f4c2a3
--- /dev/null
+++ b/db/migrate/20181026034033_remove_faux_remote_account_duplicates.rb
@@ -0,0 +1,16 @@
+class RemoveFauxRemoteAccountDuplicates < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    local_domain = Rails.configuration.x.local_domain
+
+    # Just a safety measure to ensure that under no circumstance
+    # we will query `domain IS NULL` because that would return
+    # actually local accounts, the originals
+    return if local_domain.nil?
+
+    Account.where(domain: local_domain).in_batches.destroy_all
+  end
+
+  def down; end
+end
diff --git a/db/schema.rb b/db/schema.rb
index f9019e8cf..9e718615f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2018_10_07_025445) do
+ActiveRecord::Schema.define(version: 2018_10_26_034033) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define(version: 2018_10_07_025445) do
     t.bigint "status_ids", default: [], null: false, array: true
     t.bigint "last_status_id"
     t.integer "lock_version", default: 0, null: false
+    t.boolean "unread", default: false, null: false
     t.index ["account_id", "conversation_id", "participant_account_ids"], name: "index_unique_conversations", unique: true
     t.index ["account_id"], name: "index_account_conversations_on_account_id"
     t.index ["conversation_id"], name: "index_account_conversations_on_conversation_id"
@@ -195,6 +196,7 @@ ActiveRecord::Schema.define(version: 2018_10_07_025445) do
     t.datetime "updated_at", null: false
     t.integer "severity", default: 0
     t.boolean "reject_media", default: false, null: false
+    t.boolean "reject_reports", default: false, null: false
     t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true
   end
 
@@ -311,6 +313,7 @@ ActiveRecord::Schema.define(version: 2018_10_07_025445) do
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
     t.bigint "account_id"
+    t.boolean "silent", default: false, null: false
     t.index ["account_id", "status_id"], name: "index_mentions_on_account_id_and_status_id", unique: true
     t.index ["status_id"], name: "index_mentions_on_status_id"
   end