Command Palette

Search for a command to run...

Назад к скиллам
скилл № 95717

postgres-game-schema

Genre-agnostic PostgreSQL schema and table conventions for games, written with Drizzle ORM: players, sessions, items, inventory, events, leaderboards…

БесплатноЗапускает вложенные скрипты
fcsouzaот fcsouza★ 29 звёзд на GitHub

Установить postgres-game-schema в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

PostgreSQL Game Schema

The schema is the value of this skill. Install, driver setup, config and migrations come from the vendor: use the neon-drizzle skill if it is installed, otherwise https://orm.drizzle.team/docs/get-started.

Target the stable Drizzle line, drizzle-orm 0.45.x. The Drizzle docs install lines use drizzle-orm@rc and drizzle-kit@rc; pin the 0.45 versions instead (see "Drizzle 1.0" below).

Conventions

Every table and query in a game project follows these. Other skills (stripe-game-payments, gameplay-analytics, game-economy-design) build on them.

  • Naming. Tables are plural snake_case (item_definitions). Columns are snake_case in SQL and camelCase in TypeScript: playerId: text("player_id"). Indexes are named <table>_<columns>_idx.
  • IDs. text("id").primaryKey().$defaultFn(() => crypto.randomUUID()). Player-facing identifiers are never auto-increment integers; sequential ids let anyone enumerate players and items.
  • Timestamps. timestamp(...).notNull().defaultNow(). Entity and catalog tables (players, item_definitions, guilds) carry createdAt and updatedAt; append-only and state rows carry the time that matters (events.createdAt, sessions.startedAt, guild_members.joinedAt). Give a new mutable table both columns. Set updatedAt in every update; a column default fills it only on insert.
  • Soft delete. players has deletedAt: timestamp("deleted_at"); a deleted player keeps their rows for history. Every read that returns players, including joins, filters isNull(players.deletedAt). Add deletedAt to a new entity when its history matters (templates/entity-template.ts pattern 1).
  • JSONB. Typed columns for anything you filter, sort, join or sum. jsonb(...).$type<...>().default({}) for per-genre extras: stats, baseStats, properties, metadata. Never add genre columns (swordDamage) to core tables. Use jsonb, not json: PostgreSQL stores jsonb decomposed, processes it faster and can index it.
  • Enums. pgEnum for fixed sets that code switches on (rarity, guild role, leaderboard period). Plain text for open sets designers extend (event type, currency type).
  • Foreign keys. onDelete: "cascade" from player-owned rows to players. Analytics rows (events) use onDelete: "set null" so history survives. Catalog references (itemDefinitionId) have no cascade.
  • Indexes. Index the owner key (playerId) of every player-owned table. Add a composite index for each common filter, leading with the owner: events (playerId, type), leaderboards (category, period, score). Put a unique index on every natural key an upsert targets (currencies (playerId, currencyType)): PostgreSQL infers the ON CONFLICT target from a unique index.
  • Money and currency. Integer amounts, never read-modify-write. Credit with the atomic amount = amount + n upsert (addCurrency in templates/query-patterns.ts). Debit with spendCurrency: one UPDATE ... WHERE amount >= cost, and it reports failure when no row was updated, so two parallel spends cannot overdraw. The currencies table also has CHECK (amount >= 0), so a debit that bypasses the guard fails instead of going negative.
  • Idempotency. processed_events holds one row per external event or job already applied (a Stripe event id, a reward job key), with id as the primary key, a kind and created_at. Insert it in the same transaction as the change it guards; a primary-key conflict means the change already happened. stripe-game-payments and bullmq-game-queues use this table.

Characters and ownership

players is the account, keyed to the auth user. characters holds the several characters one account owns, with a name unique per shard among live characters (characters_shard_name_idx is a partial index on deleted_at IS NULL, so deleting a character frees its name; the schema comment says how to reserve names or make them global). The slot limit is a game rule; check it in code.

When the game has characters, the character owns level, xp and stats, and you delete those three columns from players, along with players_level_idx, and point getGuildWithMembers in templates/query-patterns.ts (it selects players.level) at the character. A single-character game skips characters and keeps them on players.

The game decides whether wallets and inventory belong to the account or to a character. The schema ships them on the account (playerId). To move a table to characters:

  1. Replace its playerId column with characterId referencing characters.id (keep onDelete: "cascade"), and repoint its indexes.
  2. Keep the CHECK (amount >= 0) and the guarded spendCurrency as they are.
  3. In templates/query-patterns.ts, change spendCurrency, addCurrency (including its ON CONFLICT target), getPlayerCurrencies and the inventory queries to take characterId and filter on it. They filter by playerId today, so they rea
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • boilerplate/schema.ts
  • references/sources.md
  • templates/entity-template.ts
  • templates/query-patterns.ts

FAQ

Что делает скилл postgres-game-schema?

Genre-agnostic PostgreSQL schema and table conventions for games, written with Drizzle ORM: players, sessions, items, inventory, events, leaderboards, achievements, currencies, social relations and guilds. Use when a game needs a database table, a player data model, inventory or currency storage, a leaderboard table, or any database code that must follow the project's schema conventions.

Как установить скилл postgres-game-schema?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл postgres-game-schema запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить postgres-game-schema с