fix(api): make migrate.ts direct-run guard work on Windows

The guard compared import.meta.url against `file://${process.argv[1]}`, which
never matches on Windows (argv[1] is a drive-letter/backslash path), so
`yarn db:migrate` silently no-opped for local non-Docker dev. Use
pathToFileURL(process.argv[1]).href instead, which is correct on Windows and
Linux alike. Verified `yarn db:migrate` now creates all tables on Windows; the
Docker start path is unaffected.
This commit is contained in:
Bas van Rossem
2026-06-17 14:07:41 +02:00
parent 41b65f209c
commit efff2214d4

View File

@@ -1,3 +1,4 @@
import { pathToFileURL } from 'node:url';
import { drizzle } from 'drizzle-orm/libsql';
import { migrate } from 'drizzle-orm/libsql/migrator';
import { createClient } from '@libsql/client';
@@ -10,8 +11,9 @@ export async function runMigrations(): Promise<void> {
client.close();
}
// Allow running directly: `tsx src/db/migrate.ts`
if (import.meta.url === `file://${process.argv[1]}`) {
// Allow running directly: `tsx src/db/migrate.ts` (cross-platform — pathToFileURL
// handles Windows drive-letter/backslash paths, which a raw `file://` prefix does not).
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
runMigrations()
.then(() => {
console.log('Migrations applied.');