33# Table name: beacons
44# Database name: primary
55#
6- # id :bigint not null, primary key
7- # api_key_digest :string not null
8- # api_key_prefix :string not null
9- # manifest_checksum :string
10- # manifest_data :jsonb
11- # manifest_version :integer default(0), not null
12- # name :string not null
13- # previous_manifest_data :jsonb
14- # revoked_at :datetime
15- # created_at :datetime not null
16- # updated_at :datetime not null
17- # language_id :bigint not null
18- # region_id :bigint not null
6+ # id :bigint not null, primary key
7+ # api_key_digest :string not null
8+ # api_key_prefix :string not null
9+ # device_info :jsonb
10+ # last_seen_at :datetime
11+ # last_sync_at :datetime
12+ # last_sync_error :text
13+ # manifest_checksum :string
14+ # manifest_data :jsonb
15+ # manifest_version :integer default(0), not null
16+ # name :string not null
17+ # previous_manifest_data :jsonb
18+ # reported_files_count :integer
19+ # reported_manifest_checksum :string
20+ # reported_manifest_version :string
21+ # reported_total_size_bytes :bigint
22+ # revoked_at :datetime
23+ # sync_status :string
24+ # created_at :datetime not null
25+ # updated_at :datetime not null
26+ # language_id :bigint not null
27+ # region_id :bigint not null
1928#
2029# Indexes
2130#
2231# index_beacons_on_api_key_digest (api_key_digest) UNIQUE
2332# index_beacons_on_language_id (language_id)
33+ # index_beacons_on_last_seen_at (last_seen_at)
2434# index_beacons_on_region_id (region_id)
35+ # index_beacons_on_sync_status (sync_status)
2536#
2637# Foreign Keys
2738#
2839# fk_rails_... (language_id => languages.id)
2940# fk_rails_... (region_id => regions.id)
3041#
3142class Beacon < ApplicationRecord
43+ SYNC_STATUSES = %w[ synced syncing outdated error ] . freeze
44+
3245 belongs_to :language
3346 belongs_to :region
3447
@@ -41,6 +54,8 @@ class Beacon < ApplicationRecord
4154 delegate :name , to : :region , prefix : true
4255 delegate :name , to : :language , prefix : true
4356
57+ enum :sync_status , SYNC_STATUSES . index_with ( &:itself )
58+
4459 validates :name , presence : true
4560 validates :api_key_digest , presence : true , uniqueness : true
4661 validates :api_key_prefix , presence : true
0 commit comments