diff --git a/lib/accountify/contact.rb b/app/domains/accountify/contact.rb similarity index 100% rename from lib/accountify/contact.rb rename to app/domains/accountify/contact.rb diff --git a/lib/accountify/error.rb b/app/domains/accountify/error.rb similarity index 100% rename from lib/accountify/error.rb rename to app/domains/accountify/error.rb diff --git a/lib/accountify/invoice.rb b/app/domains/accountify/invoice.rb similarity index 100% rename from lib/accountify/invoice.rb rename to app/domains/accountify/invoice.rb diff --git a/lib/accountify/invoice_status_summary.rb b/app/domains/accountify/invoice_status_summary.rb similarity index 100% rename from lib/accountify/invoice_status_summary.rb rename to app/domains/accountify/invoice_status_summary.rb diff --git a/lib/accountify/models/contact.rb b/app/domains/accountify/models/contact.rb similarity index 100% rename from lib/accountify/models/contact.rb rename to app/domains/accountify/models/contact.rb diff --git a/lib/accountify/models/invoice.rb b/app/domains/accountify/models/invoice.rb similarity index 100% rename from lib/accountify/models/invoice.rb rename to app/domains/accountify/models/invoice.rb diff --git a/lib/accountify/models/invoice_status_summary.rb b/app/domains/accountify/models/invoice_status_summary.rb similarity index 100% rename from lib/accountify/models/invoice_status_summary.rb rename to app/domains/accountify/models/invoice_status_summary.rb diff --git a/lib/accountify/models/organisation.rb b/app/domains/accountify/models/organisation.rb similarity index 100% rename from lib/accountify/models/organisation.rb rename to app/domains/accountify/models/organisation.rb diff --git a/lib/accountify/not_available.rb b/app/domains/accountify/not_available.rb similarity index 100% rename from lib/accountify/not_available.rb rename to app/domains/accountify/not_available.rb diff --git a/lib/accountify/not_found.rb b/app/domains/accountify/not_found.rb similarity index 100% rename from lib/accountify/not_found.rb rename to app/domains/accountify/not_found.rb diff --git a/lib/accountify/organisation.rb b/app/domains/accountify/organisation.rb similarity index 100% rename from lib/accountify/organisation.rb rename to app/domains/accountify/organisation.rb diff --git a/app/models/event.rb b/app/models/event.rb new file mode 100644 index 0000000..dbc5573 --- /dev/null +++ b/app/models/event.rb @@ -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 diff --git a/db/migrate/20240114120424_create_events.rb b/db/migrate/20240114120424_create_events.rb index a0545bd..b7b82a5 100644 --- a/db/migrate/20240114120424_create_events.rb +++ b/db/migrate/20240114120424_create_events.rb @@ -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 diff --git a/lib/event.rb b/lib/event.rb deleted file mode 100644 index 8269f43..0000000 --- a/lib/event.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Event < ActiveRecord::Base - self.table_name = 'events' - - # validations - - validates :user_id, :tenant_id, presence: true - validates :eventable_type, :eventable_id, presence: true - - # associations - - belongs_to :eventable, polymorphic: true -end