-
Notifications
You must be signed in to change notification settings - Fork 336
[How to] Use UUIDs
Jay Dorsey edited this page Feb 7, 2019
·
1 revision
In order to use the public_activity gem with tables using UUIDs, you'll need to modify
the *_create_activities.rb
migration file, before running your migrations.
Assuming you want to use UUIDs for the activities table, and are using UUID's for your trackable, owner, and recipient tables, a migration like below should work:
class CreateActivities < (ActiveRecord.version.release() < Gem::Version.new('5.2.0') ? ActiveRecord::Migration : ActiveRecord::Migration[5.2])
def self.up
create_table :activities, id: :uuid, default: 'gen_random_uuid()' do |t|
t.belongs_to :trackable, polymorphic: true, type: :uuid
t.belongs_to :owner, polymorphic: true, type: :uuid
t.string :key
t.text :parameters
t.belongs_to :recipient, polymorphic: true, type: :uuid
t.timestamps
end
add_index :activities, [:trackable_id, :trackable_type]
add_index :activities, [:owner_id, :owner_type]
add_index :activities, [:recipient_id, :recipient_type]
end
def self.down
drop_table :activities
end
end