From 4b18e7bee2a7b746be41c6d23612bb20ff226e89 Mon Sep 17 00:00:00 2001 From: romeoscript Date: Sun, 22 Feb 2026 18:54:19 +0100 Subject: [PATCH 1/2] feat: add tip tracking columns to users table (#246) --- app/api/users/register/route.ts | 5 ++++- db/schema.sql | 5 ++++- scripts/migrations/add-tip-columns.sql | 11 +++++++++++ scripts/setup-db.js | 5 ++++- 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 scripts/migrations/add-tip-columns.sql diff --git a/app/api/users/register/route.ts b/app/api/users/register/route.ts index 628bf1da..7b8124b4 100644 --- a/app/api/users/register/route.ts +++ b/app/api/users/register/route.ts @@ -42,7 +42,10 @@ async function handler(req: Request) { emailNotifications BOOLEAN DEFAULT TRUE, creator JSONB DEFAULT '{"streamTitle":"", "tags":[], "category":"", "payout":"", "thumbnail":""}', created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + total_tips_received NUMERIC(20, 7) DEFAULT 0, + total_tips_count INTEGER DEFAULT 0, + last_tip_at TIMESTAMP ) `; diff --git a/db/schema.sql b/db/schema.sql index 2d253df8..cf12b1d3 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -31,7 +31,10 @@ CREATE TABLE IF NOT EXISTS users ( stream_started_at TIMESTAMP WITH TIME ZONE, emailVerified BOOLEAN DEFAULT FALSE, emailNotifications BOOLEAN DEFAULT TRUE, - creator JSONB DEFAULT '{}' + creator JSONB DEFAULT '{}', + total_tips_received NUMERIC(20, 7) DEFAULT 0, + total_tips_count INTEGER DEFAULT 0, + last_tip_at TIMESTAMP ); ALTER TABLE users diff --git a/scripts/migrations/add-tip-columns.sql b/scripts/migrations/add-tip-columns.sql new file mode 100644 index 00000000..22a5e320 --- /dev/null +++ b/scripts/migrations/add-tip-columns.sql @@ -0,0 +1,11 @@ +-- Migration: Add tip tracking columns to users table +-- Issue: #246 +-- Description: Cache tip aggregates from Stellar Horizon API for faster dashboard display + +ALTER TABLE users ADD COLUMN IF NOT EXISTS total_tips_received NUMERIC(20, 7) DEFAULT 0; +ALTER TABLE users ADD COLUMN IF NOT EXISTS total_tips_count INTEGER DEFAULT 0; +ALTER TABLE users ADD COLUMN IF NOT EXISTS last_tip_at TIMESTAMP; + +COMMENT ON COLUMN users.total_tips_received IS 'Total XLM received via tips (cached from Horizon API)'; +COMMENT ON COLUMN users.total_tips_count IS 'Number of tips received'; +COMMENT ON COLUMN users.last_tip_at IS 'Timestamp of most recent tip'; diff --git a/scripts/setup-db.js b/scripts/setup-db.js index d7df2126..5c0d657a 100644 --- a/scripts/setup-db.js +++ b/scripts/setup-db.js @@ -42,7 +42,10 @@ async function createUsersTable() { bio TEXT, socialLinks JSONB, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + total_tips_received NUMERIC(20, 7) DEFAULT 0, + total_tips_count INTEGER DEFAULT 0, + last_tip_at TIMESTAMP ); `); console.log("Users table created or already exists"); From 19f2dda28dd47754a6831bc384ce0b8fc190a4f0 Mon Sep 17 00:00:00 2001 From: romeoscript Date: Mon, 23 Feb 2026 22:19:22 +0100 Subject: [PATCH 2/2] test: add migration verification script for tip tracking columns --- scripts/test-migration.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 scripts/test-migration.sh diff --git a/scripts/test-migration.sh b/scripts/test-migration.sh new file mode 100755 index 00000000..b9b61b6c --- /dev/null +++ b/scripts/test-migration.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# scripts/test-migration.sh + +# Use streamfi_test as the default local database if not specified +DB_URL=${DATABASE_URL:-streamfi_test} + +echo "Querying 'users' table columns:" +psql $DB_URL -c "\d users" | grep -E "total_tips_received|total_tips_count|last_tip_at" + +echo "" +echo "Checking default values for existing users (first 5):" +psql $DB_URL -c "SELECT email, total_tips_received, total_tips_count, last_tip_at FROM users LIMIT 5;" +