2023-07-12 07:47:08 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-04 21:17:10 +00:00
|
|
|
class AddTypeToMediaAttachments < ActiveRecord::Migration[5.0]
|
2023-08-09 09:26:42 +00:00
|
|
|
class MigrationMediaAttachment < ApplicationRecord
|
|
|
|
self.table_name = :media_attachments
|
|
|
|
enum type: [:image, :gifv, :video]
|
|
|
|
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'].freeze
|
|
|
|
VIDEO_MIME_TYPES = ['video/webm', 'video/mp4'].freeze
|
|
|
|
end
|
|
|
|
|
2017-03-04 21:17:10 +00:00
|
|
|
def up
|
|
|
|
add_column :media_attachments, :type, :integer, default: 0, null: false
|
|
|
|
|
2023-08-09 09:26:42 +00:00
|
|
|
MigrationMediaAttachment.reset_column_information
|
|
|
|
|
|
|
|
MigrationMediaAttachment
|
|
|
|
.where(file_content_type: MigrationMediaAttachment::IMAGE_MIME_TYPES)
|
|
|
|
.update_all(type: MigrationMediaAttachment.types[:image])
|
|
|
|
MigrationMediaAttachment
|
|
|
|
.where(file_content_type: MigrationMediaAttachment::VIDEO_MIME_TYPES)
|
|
|
|
.update_all(type: MigrationMediaAttachment.types[:video])
|
2017-03-04 21:17:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
remove_column :media_attachments, :type
|
|
|
|
end
|
|
|
|
end
|