Assumption : Rails v6+, Postgres v9.1+, UUIDs

So you follow the Active Storage installation guide.  Here.

And it just works.  Yay!

But then you realise.  Those table ID columns are all auto increment integers.  Boo!

So how to resolve this?

Turns out's it's prety simple - but only if you make the fix as you install Active Storage.  If you've already installed Active Storage and run the database migrations then I think you'll have a job on your hands to revise the schema for UUIDs.

Implement Active Storage + UUIDs

It's all pretty simple and some might say not even worth a blog post.  The solution is to manually adjust the database migration files that are generated as part of the Active Storage installation process.  It's really not rocket science.

Install Active Storage and generate the database migrations.

rails active_storage:install

These are the vanilla migrations.

  def change
    create_table :active_storage_blobs do |t|
      t.string   :key,        null: false
      t.string   :filename,   null: false
      t.string   :content_type
      t.text     :metadata
      t.bigint   :byte_size,  null: false
      t.string   :checksum,   null: false
      t.datetime :created_at, null: false

      t.index [ :key ], unique: true
    end

    create_table :active_storage_attachments do |t|
      t.string     :name,     null: false
      t.references :record,   null: false, polymorphic: true, index: false
      t.references :blob,     null: false
      t.datetime :created_at, null: false

      t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
      
      t.foreign_key :active_storage_blobs, column: :blob_id
    end
  end
end

Of course over time these migration files will change slightly, as new versions of Active Storage are released.  So be aware that you might need to make some minor adjustments to what I've detailed below - if you do, let me know and I'll update this post.

And this are the migrations you need.

  def change
    create_table :active_storage_blobs, id: :uuid do |t|
      t.string   :key,        null: false
      t.string   :filename,   null: false
      t.string   :content_type
      t.text     :metadata
      t.bigint   :byte_size,  null: false
      t.string   :checksum,   null: false
      t.datetime :created_at, null: false
  
      t.index [ :key ], unique: true
    end
  
    create_table :active_storage_attachments, id: :uuid do |t|
      t.string :name, null: false
      t.references :record, type: :uuid, null: false, polymorphic: true, index: false
      t.references :blob, type: :uuid, null: false
      t.datetime :created_at, null: false
  
      t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
      
      t.foreign_key :active_storage_blobs, column: :blob_id
    end
  end
end

Once you've updated the migrations.

rails db:migrate

Rails guides - Active Storage : https://guides.rubyonrails.org/active_storage_overview.html