dawarich/db/migrate/20251227000001_create_digests.rb
Evgenii Burmakin 18b13fb915
Add yearly digest (#2073)
* Add yearly digest

* Rename YearlyDigests to Users::Digests

* Minor changes

* Update yearly digest layout and styles

* Add flags and chart to email

* Update colors

* Fix layout of stats in yearly digest view

* Remove cron job for yearly digest scheduling

* Update CHANGELOG.md

* Update digest email setting handling

* Allow sharing digest for 1 week or 1 month

* Change Digests Distance to Bigint

* Fix settings page
2025-12-28 17:33:35 +01:00

38 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class CreateDigests < ActiveRecord::Migration[8.0]
def change
create_table :digests do |t|
t.references :user, null: false, foreign_key: true
t.integer :year, null: false
t.integer :period_type, null: false, default: 0 # enum: monthly: 0, yearly: 1
# Aggregated data
t.bigint :distance, null: false, default: 0 # Total distance in meters
t.jsonb :toponyms, default: {} # Countries/cities data
t.jsonb :monthly_distances, default: {} # {1: meters, 2: meters, ...}
t.jsonb :time_spent_by_location, default: {} # Top locations by time
# First-time visits (calculated from historical data)
t.jsonb :first_time_visits, default: {} # {countries: [], cities: []}
# Comparisons
t.jsonb :year_over_year, default: {} # {distance_change_percent: 15, ...}
t.jsonb :all_time_stats, default: {} # {total_countries: 50, ...}
# Sharing (like Stat model)
t.jsonb :sharing_settings, default: {}
t.uuid :sharing_uuid
# Email tracking
t.datetime :sent_at
t.timestamps
end
add_index :digests, %i[user_id year period_type], unique: true
add_index :digests, :sharing_uuid, unique: true
add_index :digests, :year
add_index :digests, :period_type
end
end