InstantDB Schema Management
When to Use
When the user asks to modify the database, schema, add entities, or change relationships.
Instructions
- •Read the current schema from
instant.schema.ts. - •Understand the requested change (new entity, new field, new link).
- •Modify
instant.schema.tsfollowing InstantDB patterns:- •Entities use
i.entity({...})with typed fields - •Links define relationships with forward/reverse labels
- •Field types:
i.string(),i.number(),i.boolean(),i.date(),i.json(), with.optional()and.unique()
- •Entities use
- •Update
instant.perms.tsif the new entity needs permission rules. - •Update TypeScript types in
src/types/to match the schema. - •Run
pnpm typecheckto verify no type errors. - •Update
docs/tracking/change_log.md.
Schema Patterns
typescript
// Adding a new entity
const schema = i.schema({
entities: {
newEntity: i.entity({
name: i.string(),
status: i.string(),
createdAt: i.date(),
}),
},
links: {
parentChild: {
forward: { on: "parents", has: "many", label: "children" },
reverse: { on: "newEntity", has: "one", label: "parent" },
},
},
});
Rules
- •Always keep
instant.schema.tsandsrc/types/in sync - •Use descriptive link labels (not generic "items" or "data")
- •Every entity should have
createdAtandupdatedAtfields - •Run typecheck after every schema change