Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Event < ActiveRecord::Base
self.table_name = 'events'

# associations

belongs_to :eventable, polymorphic: true

# validations

validates :user_id, presence: true
validates :tenant_id, presence: true

validates :type, presence: true, length: { maximum: 255 }

validates :eventable_type, presence: true, length: { maximum: 255 },
if: -> { eventable_id.present? }

validates :eventable_id, presence: true, if: -> { eventable_type.present? }
end
13 changes: 5 additions & 8 deletions db/migrate/20240114120424_create_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ def change
t.bigint :user_id, null: false
t.bigint :tenant_id, null: false

t.text :type, null: false

t.text :eventable_type, null: false
t.bigint :eventable_id, null: false

t.string :type, null: false, limit: 255
t.jsonb :body

t.datetime :created_at, null: false
end

add_index :events, [:eventable_type, :eventable_id]
t.string :eventable_type, null: false, limit: 255
t.bigint :eventable_id, null: false
t.index [:eventable_type, :eventable_id]
end
end
end
12 changes: 0 additions & 12 deletions lib/event.rb

This file was deleted.

Loading