about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-06 00:21:12 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-06 00:29:12 +0100
commit7b9f8766e88dceb9519085deada3fa673e4c015b (patch)
treea8d70a85796fe1e8027ad77ca1a84fe69caf9cef /db/migrate
parent9f21eb6064c6cdc2bc8606e5d18173655797c233 (diff)
Fix #416 - Generate random unique 14-byte (19 characters) shortcodes
for local attachments, use them in URLs. Check status privacy
before redirecting to actual file.
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20170105224407_add_shortcode_to_media_attachments.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb b/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb
new file mode 100644
index 000000000..2685ae150
--- /dev/null
+++ b/db/migrate/20170105224407_add_shortcode_to_media_attachments.rb
@@ -0,0 +1,14 @@
+class AddShortcodeToMediaAttachments < ActiveRecord::Migration[5.0]
+  def up
+    add_column :media_attachments, :shortcode, :string, null: true, default: nil
+    add_index :media_attachments, :shortcode, unique: true
+
+    # Migrate old links
+    MediaAttachment.local.update_all('shortcode = id')
+  end
+
+  def down
+  	remove_index :media_attachments, :shortcode
+  	remove_column :media_attachments, :shortcode
+  end
+end