Module: FileBlobs::ActiveRecordMigrationExtensions

Defined in:
lib/file_blobs_rails/active_record_migration_extensions.rb

Overview

Module mixed into ActiveRecord::Migration.

Instance Method Summary collapse

Instance Method Details

#create_file_blobs_table(table_name = :file_blobs, options = {}, &block) ⇒ Object

Creates the table used to hold file blobs.

Parameters:

  • table_name (Symbol) (defaults to: :file_blobs)

    the name of the table used to hold file data

  • options (Hash<Symbol, Object>) (defaults to: {})

Options Hash (options):

  • blob_limit (Integer)

    the maximum file size that can be stored in the table; defaults to 1 megabyte



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/file_blobs_rails/active_record_migration_extensions.rb', line 13

def create_file_blobs_table(table_name = :file_blobs, options = {}, &block)
  blob_limit = options[:blob_limit] || 1.megabyte

  create_table table_name, id: false do |t|
    t.primary_key :id, :string, null: false, limit: 48
    t.binary :data, null: false, limit: blob_limit

    # Block capturing and calling is a bit slower than using yield. This is
    # not a concern because migrations aren't run in tight loops.
    block.call t
  end
end