Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/api/users/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
`;

Expand Down
4 changes: 2 additions & 2 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ CREATE TABLE IF NOT EXISTS users (
emailVerified BOOLEAN DEFAULT FALSE,
emailNotifications BOOLEAN DEFAULT TRUE,
creator JSONB DEFAULT '{}',
total_tips_received VARCHAR(255) DEFAULT '0.0000000',
total_tips_received NUMERIC(20, 7) DEFAULT 0,
total_tips_count INTEGER DEFAULT 0,
last_tip_at TIMESTAMP WITH TIME ZONE
last_tip_at TIMESTAMP
);

ALTER TABLE users
Expand Down
11 changes: 11 additions & 0 deletions scripts/migrations/add-tip-columns.sql
Original file line number Diff line number Diff line change
@@ -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';
5 changes: 4 additions & 1 deletion scripts/setup-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
13 changes: 13 additions & 0 deletions scripts/test-migration.sh
Original file line number Diff line number Diff line change
@@ -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;"

Loading