about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-09-20 03:37:04 -0500
committerFire Demon <firedemon@creature.cafe>2020-09-20 04:39:27 -0500
commit69473c4fbec7775cae2badfeb16990aa0e9e85a4 (patch)
tree9929bde90cc38cf8ab3398faf29fd2c865f5f26c /db
parentd95c3cb550bbbc44c22bce5ef758f0c2d502bbeb (diff)
[Feature] Community-managed custom emoji
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20200919234917_add_account_to_custom_emoji.rb7
-rw-r--r--db/migrate/20200920084007_backfill_custom_emoji_ownership.rb12
-rw-r--r--db/schema.rb5
3 files changed, 23 insertions, 1 deletions
diff --git a/db/migrate/20200919234917_add_account_to_custom_emoji.rb b/db/migrate/20200919234917_add_account_to_custom_emoji.rb
new file mode 100644
index 000000000..b4466ee30
--- /dev/null
+++ b/db/migrate/20200919234917_add_account_to_custom_emoji.rb
@@ -0,0 +1,7 @@
+class AddAccountToCustomEmoji < ActiveRecord::Migration[5.2]
+  def change
+    safety_assured do
+      add_reference :custom_emojis, :account, foreign_key: { on_delete: :nullify }, index: true
+    end
+  end
+end
diff --git a/db/migrate/20200920084007_backfill_custom_emoji_ownership.rb b/db/migrate/20200920084007_backfill_custom_emoji_ownership.rb
new file mode 100644
index 000000000..1542bdb5e
--- /dev/null
+++ b/db/migrate/20200920084007_backfill_custom_emoji_ownership.rb
@@ -0,0 +1,12 @@
+class BackfillCustomEmojiOwnership < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    site_contact = Account.site_contact
+    CustomEmoji.local.in_batches.update_all(account_id: site_contact.id)
+  end
+
+  def down
+    nil
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index fbcf8e636..eb0605314 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: 2020_09_07_195410) do
+ActiveRecord::Schema.define(version: 2020_09_20_084007) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -357,6 +357,8 @@ ActiveRecord::Schema.define(version: 2020_09_07_195410) do
     t.boolean "visible_in_picker", default: true, null: false
     t.bigint "category_id"
     t.integer "image_storage_schema_version"
+    t.bigint "account_id"
+    t.index ["account_id"], name: "index_custom_emojis_on_account_id"
     t.index ["shortcode", "domain"], name: "index_custom_emojis_on_shortcode_and_domain", unique: true
   end
 
@@ -1069,6 +1071,7 @@ ActiveRecord::Schema.define(version: 2020_09_07_195410) do
   add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
   add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
   add_foreign_key "conversations", "accounts"
+  add_foreign_key "custom_emojis", "accounts", on_delete: :nullify
   add_foreign_key "custom_filters", "accounts", on_delete: :cascade
   add_foreign_key "devices", "accounts", on_delete: :cascade
   add_foreign_key "devices", "oauth_access_tokens", column: "access_token_id", on_delete: :cascade