imtiajrex/appflare-skills/appflare-schema
Claude Code and agent skill by imtiajrex/appflare-skills
- community
Checking that the SKILL.md file is still in the repository.
Define and change the Appflare schema DSL (schema, table, v) and apply D1 migrations. Covers column builders (v.int, v.string, v.boolean, v.date, v.uuid, v.enum, v.array, v.object), modifiers (notNull, unique, default, defaultNow), table options for composite indexes and CHECK constraints, relations with v.one, v.many and v.manyToMany including foreign key naming, relationName pairing and junction tables, and the appflare migrate and migrate:custom workflow. Use when adding a table, column, enum, JSON field, index, constraint or relation, fixing FK or nullability issues, or running migrations in an Appflare project.
Install
npx vskill@latest install imtiajrex/appflare-skills/appflare-schemaSKILL.md
The same SKILL.md was published earlier as imtiajrex/appflare-skills/appflare-schema.
Appflare schema
Workflow
- [ ] Open the schema entry (
schemaDsl.entryinappflare.config.ts, usuallyschema.ts) - [ ] Edit tables inside the exported
schema({...}) - [ ] Run
bun appflare devfrom the backend package and fix any compiler error it prints - [ ] Run
bun appflare migrate --localand review the new SQL file indrizzle/ - [ ] Update the handlers and client code that use the changed fields
Template
Several relations to the same table
A v.many whose target has more than one matching v.one fails generation unless both sides share a relationName. The named v.many reuses the v.one's foreign key instead of inferring a new column.
Rules to apply
- Primary keys: use
v.uuid()for string ids orv.int().primaryKey({ autoIncrement: true })for numeric ids. - Nullability: plain columns are nullable and optional. Add
.notNull()to required fields. FKs fromv.oneandv.manyare NOT NULL unless{ nullable: true }. - FK names:
field: v.one("t")createsfieldId.source.rel: v.many("target")adds<singular source>Idto the target. Give the inversev.onethe same name (project↔projects.tasks), or pass the name explicitly (v.many("tasks", "parentProjectId")). - Many-to-many: declare
v.manyToManyon both tables with identical options. The junction holds links only. If the link needs data (a role, a timestamp), create an explicit join table with twov.onerelations. - Defaults:
.default(x)is a SQL default..defaultFn(fn),.defaultNow()andv.uuid()are runtime defaults applied on insert (not by rawctx.$db). Any column with a default reads back as non-null and rejects an explicitnull; add.nullable()if it really stores nulls. - Invariants: put rules that must always hold in
checks(or a trigger viamigrate:custom), because a batch can't abort on a condition. They surface asCheckConstraintError/TriggerAbortError→ HTTP 400. - Auth tables (
users,sessions,accounts,verifications) come from Better Auth. Reference them (v.one("users")) but never define them. - SQL naming is camelCase to snake_case automatically. Use
.sql("name")ortable(shape, { sqlName })only to match an existing database.
Gotchas
v.number()is an alias ofv.int()and creates an INTEGER column. There is no float column type.v.date()is stored as epoch milliseconds, and filters acceptDateor numbers..defaultNow()and.defaultFn()don't add a SQL default, so rows inserted with raw SQL (and rows written before the default existed) keepNULLeven though the type says otherwise.checks[].sqluses SQL column names (balance_minor), not field names.- Triggers, views and backfills go in an empty migration:
bun appflare migrate:custom --name add_guards. - Reciprocal
manyToManydeclarations with differentjunctionTableor field options fail generation. onDelete: "set null"requiresnullable: trueon the relation.migratereads the compiled schema, so always runbun appflare devfirst.- Pass only one of
--local,--remoteor--previewtomigrate. - Adding a Better Auth plugin changes auth tables. Regenerate and migrate afterwards.
References
- Read references/column-api.md when you need every
v.*builder, option or modifier, or the SQL and TypeScript mapping. - Read references/relations.md when configuring relation options (custom FK names, reference fields, junction names, FK actions, self-relations) or debugging a relation compile error.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/appflare-schema/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/imtiajrex/appflare-skills/appflare-schema)