Skip to content

Inline configs: migrate/check command parity and optional db - #150

Merged
mmkal merged 2 commits into
inline-config-docsfrom
inline-config-commands
Jul 7, 2026
Merged

mmkal merged 2 commits into
inline-config-docsfrom
inline-config-commands

Conversation

@mmkal

@mmkal mmkal commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #148. Gives inline defineConfig projects the same CLI command surface as file-backed ones: sqlfu migrate, check, sync, pending, applied, find, goto, and baseline now work on inline configs, and inline configs accept the same optional db (path or factory).

import {createClient} from '@libsql/client';
import {defineConfig, createLibsqlClient, sql} from 'sqlfu';

export default defineConfig({
  // optional - without it, CLI commands use .sqlfu/app.db like file-backed configs
  db: () => {
    const raw = createClient({url: process.env.TURSO_DATABASE_URL || 'file:./.sqlfu/app.db'});
    return {client: createLibsqlClient(raw), async [Symbol.asyncDispose]() { await raw.close(); }};
  },
  definitions: sql`create table posts (slug text primary key)`,
  queries: {listPosts: sql`select slug from posts`},
});

Before / after

Before, every database-touching command rejected inline projects:

$ npx sqlfu migrate
This command requires a file-backed sqlfu config. inline defineConfig modules currently support generate and draft.

After, the same commands work with the same semantics as file-backed configs — inline migration entries are the migrations, the inline definitions template is the desired schema, and the database is the config's db or the .sqlfu/app.db default:

$ npx sqlfu migrate
applied 0001_create_posts
$ npx sqlfu check
# compares definitions vs replayed inline migrations vs history vs live schema

Design

loadContextConfig resolves inline projects into a real SqlfuContext (synthesized project config + statically-parsed definitions/migrations as in-memory repo inputs) instead of throwing. The two repo-input seams (readDefinitionsSql, readMigrationsFromContext) consult context.inline; every command internal already consumed only context.config + context.host, so the migration engine, diff, and check analysis work unchanged.

The CLI only dynamically imports the inline module when it statically detects a db property (new InlineConfigSource.hasDb + optional host.importConfigModule capability), so runtime-only modules — Durable Objects importing cloudflare:workers — are never imported. A db on a non-exported config errors with instructions to export it.

Deliberate limits: modules with multiple inline defineConfig calls error for db commands (the runtime-managed multi-DO shape where CLI migrate doesn't apply), inline drafting stays on the appendInlineMigration path, and the Admin UI backend remains file-backed-only.

See tasks/inline-config-commands.md for the full spec.

Verification

  • pnpm --filter sqlfu exec vitest run test/inline-commands-parity.test.ts — new end-to-end tests: migrate/check/pending/applied against the default db, a db path, and a db factory (real module import through a temp-dir node_modules symlink); drift detection with no database; clear errors for non-exported db and multi-config modules
  • pnpm --filter sqlfu exec vitest run — full suite; only the pre-existing environmental failures (resolve-sqlfu-ui needs the ui package built; generate-watch timeout flake)
  • pnpm --filter sqlfu typecheck && pnpm --filter @sqlfu/ui typecheck
  • README/docs synced

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pkg-pr-new

pkg-pr-new Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/sqlfu@150

commit: 07bf1b2

sqlfu migrate, check, sync, pending, applied, find, goto and baseline
now work on inline defineConfig projects. loadContextConfig resolves an
inline project into a real SqlfuContext instead of throwing: a
synthesized project config plus the statically-parsed definitions SQL
and migration entries as in-memory repo inputs, consumed via the two
repo-input seams (readDefinitionsSql / readMigrationsFromContext). All
the command internals already only used context.config + context.host,
so they work unchanged - including the .sqlfu/app.db default database
when no db is declared, matching file-backed configs.

Inline configs also accept the same optional db (path or factory) as
file-backed configs. The static parser records whether a defineConfig
object declares db, and only then does the CLI dynamically import the
module (via a new optional host.importConfigModule capability) - so
runtime-only modules like Durable Objects importing cloudflare:workers
are never imported. String paths resolve relative to the config module;
a db on a non-exported config errors with instructions to export it.

Deliberate limits: modules with multiple inline defineConfig calls error
for db commands (that's the runtime-managed multi-DO shape), drafting
for inline stays on the appendInlineMigration path, and the Admin UI
backend remains file-backed-only with an updated error message.

Docs: the CLI/README command-shape notes now describe parity, and the
turso guide's db factory example is back - this time against an API that
actually supports it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mmkal
mmkal merged commit 07bf1b2 into inline-config-docs Jul 7, 2026
7 checks passed
@mmkal

mmkal commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 Merged into #148 directly (fast-forward of inline-config-docs) — inline/file-backed command parity ships with the onboarding change rather than as a separate stacked step. Closing.

@mmkal
mmkal deleted the inline-config-commands branch July 7, 2026 10:37
mmkal added a commit that referenced this pull request Oct 29, 2026
Both tasks' checklists are done; the commands task shipped as #150,
merged into this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant