diff --git a/migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql b/migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql new file mode 100644 index 00000000..0f62cea5 --- /dev/null +++ b/migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql @@ -0,0 +1,9 @@ +-- +micrate Up +-- SQL in section 'Up' is executed when this migration is applied + +ALTER TABLE "sys" ADD COLUMN IF NOT EXISTS space_config JSONB NOT NULL DEFAULT '{}'::jsonb; + +-- +micrate Down +-- SQL section 'Down' is executed when this migration is rolled back + +ALTER TABLE "sys" DROP COLUMN IF EXISTS space_config; \ No newline at end of file diff --git a/spec/control_system_spec.cr b/spec/control_system_spec.cr index 3c7f7aae..c9563eff 100644 --- a/spec/control_system_spec.cr +++ b/spec/control_system_spec.cr @@ -115,6 +115,23 @@ module PlaceOS::Model ids = data.map { |d| JSON.parse(d).as_h["id"].to_s } ids.sort.should eq zone_ids.sort end + + it "#space_config" do + cs = Generator.control_system.save! + space_config = {} of String => (String | Int32 | Int64 | Float64 | Bool | Nil) + space_config["enabled"] = false + space_config["allow_recurrence_bookings"] = "disabled" + space_config["threshold"] = 0.25 + space_config["temp"] = 50 + space_config["i64"] = 20_i64 + space_config["none"] = nil + cs.space_config = JSON.parse(space_config.to_json).as_h + cs.save + + cs.space_config["enabled"].should be_false + cs.space_config["allow_recurrence_bookings"].should eq("disabled") + cs.space_config["threshold"].should eq 0.25 + end end describe "validation" do diff --git a/src/placeos-models/control_system.cr b/src/placeos-models/control_system.cr index e8cf0b88..2f770aa1 100644 --- a/src/placeos-models/control_system.cr +++ b/src/placeos-models/control_system.cr @@ -73,6 +73,8 @@ module PlaceOS::Model attribute signage_last_seen : Time = -> { 5.hours.ago }, converter: PlaceOS::Model::Timestamps::EpochConverter, type: "integer", format: "Int64", mass_assignment: false belongs_to Playlist::Item, foreign_key: "playlist_item_id" + attribute space_config : Hash(String, JSON::Any) = {} of String => JSON::Any + def update_last_seen_time(item_id : String? = nil) system_id = self.id.as(String)