Sha256: 3bd38e73aebfeb20b444a8c33cb38523f7a12144cff34857bda04fca4265ba45

Contents?: true

Size: 955 Bytes

Versions: 5

Compression:

Stored size: 955 Bytes

Contents

class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
  def change
    # Use Active Record's configured type for primary key
    create_table :active_storage_variant_records, id: primary_key_type do |t|
      t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
      t.string :variation_digest, null: false

      t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
      t.foreign_key :active_storage_blobs, column: :blob_id
    end
  end

  private
    def primary_key_type
      config = Rails.configuration.generators
      config.options[config.orm][:primary_key_type] || :primary_key
    end

    def blobs_primary_key_type
      pkey_name = connection.primary_key(:active_storage_blobs)
      pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
      pkey_column.bigint? ? :bigint : pkey_column.type
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activestorage-7.0.0.rc3 db/update_migrate/20191206030411_create_active_storage_variant_records.rb
activestorage-7.0.0.rc2 db/update_migrate/20191206030411_create_active_storage_variant_records.rb
activestorage-7.0.0.rc1 db/update_migrate/20191206030411_create_active_storage_variant_records.rb
activestorage-7.0.0.alpha2 db/update_migrate/20191206030411_create_active_storage_variant_records.rb
activestorage-7.0.0.alpha1 db/update_migrate/20191206030411_create_active_storage_variant_records.rb