Platforms no longer have a user_id: there's one global list, unique by name, that every authenticated user reads from and writes to. Games are unchanged - still private per user, still referencing platform_id. - Migration: dropped platform.user_id and its FK, UNIQUE(user_id, name) -> UNIQUE(name), index on change_seq alone instead of (user_id, change_seq). Amended the one init migration in place rather than stacking a second one, since nothing is deployed yet. - db/query.sql: platform queries no longer take a user_id parameter. DeletePlatform's NOT EXISTS guard already checked games from any user (it never filtered the subquery by user_id), so deleting a shared platform is correctly blocked by any user's games on it, not just the deleter's. - routes.go: platform handlers still require auth (the list isn't public to anonymous requests) but no longer scope by user. - Tests: updated the mocks for the new signatures, added TestListPlatformsIsSharedAcrossUsers. Verified against a real Postgres: user A creates "PC", user B sees it immediately, both can add games against it, each only sees their own games, deleting the platform is blocked while either user has a game on it, and the name stays globally unique. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
50 lines
920 B
Go
50 lines
920 B
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
|
|
package db
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type Game struct {
|
|
ID uuid.UUID
|
|
UserID uuid.UUID
|
|
PlatformID uuid.UUID
|
|
Name string
|
|
Score int32
|
|
ReleaseDate pgtype.Date
|
|
Finished pgtype.Date
|
|
UpdatedAt pgtype.Timestamptz
|
|
DeletedAt pgtype.Timestamptz
|
|
ChangeSeq int64
|
|
}
|
|
|
|
type Platform struct {
|
|
ID uuid.UUID
|
|
Name string
|
|
UpdatedAt pgtype.Timestamptz
|
|
DeletedAt pgtype.Timestamptz
|
|
ChangeSeq int64
|
|
}
|
|
|
|
type Session struct {
|
|
TokenHash []byte
|
|
UserID uuid.UUID
|
|
CreatedAt pgtype.Timestamptz
|
|
ExpiresAt pgtype.Timestamptz
|
|
LastSeenAt pgtype.Timestamptz
|
|
}
|
|
|
|
type User struct {
|
|
ID uuid.UUID
|
|
Email string
|
|
PasswordHash string
|
|
Name string
|
|
Bio pgtype.Text
|
|
CreatedAt pgtype.Timestamptz
|
|
UpdatedAt pgtype.Timestamptz
|
|
}
|