New migration files on this branch vs base, plus uncommitted ones locally.
(baseRef: string)
| 391 | |
| 392 | /** New migration files on this branch vs base, plus uncommitted ones locally. */ |
| 393 | function changedMigrationFiles(baseRef: string): string[] { |
| 394 | const files = new Set<string>() |
| 395 | const inDir = (p: string) => p.startsWith(`${MIGRATIONS_DIR}/`) && p.endsWith('.sql') |
| 396 | |
| 397 | const mergeBase = git(['merge-base', baseRef, 'HEAD']) ?? baseRef |
| 398 | const committed = git([ |
| 399 | 'diff', |
| 400 | '--name-only', |
| 401 | '--diff-filter=AM', |
| 402 | mergeBase, |
| 403 | 'HEAD', |
| 404 | '--', |
| 405 | MIGRATIONS_DIR, |
| 406 | ]) |
| 407 | if (committed === null) return [] // git unavailable → fail open (handled by caller) |
| 408 | for (const f of committed.split('\n')) if (inDir(f)) files.add(f) |
| 409 | |
| 410 | const status = git(['status', '--porcelain', '--', MIGRATIONS_DIR]) |
| 411 | if (status) { |
| 412 | for (const raw of status.split('\n')) { |
| 413 | const p = raw.slice(3).trim() |
| 414 | if (inDir(p)) files.add(p) |
| 415 | } |
| 416 | } |
| 417 | return [...files] |
| 418 | } |
| 419 | |
| 420 | async function listSqlFiles(dir: string): Promise<string[]> { |
| 421 | const out: string[] = [] |
no test coverage detected