From 6ca9b0f1e1337204b7b756eed83414c564f97b98 Mon Sep 17 00:00:00 2001 From: diti Date: Thu, 5 Mar 2026 12:18:25 +0100 Subject: [PATCH 1/3] Add started_at/ended_at datetime fields to Banner --- app/helpers/application_helper.rb | 3 ++- app/models/banner.rb | 7 +++++++ db/migrate/20260305105227_add_timeto_banner.rb | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20260305105227_add_timeto_banner.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0bd3bdb0f..be5507ecf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -25,7 +25,7 @@ def today def display_banner # Cache banners to avoid repeated queries during page render - @banners ||= Banner.published.select("id, content").to_a + @banners ||= Banner.active.select("id, content").to_a return if @banners.empty? safe_content_array = @banners.map { |banner| @@ -41,6 +41,7 @@ def display_banner content_tag(:div, id: "banner-news", class: "bg-yellow-200 text-black text-center px-4 py-2") do content_tag(:div, safe_content.html_safe, class: "font-medium") end + end def sortable_field_display_name(name) diff --git a/app/models/banner.rb b/app/models/banner.rb index 592d7ae41..32b5720c2 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -12,4 +12,11 @@ class Banner < ApplicationRecord def name content.truncate(50) end + + scope :active, -> { + where(show: true) + .where('started_at IS NULL OR started_at <= ?', Time.current) + .where('ended_at IS NULL OR ended_at >= ?', Time.current) + } + end diff --git a/db/migrate/20260305105227_add_timeto_banner.rb b/db/migrate/20260305105227_add_timeto_banner.rb new file mode 100644 index 000000000..627ea1350 --- /dev/null +++ b/db/migrate/20260305105227_add_timeto_banner.rb @@ -0,0 +1,6 @@ +class AddTimetoBanner < ActiveRecord::Migration[8.1] + def change + add_column :banners, :started_at, :datetime + add_column :banners, :ended_at, :datetime + end +end From eed9b40f30c4f1cc3d15cec2e963f61986ed012e Mon Sep 17 00:00:00 2001 From: diti Date: Thu, 5 Mar 2026 12:28:20 +0100 Subject: [PATCH 2/3] rubocop --- app/helpers/application_helper.rb | 1 - app/models/banner.rb | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index be5507ecf..57a5a8800 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -41,7 +41,6 @@ def display_banner content_tag(:div, id: "banner-news", class: "bg-yellow-200 text-black text-center px-4 py-2") do content_tag(:div, safe_content.html_safe, class: "font-medium") end - end def sortable_field_display_name(name) diff --git a/app/models/banner.rb b/app/models/banner.rb index 32b5720c2..c54e993f8 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -13,10 +13,9 @@ def name content.truncate(50) end - scope :active, -> { - where(show: true) - .where('started_at IS NULL OR started_at <= ?', Time.current) - .where('ended_at IS NULL OR ended_at >= ?', Time.current) - } - + scope :active, -> { + where(show: true) + .where("started_at IS NULL OR started_at <= ?", Time.current) + .where("ended_at IS NULL OR ended_at >= ?", Time.current) + } end From 0b55e105798a563260146ef5c08a1221fb7192a8 Mon Sep 17 00:00:00 2001 From: diti Date: Thu, 5 Mar 2026 12:32:19 +0100 Subject: [PATCH 3/3] Update schema with banner timestamps --- db/schema.rb | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 3014b674b..e9f594472 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -134,7 +134,7 @@ create_table "ahoy_events", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name" - t.json "properties" + t.text "properties" t.bigint "resource_id" t.string "resource_type" t.datetime "time" @@ -210,11 +210,21 @@ end create_table "banners", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| +<<<<<<< HEAD t.text "content" t.datetime "created_at", precision: nil, null: false t.integer "created_by_id" t.boolean "published", default: false, null: false t.boolean "show" +======= + t.text "content", size: :medium + t.datetime "created_at", precision: nil, null: false + t.integer "created_by_id" + t.datetime "ended_at" + t.boolean "published", default: false, null: false + t.boolean "show" + t.datetime "started_at" +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.datetime "updated_at", precision: nil, null: false t.integer "updated_by_id" t.index ["created_by_id"], name: "index_banners_on_created_by_id" @@ -223,7 +233,7 @@ end create_table "blazer_audits", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| - t.timestamp "created_at", null: false + t.timestamp "created_at", default: -> { "current_timestamp() ON UPDATE current_timestamp()" }, null: false t.string "data_source" t.bigint "query_id" t.text "statement" @@ -451,7 +461,11 @@ t.integer "cost_cents" t.datetime "created_at", null: false t.integer "created_by_id" +<<<<<<< HEAD t.text "description" +======= + t.text "description", size: :medium +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.datetime "end_date", precision: nil t.boolean "featured", default: false, null: false t.boolean "inactive", default: true, null: false @@ -474,7 +488,11 @@ end create_table "faqs", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| +<<<<<<< HEAD t.text "answer", size: :medium +======= + t.text "answer", size: :long +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.datetime "created_at", precision: nil, null: false t.boolean "inactive" t.integer "position", null: false @@ -496,7 +514,11 @@ create_table "form_builders", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.datetime "created_at", precision: nil, null: false +<<<<<<< HEAD t.text "description", size: :medium +======= + t.text "description", size: :long +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.string "name" t.integer "owner_type" t.datetime "updated_at", precision: nil, null: false @@ -652,7 +674,11 @@ t.integer "location_id" t.string "mission_vision_values" t.string "name" +<<<<<<< HEAD t.text "notes", size: :medium +======= + t.text "notes", size: :long +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.integer "organization_status_id" t.boolean "profile_show_description", default: true, null: false t.boolean "profile_show_email", default: true, null: false @@ -686,7 +712,7 @@ t.string "payment_type", default: "stripe", null: false t.string "status", null: false t.string "stripe_charge_id" - t.json "stripe_metadata" + t.text "stripe_metadata", size: :long, collation: "utf8mb4_bin" t.string "stripe_payment_intent_id" t.datetime "updated_at", null: false t.index ["event_id"], name: "index_payments_on_event_id" @@ -697,6 +723,7 @@ t.index ["payer_type", "payer_id"], name: "index_payments_on_payer_type_and_payer_id" t.index ["stripe_charge_id"], name: "index_payments_on_stripe_charge_id" t.index ["stripe_payment_intent_id"], name: "index_payments_on_stripe_payment_intent_id", unique: true + t.check_constraint "json_valid(`stripe_metadata`)", name: "stripe_metadata" end create_table "people", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| @@ -926,7 +953,11 @@ create_table "story_ideas", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "author_credit_preference" +<<<<<<< HEAD t.text "body" +======= + t.text "body", size: :medium +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.datetime "created_at", null: false t.integer "created_by_id", null: false t.string "external_workshop_title" @@ -945,10 +976,33 @@ t.index ["workshop_id"], name: "index_story_ideas_on_workshop_id" end +<<<<<<< HEAD create_table "user_form_form_fields", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.datetime "created_at", precision: nil, null: false t.integer "form_field_id" t.text "text", size: :medium +======= + create_table "tutorials", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| + t.text "body" + t.datetime "created_at", null: false + t.boolean "featured", default: false, null: false + t.integer "position", default: 10, null: false + t.boolean "publicly_featured", default: false, null: false + t.boolean "publicly_visible", default: false, null: false + t.boolean "published", default: false, null: false + t.string "title" + t.datetime "updated_at", null: false + t.string "youtube_url" + t.index ["featured"], name: "index_tutorials_on_featured" + t.index ["published"], name: "index_tutorials_on_published" + t.index ["title"], name: "index_tutorials_on_title" + end + + create_table "user_form_form_fields", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| + t.datetime "created_at", precision: nil, null: false + t.integer "form_field_id" + t.text "text", size: :long +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.datetime "updated_at", precision: nil, null: false t.integer "user_form_id" t.index ["form_field_id"], name: "index_user_form_form_fields_on_form_field_id" @@ -1118,10 +1172,17 @@ t.integer "time_opening" t.integer "time_opening_circle" t.integer "time_warm_up" +<<<<<<< HEAD t.text "timeframe" t.text "timeframe_spanish" t.text "tips" t.text "tips_spanish" +======= + t.text "timeframe", size: :medium + t.text "timeframe_spanish", size: :medium + t.text "tips", size: :medium + t.text "tips_spanish", size: :medium +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.string "title" t.datetime "updated_at", null: false t.integer "updated_by_id", null: false @@ -1220,14 +1281,20 @@ t.boolean "published", default: false, null: false t.datetime "updated_at", precision: nil, null: false t.integer "variation_id" +<<<<<<< HEAD t.integer "windows_type_id" +======= +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.integer "workshop_id" t.bigint "workshop_variation_idea_id" t.string "youtube_url" t.index ["created_by_id"], name: "index_workshop_variations_on_created_by_id" t.index ["organization_id"], name: "index_workshop_variations_on_organization_id" t.index ["published"], name: "index_workshop_variations_on_published" +<<<<<<< HEAD t.index ["windows_type_id"], name: "index_workshop_variations_on_windows_type_id" +======= +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.index ["workshop_id"], name: "index_workshop_variations_on_workshop_id" t.index ["workshop_variation_idea_id"], name: "index_workshop_variations_on_workshop_variation_idea_id" end @@ -1302,11 +1369,19 @@ t.integer "time_opening" t.integer "time_opening_circle" t.integer "time_warm_up" +<<<<<<< HEAD t.text "timeframe", size: :medium t.text "timeframe_spanish", size: :medium t.text "timestamps", size: :medium t.text "tips", size: :medium t.text "tips_spanish", size: :medium +======= + t.text "timeframe", size: :long + t.text "timeframe_spanish", size: :long + t.text "timestamps", size: :long + t.text "tips", size: :long + t.text "tips_spanish", size: :long +>>>>>>> 6515dbbee (Update schema with banner timestamps) t.string "title" t.datetime "updated_at", precision: nil, null: false t.text "visualization", size: :medium