From 45522a91208907a34cfc4f036d331f73ef2ffaf5 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 21 Dec 2024 13:06:59 +1100 Subject: [PATCH 1/4] update event schema and model --- db/migrate/20240114120424_create_events.rb | 24 ++++++++++++++++------ lib/event.rb | 13 ++++++++---- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/db/migrate/20240114120424_create_events.rb b/db/migrate/20240114120424_create_events.rb index a0545bd..b392150 100644 --- a/db/migrate/20240114120424_create_events.rb +++ b/db/migrate/20240114120424_create_events.rb @@ -4,16 +4,28 @@ def change t.bigint :user_id, null: false t.bigint :tenant_id, null: false - t.text :type, null: false + t.string :type, null: false, limit: 255 + t.send(json_column_type, :body) + t.datetime :created_at, null: false - t.text :eventable_type, null: false + t.string :eventable_type, null: false, limit: 255 t.bigint :eventable_id, null: false + t.index [:eventable_type, :eventable_id] + end + end - t.jsonb :body + private - t.datetime :created_at, null: false + def json_column_type + case ActiveRecord::Base.connection.adapter_name + when /PostgreSQL/ + :jsonb + when /MySQL/, /MariaDB/ + :json + when /SQLite/ + :text + else + :json end - - add_index :events, [:eventable_type, :eventable_id] end end diff --git a/lib/event.rb b/lib/event.rb index 8269f43..9b5b5be 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -1,12 +1,17 @@ class Event < ActiveRecord::Base self.table_name = 'events' + # associations + + belongs_to :eventable, polymorphic: true + # validations - validates :user_id, :tenant_id, presence: true - validates :eventable_type, :eventable_id, presence: true + validates :user_id, presence: true + validates :tenant_id, presence: true - # associations + validates :type, presence: true, length: { maximum: 255 } - belongs_to :eventable, polymorphic: true + validates :eventable_type, presence: true, length: { maximum: 255 }, if: -> { eventable_id.present? } + validates :eventable_id, presence: true, if: -> { eventable_type.present? } end From ee390c3e4a78ed5702ef1c5a2a341cc14db5f73d Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 21 Dec 2024 18:32:32 +1100 Subject: [PATCH 2/4] remove provider specific support --- db/migrate/20240114120424_create_events.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/db/migrate/20240114120424_create_events.rb b/db/migrate/20240114120424_create_events.rb index b392150..b7b82a5 100644 --- a/db/migrate/20240114120424_create_events.rb +++ b/db/migrate/20240114120424_create_events.rb @@ -5,7 +5,7 @@ def change t.bigint :tenant_id, null: false t.string :type, null: false, limit: 255 - t.send(json_column_type, :body) + t.jsonb :body t.datetime :created_at, null: false t.string :eventable_type, null: false, limit: 255 @@ -13,19 +13,4 @@ def change t.index [:eventable_type, :eventable_id] end end - - private - - def json_column_type - case ActiveRecord::Base.connection.adapter_name - when /PostgreSQL/ - :jsonb - when /MySQL/, /MariaDB/ - :json - when /SQLite/ - :text - else - :json - end - end end From 0a592ffde25cb019a0af190df27dc97ed184f045 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 21 Dec 2024 19:22:09 +1100 Subject: [PATCH 3/4] move accountify/ under app/domains --- {lib => app/domains}/accountify/contact.rb | 0 {lib => app/domains}/accountify/error.rb | 0 {lib => app/domains}/accountify/invoice.rb | 0 {lib => app/domains}/accountify/invoice_status_summary.rb | 0 {lib => app/domains}/accountify/models/contact.rb | 0 {lib => app/domains}/accountify/models/invoice.rb | 0 {lib => app/domains}/accountify/models/invoice_status_summary.rb | 0 {lib => app/domains}/accountify/models/organisation.rb | 0 {lib => app/domains}/accountify/not_available.rb | 0 {lib => app/domains}/accountify/not_found.rb | 0 {lib => app/domains}/accountify/organisation.rb | 0 {lib => app/models}/event.rb | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename {lib => app/domains}/accountify/contact.rb (100%) rename {lib => app/domains}/accountify/error.rb (100%) rename {lib => app/domains}/accountify/invoice.rb (100%) rename {lib => app/domains}/accountify/invoice_status_summary.rb (100%) rename {lib => app/domains}/accountify/models/contact.rb (100%) rename {lib => app/domains}/accountify/models/invoice.rb (100%) rename {lib => app/domains}/accountify/models/invoice_status_summary.rb (100%) rename {lib => app/domains}/accountify/models/organisation.rb (100%) rename {lib => app/domains}/accountify/not_available.rb (100%) rename {lib => app/domains}/accountify/not_found.rb (100%) rename {lib => app/domains}/accountify/organisation.rb (100%) rename {lib => app/models}/event.rb (100%) 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/lib/event.rb b/app/models/event.rb similarity index 100% rename from lib/event.rb rename to app/models/event.rb From ff10798a50effb996623a07a3b1037d3fabbdef0 Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sat, 21 Dec 2024 19:25:15 +1100 Subject: [PATCH 4/4] fix word wrap --- app/models/event.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/event.rb b/app/models/event.rb index 9b5b5be..dbc5573 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -12,6 +12,8 @@ class Event < ActiveRecord::Base validates :type, presence: true, length: { maximum: 255 } - validates :eventable_type, presence: true, length: { maximum: 255 }, if: -> { eventable_id.present? } + validates :eventable_type, presence: true, length: { maximum: 255 }, + if: -> { eventable_id.present? } + validates :eventable_id, presence: true, if: -> { eventable_type.present? } end