-- Each account's period totals (counters and gauge peaks), copied by its AccountState a few minutes after usage -- moves, so the admin usage page ranks accounts with one query instead of reading every account. CREATE TABLE IF NOT EXISTS usage_leaderboard ( period TEXT NOT NULL, meter TEXT NOT NULL, account_id TEXT NOT NULL, quantity REAL NOT NULL, updated_at INTEGER NOT NULL, PRIMARY KEY (period, meter, account_id) ); CREATE INDEX IF NOT EXISTS usage_leaderboard_rank ON usage_leaderboard(period, meter, quantity); CREATE INDEX IF NOT EXISTS usage_leaderboard_account ON usage_leaderboard(account_id, period);