{"id":51358371,"url":"https://github.com/kuosuko/dbfy","last_synced_at":"2026-07-02T21:10:11.695Z","repository":{"id":361879330,"uuid":"1256250443","full_name":"kuosuko/dbfy","owner":"kuosuko","description":"DB-ify your migrations — generate a clean post-merge schema snapshot from a folder of SQL migration files. Built for AI agents.","archived":false,"fork":false,"pushed_at":"2026-06-01T16:11:47.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-01T17:25:35.379Z","etag":null,"topics":["agent-skills","cli","migration","postgres","schema","sqlite"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kuosuko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-01T15:46:21.000Z","updated_at":"2026-06-01T16:32:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/kuosuko/dbfy","commit_stats":null,"previous_names":["kuosuko/dbfy"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/kuosuko/dbfy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuosuko%2Fdbfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuosuko%2Fdbfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuosuko%2Fdbfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuosuko%2Fdbfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuosuko","download_url":"https://codeload.github.com/kuosuko/dbfy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuosuko%2Fdbfy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35062939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-skills","cli","migration","postgres","schema","sqlite"],"created_at":"2026-07-02T21:10:11.163Z","updated_at":"2026-07-02T21:10:11.681Z","avatar_url":"https://github.com/kuosuko.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dbfy\n\n\u003e DB-ify your migrations — generate a clean post-merge schema snapshot from a folder of SQL migration files. Built for AI agents.\n\nWhen you're developing a database with `001-xxx.sql`, `002-xxx.sql`, ..., `042-xxx.sql` migrations, AI agents (and humans) usually want **one canonical view of the current schema** — not the entire migration history.\n\n**dbfy** applies your migrations to an ephemeral database in order, dumps the final schema, and hands you a single clean `schema.snapshot.sql` file. No live DB required. No Docker. No waiting.\n\n```\n$ dbfy\ndbfy: auto-detected migrations in \"migrations\"\ndbfy: auto-detected dialect \"postgres\"\ndbfy: wrote ./schema.snapshot.sql (4 migrations, 23ms)\n```\n\nRun it bare in your project: dbfy finds your migrations folder and infers the\ndialect from the SQL itself — no flags required.\n\n## Why\n\n- **For AI agents** — feed one canonical schema file into context, not 50 migration files\n- **For humans** — instant \"what does the DB look like right now?\" view\n- **For CI** — verify destructive migrations actually produce the schema you think\n- **For reviews** — diff `schema.snapshot.sql` across branches\n\n## Install\n\n```bash\nnpm install -g @kuosuko/dbfy\n```\n\nOr run without installing:\n\n```bash\nnpx @kuosuko/dbfy\n```\n\n## Usage\n\n```bash\ndbfy [options]\n\nOptions:\n   -m, --migrations \u003cdir\u003e   Directory of migration files (auto-detected by default)\n   -o, --out \u003cfile|-\u003e       Output file, or '-' for stdout (default: ./schema.snapshot.sql)\n   -d, --dialect \u003cname\u003e     sqlite | postgres | mysql (auto-detected by default)\n       --url \u003curl\u003e          MySQL connection URL for full-fidelity server mode\n                            (also reads MYSQL_URL / DATABASE_URL)\n       --check              Verify the --out file is up to date; exit 1 on drift (CI)\n       --quiet              Suppress the summary line\n       --no-header          Omit the metadata header from the snapshot\n   -h, --help               Show this help\n   -v, --version            Show version\n```\n\nBoth `--migrations` and `--dialect` are auto-detected when omitted. Anything you\npass explicitly always wins over detection.\n\n### Dialects\n\n| Dialect | Engine | Server? | Notes |\n|---------|--------|---------|-------|\n| `sqlite` | better-sqlite3 (in-memory) | No | Fast (~20ms), zero-setup |\n| `postgres` | PGlite (in-memory WASM Postgres) | No | Full PG types: JSONB, ENUM, arrays, partial indexes |\n| `mysql` | **pure DDL parser** (default) | **No** | Parses DDL to the final schema in milliseconds — no server, no Docker |\n| `mysql` + `--url` | real MySQL via `mysql2` | Yes | Full fidelity: views, triggers, routines, generated columns |\n\n```bash\n# SQLite migrations (auto-detected)\ndbfy --out schema.snapshot.sql\n\n# PostgreSQL migrations\ndbfy --out schema.snapshot.sql --dialect postgres\n\n# MySQL — pure-parse, NO server needed (this is dbfy's differentiator)\ndbfy --out schema.snapshot.sql --dialect mysql\n\n# MySQL — full fidelity against a real server\ndbfy --dialect mysql --url mysql://root:root@localhost:3306/ --out schema.snapshot.sql\n\n# Pipe to stdout for agent context\ndbfy --dialect postgres --out -\n```\n\n#### Why MySQL has two modes\n\nUnlike Postgres (which has PGlite, a mature in-memory WASM build), MySQL has **no\nembeddable engine**. Most tools therefore need a live MySQL or a Docker container\njust to compute the final schema. dbfy's default MySQL mode instead **parses the\nDDL directly** — folding every `ALTER TABLE` back into its `CREATE TABLE` — so you\nget the post-merge schema in milliseconds with zero setup.\n\nThe pure-parse engine understands structure (tables, columns, keys, indexes,\nforeign keys) but not stored programs. When you need views, triggers, routines, or\ngenerated columns reproduced exactly, pass `--url` (or set `MYSQL_URL` /\n`DATABASE_URL`) and dbfy runs the migrations against a real server in a throwaway\ndatabase, then drops it.\n\n### CI: fail the build when a snapshot is stale\n\n`--check` regenerates the schema in memory and compares it to the committed\nsnapshot (ignoring the volatile `-- generated:` timestamp line). It exits `0` when\nthey match and `1` on drift — so a contributor who edits a migration but forgets to\nrefresh `schema.snapshot.sql` fails CI.\n\n```bash\n# In CI, after npm ci:\ndbfy --check\n```\n\n```yaml\n# .github/workflows/schema.yml\n- run: npx @kuosuko/dbfy --check\n```\n\n### Migration filename pattern\n\nAny file matching this regex is picked up:\n\n```\n/^(\\d+)[-_](.+)\\.(sql|up\\.sql)$/i\n```\n\nSo all of these work:\n\n- `001-create-users.sql`\n- `001_create_users.sql`\n- `042-add-user-email.up.sql`\n- `20250101_1200-init.sql` (timestamp-based, sorted numerically)\n\n### Example\n\nGiven migrations:\n\n```\nmigrations/\n├── 001-create-users.sql\n├── 002-create-posts.sql\n├── 003-add-comments.sql\n└── 004-add-user-bio.sql\n```\n\nRunning `dbfy` produces a single `schema.snapshot.sql` containing the **post-merge** state of the schema — including destructive changes from later migrations (column drops, etc.).\n\n## How it works\n\n1. Discover migration files matching the pattern, sort by leading number\n2. Spin up an in-memory SQLite database\n3. Apply each migration in order\n4. Dump the final `sqlite_master` schema\n5. Write to file (or stdout)\n\nThe whole thing takes ~20-50ms for typical projects. No external services, no Docker, no configuration files.\n\n## Programmatic API\n\n```ts\nimport { snap } from '@kuosuko/dbfy';\n\nconst result = await snap({\n  migrationsDir: './migrations',\n  out: './schema.snapshot.sql',  // or '-' for stdout\n  dialect: 'mysql',\n  serverUrl: process.env.MYSQL_URL, // optional — omit for zero-setup pure-parse\n  includeHeader: true,\n});\n\nconsole.log(result.filesProcessed, 'migrations applied');\nconsole.log(result.warnings);\n```\n\n## Limitations\n\n- Migrations that contain **data backfills** (not just DDL) are still applied, but the backfill data doesn't end up in the schema file (which is correct — the schema file describes structure, not data).\n- **MySQL pure-parse mode** (the default, no `--url`) reproduces structure — tables, columns, keys, indexes, foreign keys — but not stored programs (views, triggers, routines) or generated columns. dbfy warns when it skips one; pass `--url` for full fidelity.\n\n## Install as Agent Skill\n\ndbfy ships with a `SKILL.md` that teaches AI agents when and how to use it.\n\n**One-command install (recommended):**\n```bash\nnpx skills add kuosuko/dbfy -g\n```\n\n**Manual install:**\n\n| Agent | Location |\n|-------|----------|\n| Claude Code | `~/.claude/skills/dbfy/SKILL.md` or `.claude/skills/dbfy/SKILL.md` |\n| OpenCode | `~/.config/opencode/skills/dbfy/SKILL.md` |\n| Cursor | `.cursor/skills/dbfy/SKILL.md` |\n| Windsurf | `.windsurf/skills/dbfy/SKILL.md` |\n\nThe skill tells the agent to use `dbfy` instead of reading migration files one by one, keeping context lean.\n\nBrowse skills at [skills.sh](https://skills.sh).\n\n## Development\n\n```bash\ngit clone https://github.com/kuosuko/dbfy.git\ncd dbfy\nnpm install\nnpm test\nnpm run build\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuosuko%2Fdbfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuosuko%2Fdbfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuosuko%2Fdbfy/lists"}