20170901141119_truncate_preview_cards.rb 1.1 KB

123456789101112131415161718192021222324252627282930
  1. class TruncatePreviewCards < ActiveRecord::Migration[5.1]
  2. def up
  3. rename_table :preview_cards, :deprecated_preview_cards
  4. create_table :preview_cards do |t|
  5. t.string :url, default: '', null: false, index: { unique: true }
  6. t.string :title, default: '', null: false
  7. t.string :description, default: '', null: false
  8. t.attachment :image
  9. t.integer :type, default: 0, null: false
  10. t.text :html, default: '', null: false
  11. t.string :author_name, default: '', null: false
  12. t.string :author_url, default: '', null: false
  13. t.string :provider_name, default: '', null: false
  14. t.string :provider_url, default: '', null: false
  15. t.integer :width, default: 0, null: false
  16. t.integer :height, default: 0, null: false
  17. t.timestamps
  18. end
  19. end
  20. def down
  21. if ActiveRecord::Base.connection.table_exists? 'deprecated_preview_cards'
  22. drop_table :preview_cards
  23. rename_table :deprecated_preview_cards, :preview_cards
  24. else
  25. raise ActiveRecord::IrreversibleMigration, 'Previous preview cards table has already been removed'
  26. end
  27. end
  28. end