20170105224407_add_shortcode_to_media_attachments.rb 665 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. class AddShortcodeToMediaAttachments < ActiveRecord::Migration[5.0]
  3. class MigrationMediaAttachment < ApplicationRecord
  4. self.table_name = :media_attachments
  5. scope :local, -> { where(remote_url: '') }
  6. end
  7. def up
  8. add_column :media_attachments, :shortcode, :string, null: true, default: nil
  9. add_index :media_attachments, :shortcode, unique: true
  10. MigrationMediaAttachment.reset_column_information
  11. # Migrate old links
  12. MigrationMediaAttachment.local.update_all('shortcode = id')
  13. end
  14. def down
  15. remove_index :media_attachments, :shortcode
  16. remove_column :media_attachments, :shortcode
  17. end
  18. end