mcpField
S
spacetimedb-tables

spacetimedb-tables

github.com/danmossaData & databases2169 installsUpdated 19w ago
Repository

About spacetimedb-tables

A reference skill for designing SpacetimeDB module tables and improving access patterns. It serves developers working with TypeScript, C#, Rust, or C++ schemas, with guidance on indexing, visibility, migrations, events, and schedules.

Key features

  1. 01Language-specific table declaration patterns
  2. 02Table visibility and access guidance
  3. 03Index selection and performance advice
  4. 04Migration and column-default rules
  5. 05Event and schedule table guidance

Use cases

  1. 01Designing a SpacetimeDB module schema
  2. 02Choosing indexes for frequent queries
  3. 03Changing a published table safely

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/danmossa/spacetimedb-skills --skill spacetimedb-tables

After installing, type/spacetimedb-tablesin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
tables-access-permissions.md
tables-auto-increment.md
tables-column-types.md
tables-constraints.md
tables-default-values.md
tables-event-tables.md
tables-file-storage.md
tables-indexes.md
tables-performance.md
tables-schedule-tables.md
tables.md

Details

From the project README

Use this skill for module schema and table performance.

Core table patterns

TypeScript tables use table(options, columns) and must be passed to schema() as an object:

import { schema, table, t } from "spacetimedb/server";

const player = table(
  { name: "player", public: true },
  {
    id: t.u64().primaryKey().autoInc(),
    identity: t.identity().unique(),
    name: t.string().index("btree"),
  },
);

export default schema({ player });

Language-specific table declarations:

  • TypeScript: { name: "player_score" } creates ctx.db.playerScore.
  • C#: [SpacetimeDB.Table(Accessor = "Player", Public = true)] creates ctx.Db.Player; the type must be partial.
  • Rust: #[spacetimedb::table(accessor = player, public)] creates ctx.db.player(); pub struct does not make a table public.
  • C++: SPACETIMEDB_TABLE(Type, player, Public) creates ctx.db[player].

Design rules

  • Organize data by access/update pattern. Split hot, frequently updated state from rarely changed profile, settings, or stats fields.
  • Public tables are visible to clients through subscriptions. Keep server-only state private and expose derived subsets through views when needed.
  • Primary keys and unique constraints automatically create indexes; do not add duplicate indexes for them.
  • Add indexes only for frequent equality, range, subscription, or join paths. Use B-tree by default; direct indexes are for dense unsigned integer keys and are not universally supported in every language.
  • New columns in existing published tables need defaults and must be appended at the end. Check database migration rules before changing existing schemas.
  • Auto-increment values are generated by the database and can have gaps after failed transactions.
  • Use event tables for append-only client notifications; the event flag cannot be changed after publish.
  • Schedule tables need a ScheduleAt column and a linked scheduled reducer. In TypeScript, import ScheduleAt from spacetimedb, not spacetimedb/server.

Reference map

NeedOpen
Table definitions and core patternsreferences/tables.md
Access controlreferences/tables-access-permissions.md
IDs and defaultsreferences/tables-auto-increment.md, references/tables-default-values.md
Types and constraintsreferences/tables-column-types.md, references/tables-constraints.md
Index designreferences/tables-indexes.md
Event and schedule tablesreferences/tables-event-tables.md, references/tables-schedule-tables.md
Storage and performancereferences/tables-file-storage.md, references/tables-performance.md

Guidance

  • Check migration implications in spacetimedb-databases before changing existing schemas.
  • Favor indexed lookups for reducer paths that run often or touch large tables.
  • Use event tables for append-only client notifications, especially when replacing reducer result callback patterns.

Comments

Markdown supported