Skip to content

Windows fix - #435

Closed
DracFiendMG wants to merge 2 commits into
truefoundry:mainfrom
DracFiendMG:windows-fix
Closed

DracFiendMG wants to merge 2 commits into
truefoundry:mainfrom
DracFiendMG:windows-fix

Conversation

@DracFiendMG

@DracFiendMG DracFiendMG commented Aug 26, 2026 •

Copy link
Copy Markdown

Summary

This PR fixes Issue #427

Closes #427

Changes

A small custom migration provider that imports migrations via a file:// URL on Windows.

How was this tested?

Cloned, built and ran the repo locally and validated whether the behavior after the fix.
image

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Low Risk
Small, SQLite-only change to how migration files are loaded; Postgres migration setup is unchanged.

Overview
Fixes SQLite startup on Windows where dynamic import() of migration modules failed when given raw filesystem paths (Issue #427).

migrateSqliteToLatest now uses a custom FileUrlMigrationProvider instead of Kysely’s FileMigrationProvider. The provider still scans sqlite/migrations for .js/.ts files, but on win32 it loads each migration via pathToFileURL(...).href; on other platforms it keeps importing by path as before.

Reviewed by Cursor Bugbot for commit 4299bc6. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI lite review requested due to automatic review settings August 26, 2026 07:03
@changeset-bot

changeset-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4299bc6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Windows startup for the SQLite-backed (npx @truefoundry/trueforge) flow by changing how SQLite migration modules are loaded so Node’s ESM loader receives a valid file:// specifier on Windows.

Changes:

  • Replaces Kysely’s FileMigrationProvider usage for SQLite with a custom FileUrlMigrationProvider.
  • Adds FileUrlMigrationProvider to load migration modules via dynamic import() (with Windows-specific file URL handling).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/trueforge/src/db/migrateSqlite.ts Switches SQLite migrator to the new custom migration provider.
packages/trueforge/src/db/fileUrlMigrationProvider.ts Introduces a migration provider that reads the migrations directory and imports migration modules dynamically.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +22 to +26
const specifier = process.platform === 'win32' ? pathToFileURL(fullPath).href : fullPath;

const migration = (await import(specifier)) as Migration;
const key = file.substring(0, file.lastIndexOf('.'));
migrations[key] = migration;
Comment on lines 19 to 23
export async function migrateSqliteToLatest(db: Kysely<Database>): Promise<void> {
const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder: path.join(import.meta.dirname, 'sqlite', 'migrations'),
}),
provider: new FileUrlMigrationProvider(path.join(import.meta.dirname, 'sqlite', 'migrations')),
});

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4299bc6. Configure here.


return migrations;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant migration provider

Medium Severity

FileUrlMigrationProvider reimplements Kysely's FileMigrationProvider, but that class already accepts a custom import hook (since 0.29.0; this package uses ^0.29.4) intended for the Windows file:// case. The copy also skips Kysely's default-export unwrap and isMigration checks, so behavior can drift from the built-in provider.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4299bc6. Configure here.


const specifier = process.platform === 'win32' ? pathToFileURL(fullPath).href : fullPath;

const migration = (await import(specifier)) as Migration;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disallowed type assertion

Low Severity

The dynamic import result is forced to Migration with as Migration, which violates the project rule that bans as T / similar assertions to silence typing. A sound approach uses a type guard (as Kysely's isMigration does) or a corrected contract instead of asserting the module namespace.

Fix in Cursor Fix in Web

Triggered by project rule: TrueForge review rules

Reviewed by Cursor Bugbot for commit 4299bc6. Configure here.


return migrations;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing package changeset

Low Severity

Non-blocking: this ships in @truefoundry/trueforge but the PR adds no .changeset/*.md. Please run pnpm changeset and bump @truefoundry/trueforge.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: TrueForge review rules

Reviewed by Cursor Bugbot for commit 4299bc6. Configure here.

@k10-Gangal

Copy link
Copy Markdown

Much needed feature

@thesujai

Copy link
Copy Markdown
Contributor

@DracFiendMG Thanks for your interest to contribute, we think #374 as in a more mergeable state and hence we would like the windows compatibility issue solved through that.

You can look at other help-wanted issues and work on those, also you can look at https://github.com/truefoundry/trueforge/blob/main/CONTRIBUTING.md before you start contributing.

@thesujai thesujai closed this Aug 27, 2026
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.

npx @truefoundry/trueforge command fails to start the server on Windows Terminal (PS, CMD, and Git Bash)

5 participants