postgres-game-schema
Genre-agnostic PostgreSQL schema and table conventions for games, written with Drizzle ORM: players, sessions, items, inventory, events, leaderboards…
от 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) carrycreatedAtandupdatedAt; append-only and state rows carry the time that matters (events.createdAt,sessions.startedAt,guild_members.joinedAt). Give a new mutable table both columns. SetupdatedAtin every update; a column default fills it only on insert. - Soft delete.
playershasdeletedAt: timestamp("deleted_at"); a deleted player keeps their rows for history. Every read that returns players, including joins, filtersisNull(players.deletedAt). AdddeletedAtto a new entity when its history matters (templates/entity-template.tspattern 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. Usejsonb, notjson: PostgreSQL storesjsonbdecomposed, processes it faster and can index it. - Enums.
pgEnumfor fixed sets that code switches on (rarity, guild role, leaderboard period). Plaintextfor open sets designers extend (event type, currency type). - Foreign keys.
onDelete: "cascade"from player-owned rows toplayers. Analytics rows (events) useonDelete: "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 theON CONFLICTtarget from a unique index. - Money and currency. Integer amounts, never read-modify-write. Credit with the atomic
amount = amount + nupsert (addCurrencyintemplates/query-patterns.ts). Debit withspendCurrency: oneUPDATE ... WHERE amount >= cost, and it reports failure when no row was updated, so two parallel spends cannot overdraw. Thecurrenciestable also hasCHECK (amount >= 0), so a debit that bypasses the guard fails instead of going negative. - Idempotency.
processed_eventsholds one row per external event or job already applied (a Stripe event id, a reward job key), withidas the primary key, akindandcreated_at. Insert it in the same transaction as the change it guards; a primary-key conflict means the change already happened.stripe-game-paymentsandbullmq-game-queuesuse 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:
- Replace its
playerIdcolumn withcharacterIdreferencingcharacters.id(keeponDelete: "cascade"), and repoint its indexes. - Keep the
CHECK (amount >= 0)and the guardedspendCurrencyas they are. - In
templates/query-patterns.ts, changespendCurrency,addCurrency(including itsON CONFLICTtarget),getPlayerCurrenciesand the inventory queries to takecharacterIdand filter on it. They filter byplayerIdtoday, so they rea
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- 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 запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…