Add member accounts, follow-based leaderboard, and dedicated Postgres
Members register via email+password (scrypt) or Google OAuth — same signed-cookie + scrypt pattern as LokiLab (lib/auth.ts, member-password.ts, member-auth.ts, google-oauth.ts), own AUTH_SECRET and own OAuth client, own dedicated Postgres database (lokiloto-db on Coolify), fully isolated from LokiLab's own DB and auth. Leaderboard tracks who follows Loki's picks most accurately — members star a pick from the results panel (FollowButton), resolution reuses LokiLab's own lastDraw.won, no money or pooled play involved anywhere. Leaderboard page renders a horizontal bar chart (recharts) plus a ranked list. Profile page: public nickname (required to appear on the leaderboard), list of followed picks. Header now carries nav + a user menu (avatar dropdown when signed in, "Connexion" button otherwise). Dockerfile runs prisma migrate deploy at container start via docker-entrypoint.sh, same pattern as LokiLab. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
fc69d4a668
commit
c3a0a7b765
@@ -0,0 +1,45 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "User" (
|
||||
"id" TEXT NOT NULL,
|
||||
"email" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"avatarUrl" TEXT,
|
||||
"googleSub" TEXT,
|
||||
"passwordHash" TEXT,
|
||||
"publicNickname" TEXT,
|
||||
"favoriteCountry" TEXT NOT NULL DEFAULT 'CA-QC',
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "FollowedPick" (
|
||||
"id" TEXT NOT NULL,
|
||||
"userId" TEXT NOT NULL,
|
||||
"lotteryId" TEXT NOT NULL,
|
||||
"country" TEXT NOT NULL,
|
||||
"targetDrawDate" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "FollowedPick_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_googleSub_key" ON "User"("googleSub");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "FollowedPick_userId_idx" ON "FollowedPick"("userId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "FollowedPick_lotteryId_targetDrawDate_idx" ON "FollowedPick"("lotteryId", "targetDrawDate");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "FollowedPick_userId_lotteryId_targetDrawDate_key" ON "FollowedPick"("userId", "lotteryId", "targetDrawDate");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "FollowedPick" ADD CONSTRAINT "FollowedPick_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (e.g., Git)
|
||||
provider = "postgresql"
|
||||
@@ -0,0 +1,52 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
/// A member account, created on email+password signup or Google sign-in —
|
||||
/// same dual-path pattern as LokiLab (lib/member-password.ts / google-oauth.ts).
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
name String
|
||||
avatarUrl String?
|
||||
googleSub String? @unique
|
||||
/// scrypt hash, format `scrypt$<salt>$<hex>`. Null when the account was
|
||||
/// created via Google only.
|
||||
passwordHash String?
|
||||
/// Shown instead of name/email anywhere this member's activity is public
|
||||
/// (leaderboard, follow counts). Must be set before a member appears
|
||||
/// publicly.
|
||||
publicNickname String?
|
||||
/// Last country tab the member viewed, restored on next visit.
|
||||
favoriteCountry String @default("CA-QC")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
follows FollowedPick[]
|
||||
}
|
||||
|
||||
/// A member "following" one of Loki's picks for a specific upcoming draw —
|
||||
/// the leaderboard is built from how many of these resolve as wins. No
|
||||
/// money, no pooled play: this only records that a member said "I'm
|
||||
/// tracking this one," same spirit as LokiLab's "je joue aussi" copy but
|
||||
/// without a numbers payload (the pick itself lives in LokiLab's feed).
|
||||
model FollowedPick {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
/// Matches LokiLab's lottery id (e.g. "lotto-max", "q4").
|
||||
lotteryId String
|
||||
country String
|
||||
targetDrawDate String
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@unique([userId, lotteryId, targetDrawDate])
|
||||
@@index([userId])
|
||||
@@index([lotteryId, targetDrawDate])
|
||||
}
|
||||
Reference in New Issue
Block a user