about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-03-07 09:36:47 +0100
committerGitHub <noreply@github.com>2022-03-07 09:36:47 +0100
commitedf09ec747ebba5a170e27eb13663462a116ec6c (patch)
treed8e6c66a345369d21af075e6102382c846a5f248 /db
parentc439e13e1231acd763b38ea6287b60edf51cadc8 (diff)
Add `/api/v1/accounts/familiar_followers` to REST API (#17700)
* Add `/api/v1/accounts/familiar_followers` to REST API

* Change hide network preference to be stored consistently for local and remote accounts

* Add dummy classes to migration

* Apply suggestions from code review

Co-authored-by: Claire <claire.github-309c@sitedethib.com>

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20220304195405_migrate_hide_network_preference.rb37
-rw-r--r--db/schema.rb2
2 files changed, 38 insertions, 1 deletions
diff --git a/db/migrate/20220304195405_migrate_hide_network_preference.rb b/db/migrate/20220304195405_migrate_hide_network_preference.rb
new file mode 100644
index 000000000..102ee46d6
--- /dev/null
+++ b/db/migrate/20220304195405_migrate_hide_network_preference.rb
@@ -0,0 +1,37 @@
+class MigrateHideNetworkPreference < ActiveRecord::Migration[6.1]
+  disable_ddl_transaction!
+
+  # Dummy classes, to make migration possible across version changes
+  class Account < ApplicationRecord
+    has_one :user, inverse_of: :account
+    scope :local, -> { where(domain: nil) }
+  end
+
+  class User < ApplicationRecord
+    belongs_to :account
+  end
+
+  def up
+    Account.reset_column_information
+
+    Setting.unscoped.where(thing_type: 'User', var: 'hide_network').find_each do |setting|
+      account = User.find(setting.thing_id).account
+
+      ApplicationRecord.transaction do
+        account.update(hide_collections: setting.value)
+        setting.delete
+      end
+    rescue ActiveRecord::RecordNotFound
+      next
+    end
+  end
+
+  def down
+    Account.local.where(hide_collections: true).includes(:user).find_each do |account|
+      ApplicationRecord.transaction do
+        Setting.create(thing_type: 'User', thing_id: account.user.id, var: 'hide_network', value: account.hide_collections?)
+        account.update(hide_collections: nil)
+      end
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 756e5e9ab..3666804ee 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: 2022_02_27_041951) do
+ActiveRecord::Schema.define(version: 2022_03_04_195405) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"