mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
* Preserve existing demo data by default Add SKIP_CLEAR environment variable to demo_data rake tasks. Defaults to true (preserving existing data). Set SKIP_CLEAR=0 to wipe data before generating new demo data. https://claude.ai/code/session_01GcoMc2SH3czPrbeGkHbmpE * Add deterministic instatus.com API key for demo data Create a read-only API key named "instatus.com" with a fixed value when generating demo data. This allows uptime monitoring tools to use a hardcoded API key that doesn't change between demo data runs. The key is idempotent - if it already exists, it will be reused. https://claude.ai/code/session_01GcoMc2SH3czPrbeGkHbmpE * OK to name instatus to a point * Remove all Instatus references * Rename to create_monitoring_api_key! and scope lookup to admin_user - Rename create_instatus_api_key! to create_monitoring_api_key! (snake_case) - Scope API key lookup to admin_user instead of global ApiKey lookup - Each family's admin now has their own monitoring API key https://claude.ai/code/session_01GcoMc2SH3czPrbeGkHbmpE --------- Co-authored-by: Claude <noreply@anthropic.com>
75 lines
2.6 KiB
Ruby
75 lines
2.6 KiB
Ruby
namespace :demo_data do
|
||
desc "Load empty demo dataset (no financial data)"
|
||
task empty: :environment do
|
||
start = Time.now
|
||
skip_clear = ENV.fetch("SKIP_CLEAR", "1") == "1"
|
||
puts "🚀 Loading EMPTY demo data#{skip_clear ? ' (preserving existing data)' : ' (clearing existing data)'}…"
|
||
|
||
Demo::Generator.new.generate_empty_data!(skip_clear: skip_clear)
|
||
|
||
puts "✅ Done in #{(Time.now - start).round(2)}s"
|
||
end
|
||
|
||
desc "Load new-user demo dataset (family created but not onboarded)"
|
||
task new_user: :environment do
|
||
start = Time.now
|
||
skip_clear = ENV.fetch("SKIP_CLEAR", "1") == "1"
|
||
puts "🚀 Loading NEW-USER demo data#{skip_clear ? ' (preserving existing data)' : ' (clearing existing data)'}…"
|
||
|
||
Demo::Generator.new.generate_new_user_data!(skip_clear: skip_clear)
|
||
|
||
puts "✅ Done in #{(Time.now - start).round(2)}s"
|
||
end
|
||
|
||
desc "Load full realistic demo dataset"
|
||
task default: :environment do
|
||
start = Time.now
|
||
seed = ENV.fetch("SEED", Random.new_seed)
|
||
skip_clear = ENV.fetch("SKIP_CLEAR", "1") == "1"
|
||
puts "🚀 Loading FULL demo data (seed=#{seed})#{skip_clear ? ' (preserving existing data)' : ' (clearing existing data)'}…"
|
||
|
||
generator = Demo::Generator.new(seed: seed)
|
||
generator.generate_default_data!(skip_clear: skip_clear)
|
||
|
||
validate_demo_data
|
||
|
||
elapsed = Time.now - start
|
||
puts "🎉 Demo data ready in #{elapsed.round(2)}s"
|
||
end
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# Validation helpers
|
||
# ---------------------------------------------------------------------------
|
||
def validate_demo_data
|
||
total_entries = Entry.count
|
||
trade_entries = Entry.where(entryable_type: "Trade").count
|
||
categorized_txn = Transaction.joins(:category).count
|
||
txn_total = Transaction.count
|
||
|
||
coverage = ((categorized_txn.to_f / txn_total) * 100).round(1)
|
||
|
||
puts "\n📊 Validation Summary".ljust(40, "-")
|
||
puts "Entries total: #{total_entries}"
|
||
puts "Trade entries: #{trade_entries} (#{trade_entries.between?(500, 1000) ? '✅' : '❌'})"
|
||
puts "Txn categorization: #{coverage}% (>=75% ✅)"
|
||
|
||
unless total_entries.between?(8_000, 12_000)
|
||
puts "Total entries #{total_entries} outside 8k–12k range"
|
||
end
|
||
|
||
unless trade_entries.between?(500, 1000)
|
||
puts "Trade entries #{trade_entries} outside 500–1 000 range"
|
||
end
|
||
|
||
unless coverage >= 75
|
||
puts "Categorization coverage below 75%"
|
||
end
|
||
end
|
||
end
|
||
|
||
# Alias namespace to avoid forgetfulness
|
||
namespace :sample_data do
|
||
desc "Load full realistic demo dataset (alias for demo_data:default)"
|
||
task default: "demo_data:default"
|
||
end
|