jumbotron 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70b7fd9c8a5076c1337d2a6cf9e02016fd6cfa28ec64c9cc0a57c82ff3892698
4
- data.tar.gz: 5051beb14f8770e109f382abd0729952446ecd40a50fbd143ac4e5b5746800b0
3
+ metadata.gz: 31fa4d11ab93d13b5e6db4ab799f05f69b6153067ceb0894677e07bd785c27a3
4
+ data.tar.gz: 2f660fdbdf85bb67f9212c6c8c55b6bc9f49a2699c643070a5496946d8894259
5
5
  SHA512:
6
- metadata.gz: c684624b00cded82fb1e274b793a5e0c7cca6d0720589192def2ea53357ce933d631e59373728bfb3052343706df6684ddfd082482100aef79160a65fb8b9dbf
7
- data.tar.gz: 72f5a0934b87a9008e6fc782b377ac166f762119504f646bcf4d964892475c2df66871a3222bdf81c20a8eaba264f3e5c519bbbfc5bf4acd1396ac95a94d308c
6
+ metadata.gz: ee10748cd68f85baa4c3774ef6f7fbcd4c6376f76927a442a8e4ce1b4e28e34c56f7c6355af29545ba1306f7367e37499a56dbdb00f990e413aea020cf37079e
7
+ data.tar.gz: 30e89a701a8dc935ac6d0d4aeffc61d982b6a800d97f86ac43035a23d4ac480bd60485c6c8e96093eaef022b128693ccf0b663b63716dab53385bce0e79ea174
@@ -4,6 +4,12 @@ module Jumbotron
4
4
  class HistoricalChange < ApplicationRecord
5
5
  belongs_to :observation_batch, inverse_of: :historical_changes
6
6
 
7
+ # Force JSON attribute types so writes are JSON.generate'd on every adapter.
8
+ # MariaDB stores t.json as LONGTEXT + json_valid CHECK; without :json, AR
9
+ # persists Ruby #inspect and discovery/evidence writes fail CheckViolation.
10
+ attribute :previous_value, :json
11
+ attribute :new_value, :json
12
+
7
13
  validates :subject_type, :subject_id, :attribute_name, :observed_at, :provider, presence: true
8
14
  end
9
15
  end
@@ -9,6 +9,8 @@ module Jumbotron
9
9
  inverse_of: :observation_batch,
10
10
  dependent: :restrict_with_exception
11
11
 
12
+ attribute :metadata, :json, default: -> { {} }
13
+
12
14
  validates :provider, :adapter_scope, :observed_at, presence: true
13
15
  end
14
16
  end
@@ -19,7 +19,7 @@ module Jumbotron
19
19
  :season_phase,
20
20
  :kind
21
21
  )
22
- Team = Data.define(:id, :name)
22
+ Team = Data.define(:id, :name, :key)
23
23
  Venue = Data.define(:id, :name)
24
24
  Participant = Data.define(:role, :score, :result, :team)
25
25
  GameSegment = Data.define(:kind, :number)
@@ -7,5 +7,16 @@ module Jumbotron
7
7
  has_many :provider_identities, as: :target, inverse_of: :target, dependent: :restrict_with_exception
8
8
 
9
9
  validates :name, presence: true
10
+ validates :key, presence: true, uniqueness: true
11
+ validate :key_format_must_be_semantic
12
+
13
+ private
14
+
15
+ def key_format_must_be_semantic
16
+ return if key.blank?
17
+ return if Jumbotron::TeamKey.valid_format?(key)
18
+
19
+ errors.add(:key, "must be a lowercase kebab-case semantic key")
20
+ end
10
21
  end
11
22
  end
@@ -57,6 +57,7 @@ module Jumbotron
57
57
  team.name = team_input.name
58
58
  team.changed_at = observed_at
59
59
  end
60
+ # key is immutable after assignment — never regenerate from name or provider id
60
61
  team.observed_at = observed_at
61
62
  team.save!
62
63
  team
@@ -65,13 +66,28 @@ module Jumbotron
65
66
  def create_new!
66
67
  team = Team.create!(
67
68
  name: team_input.name,
69
+ key: allocate_key!(team_input.name),
68
70
  observed_at: observed_at,
69
71
  changed_at: observed_at
70
72
  )
71
73
  change_set.record(subject: team, attribute: "name", previous: nil, new_value: team.name)
74
+ change_set.record(subject: team, attribute: "key", previous: nil, new_value: team.key)
72
75
  team
73
76
  end
74
77
 
78
+ def allocate_key!(name)
79
+ base = Jumbotron::TeamKey.normalize(name)
80
+ return base unless Team.exists?(key: base)
81
+
82
+ suffix = 2
83
+ loop do
84
+ candidate = "#{base}-#{suffix}"
85
+ return candidate unless Team.exists?(key: candidate)
86
+
87
+ suffix += 1
88
+ end
89
+ end
90
+
75
91
  def recover_after_race!
76
92
  ref = team_input.provider_identities.first
77
93
  identity = ProviderIdentity.find_by!(
@@ -69,7 +69,11 @@ module Jumbotron
69
69
  role: participant.role,
70
70
  score: participant.score,
71
71
  result: participant.result,
72
- team: Jumbotron::Public::Team.new(id: participant.team.id, name: participant.team.name)
72
+ team: Jumbotron::Public::Team.new(
73
+ id: participant.team.id,
74
+ name: participant.team.name,
75
+ key: participant.team.key
76
+ )
73
77
  )
74
78
  end
75
79
 
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddKeyToJumbotronTeams < ActiveRecord::Migration[8.1]
4
+ def up
5
+ add_column :jumbotron_teams, :key, :string, limit: 191
6
+ backfill_keys!
7
+ change_column_null :jumbotron_teams, :key, false
8
+ add_index :jumbotron_teams, :key, unique: true, name: "index_jumbotron_teams_on_key"
9
+ end
10
+
11
+ def down
12
+ remove_index :jumbotron_teams, name: "index_jumbotron_teams_on_key"
13
+ remove_column :jumbotron_teams, :key
14
+ end
15
+
16
+ private
17
+
18
+ def backfill_keys!
19
+ say_with_time "backfill jumbotron_teams.key" do
20
+ taken = {}
21
+ connection.select_all("SELECT id, name FROM jumbotron_teams ORDER BY id").each do |row|
22
+ key = allocate_key(normalize_name(row["name"]), taken)
23
+ taken[key] = true
24
+ connection.execute(
25
+ "UPDATE jumbotron_teams SET `key` = #{connection.quote(key)} WHERE id = #{row['id'].to_i}"
26
+ )
27
+ end
28
+ end
29
+ end
30
+
31
+ def normalize_name(name)
32
+ slug = name.to_s.unicode_normalize(:nfc).downcase
33
+ slug = slug.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "")
34
+ slug = "team" if slug.blank?
35
+ slug
36
+ end
37
+
38
+ def allocate_key(base, taken)
39
+ return base unless taken[base]
40
+
41
+ suffix = 2
42
+ loop do
43
+ candidate = "#{base}-#{suffix}"
44
+ return candidate unless taken[candidate]
45
+
46
+ suffix += 1
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ # Upgrade: Jumbotron 0.1.4
2
+
3
+ **From:** `0.1.3`
4
+ **To:** `0.1.4`
5
+
6
+ Patch release for MariaDB-safe observation evidence JSON persistence. No public consumer contract break. Hosts must already run CommandTower `>= 0.12`.
7
+
8
+ ## Host-facing change
9
+
10
+ | Change | Host impact |
11
+ |--------|-------------|
12
+ | `HistoricalChange` JSON coding | `previous_value` and `new_value` declare `attribute :…, :json`. Fixes `ActiveRecord::CheckViolation` on MariaDB 10.11 where `t.json` is LONGTEXT + `json_valid` CHECK (discovery / sync evidence writes). |
13
+ | `ObservationBatch` JSON coding | `metadata` declares `attribute :metadata, :json`. Defense in depth for non-empty metadata. |
14
+
15
+ ## Upgrade checklist
16
+
17
+ 1. Bump gem to `0.1.4` (or `>= 0.1.4`).
18
+ 2. **No new migration** — runtime model coder only; existing `jumbotron_*` tables unchanged.
19
+ 3. **No** recurring schedule rematerialize required for this patch.
20
+ 4. After deploy, run a **one-shot** full-season discovery if the catalog is still empty (boot discovery remains off on Pick'em):
21
+
22
+ ```ruby
23
+ Jumbotron::DiscoveryJob.perform_later(
24
+ adapter_id: "espn_nfl",
25
+ discovery_id: "full_season",
26
+ continuation_attempt: 1
27
+ )
28
+ ```
29
+
30
+ 5. Smoke: `Jumbotron::Game.count` > 0 after discovery completes; live `GameUpdateJob` ticks without `CheckViolation` on evidence writes.
31
+
32
+ ## Dummy host (engine repo)
33
+
34
+ Jumbotron dummy Compose now uses **MariaDB 10.11.14** (production parity). Recreate the Compose `mysql` volume after pulling this release.
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jumbotron
4
+ # Immutable semantic public team identity helper.
5
+ # Derives a kebab-case slug once at assignment; callers must not re-run on rename.
6
+ module TeamKey
7
+ FORMAT = /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/
8
+
9
+ module_function
10
+
11
+ def normalize(name)
12
+ slug = name.to_s.unicode_normalize(:nfc).downcase
13
+ slug = slug.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "")
14
+ slug = "team" if slug.blank?
15
+ slug
16
+ end
17
+
18
+ def valid_format?(key)
19
+ key.to_s.match?(FORMAT)
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jumbotron
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/jumbotron.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "rails"
4
4
  require "command_tower"
5
5
  require "jumbotron/version"
6
+ require "jumbotron/team_key"
6
7
  require "jumbotron/engine"
7
8
  require "jumbotron/client"
8
9
 
@@ -5,5 +5,11 @@ FactoryBot.define do
5
5
  sequence(:name) { |n| "Team #{n}" }
6
6
  observed_at { Time.current }
7
7
  changed_at { Time.current }
8
+
9
+ after(:build) do |team|
10
+ next if team.key.present?
11
+
12
+ team.key = Jumbotron::TeamKey.normalize(team.name)
13
+ end
8
14
  end
9
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jumbotron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - matt-taylor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-24 00:00:00.000000000 Z
11
+ date: 2026-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: command_tower
@@ -205,12 +205,15 @@ files:
205
205
  - db/migrate/20260813000001_create_jumbotron_schedule_groups.rb
206
206
  - db/migrate/20260814000001_create_jumbotron_line_observations.rb
207
207
  - db/migrate/20260820000001_add_progress_to_jumbotron_games.rb
208
+ - db/migrate/20260827150001_add_key_to_jumbotron_teams.rb
208
209
  - docs/testing.md
209
210
  - docs/upgrades/0.1.2.md
210
211
  - docs/upgrades/0.1.3.md
212
+ - docs/upgrades/0.1.4.md
211
213
  - lib/jumbotron.rb
212
214
  - lib/jumbotron/client.rb
213
215
  - lib/jumbotron/engine.rb
216
+ - lib/jumbotron/team_key.rb
214
217
  - lib/jumbotron/testing.rb
215
218
  - lib/jumbotron/version.rb
216
219
  - lib/tasks/jumbotron_schedules.rake