From f944e731b69221a559c51a079f7beec53230b071 Mon Sep 17 00:00:00 2001 From: Klaus Zanders Date: Wed, 20 Nov 2024 17:46:37 +0100 Subject: [PATCH] Update tableless models to not rely on fake schema loading --- app/models/action.rb | 8 ++++---- app/models/capability.rb | 6 +++--- app/models/concerns/tableless.rb | 20 ++++---------------- app/models/day.rb | 6 +++--- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/app/models/action.rb b/app/models/action.rb index 0ae3927bf26d..2d5e121340e2 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -34,8 +34,8 @@ class Action < ApplicationRecord default_scope { default } - attribute :id, :text, default: nil - attribute :permission, :text, default: nil - attribute :global, :boolean, default: false - attribute :module, :text, default: false + define_attribute :id, ActiveRecord::Type.lookup(:text), default: nil + define_attribute :permission, ActiveRecord::Type.lookup(:text), default: nil + define_attribute :global, ActiveRecord::Type.lookup(:boolean), default: false + define_attribute :module, ActiveRecord::Type.lookup(:text), default: false end diff --git a/app/models/capability.rb b/app/models/capability.rb index 1d7c9729835e..a163cd6044a6 100644 --- a/app/models/capability.rb +++ b/app/models/capability.rb @@ -37,7 +37,7 @@ class Capability < ApplicationRecord belongs_to :context, class_name: "Project" belongs_to :principal - attribute :action, :text, default: nil - attribute :context_id, :integer, default: nil - attribute :principal_id, :integer, default: nil + define_attribute :action, ActiveRecord::Type.lookup(:text), default: nil + define_attribute :context_id, ActiveRecord::Type.lookup(:integer), default: nil + define_attribute :principal_id, ActiveRecord::Type.lookup(:integer), default: nil end diff --git a/app/models/concerns/tableless.rb b/app/models/concerns/tableless.rb index 70224951bac9..236497e6e47b 100644 --- a/app/models/concerns/tableless.rb +++ b/app/models/concerns/tableless.rb @@ -38,24 +38,12 @@ def readonly? end class_methods do - def attribute_names - @attribute_names ||= attribute_types.keys - end - def load_schema! - @columns_hash ||= Hash.new - - # From active_record/attributes.rb - attributes_to_define_after_schema_loads.each do |name, (type, default)| - if type.is_a?(Symbol) - type = ActiveRecord::Type.lookup(type, default) - end - - define_attribute(name, type, default:) + # noop + end - # Improve Model#inspect output - @columns_hash[name.to_s] = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default) - end + def columns_hash + @columns_hash ||= {} end end end diff --git a/app/models/day.rb b/app/models/day.rb index 6c006389c79a..a182b8836db9 100644 --- a/app/models/day.rb +++ b/app/models/day.rb @@ -36,9 +36,9 @@ class Day < ApplicationRecord primary_key: :date, dependent: nil - attribute :date, :date, default: nil - attribute :day_of_week, :integer, default: nil - attribute :working, :boolean, default: "t" + define_attribute :date, ActiveRecord::Type.lookup(:date), default: nil + define_attribute :day_of_week, ActiveRecord::Type.lookup(:integer), default: nil + define_attribute :working, ActiveRecord::Type.lookup(:boolean), default: "t" delegate :name, to: :week_day, allow_nil: true