Skip to content

chore(root): adds src and test files#29

Merged
yowainwright merged 9 commits into
mainfrom
improvements-tweaks
May 3, 2026
Merged

chore(root): adds src and test files#29
yowainwright merged 9 commits into
mainfrom
improvements-tweaks

Conversation

@yowainwright

@yowainwright yowainwright commented Apr 27, 2026

Copy link
Copy Markdown
Owner

Description

Adds small code tweaks + tests

Type

  • Fix
  • Feature
  • Documentation

Testing

  • Tests pass (npm test)
  • Build succeeds (npm run build)

@codecov

codecov Bot commented Apr 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.73504% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.38%. Comparing base (f182d76) to head (124d399).

Files with missing lines Patch % Lines
src/migrations/index.ts 90.71% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #29      +/-   ##
==========================================
- Coverage   87.72%   87.38%   -0.35%     
==========================================
  Files          12       12              
  Lines        1491     1538      +47     
==========================================
+ Hits         1308     1344      +36     
- Misses        183      194      +11     
Flag Coverage Δ
unittests 87.38% <92.73%> (-0.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps

greptile-apps Bot commented Apr 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR refactors the migrations engine with several improvements: SQL statement splitting now correctly handles single/double-quoted strings, line/block comments, and PostgreSQL dollar-quote syntax; locking is unified to a cross-database table-based approach (_prisma_migrations_lock); $transaction replaces manual BEGIN/COMMIT/ROLLBACK; and MigrationHooks plus MigrationsOptions are exported as first-class interfaces. The CLI gains a withPrismaClient helper to guarantee $disconnect on all code paths and parseStepsOption for validated --steps handling.

Confidence Score: 4/5

Safe to merge; no new P0/P1 issues found. Previously flagged concerns around stale-lock propagation remain but are pre-existing.

This is a broad, well-considered refactor with clear improvements: unified table-based locking, proper $transaction usage, robust SQL parser, and backward compat with Prisma Migrate records. All previously flagged interface and retry-loop concerns have been addressed in this PR.

src/migrations/index.ts and src/migrations/locking.ts are the most impactful files; the unit tests cover the key new behaviours well.

Important Files Changed

Filename Overview
src/migrations/index.ts Major refactor: adds SQL parser with proper string/comment/dollar-quote awareness, MigrationHooks, MigrationsOptions, Prisma Migrate record compatibility helpers, and switches to $transaction.
src/migrations/locking.ts Replaces per-DB advisory lock detection with a unified table-based lock; adds stale-lock TTL via clearStaleLock; non-conflict errors from tryAcquire are now re-thrown instead of silently returning false.
src/types.ts Splits PrismaClient into PrismaMigrationClient (raw query methods + $executeRawUnsafe) and PrismaClient extends PrismaMigrationClient (adds $transaction, $disconnect).
src/cli/index.ts Adds withPrismaClient helper (ensures $disconnect in finally), parseStepsOption for validated CLI step parsing, and loadRuntimeConfig closure that merges file-based log level with CLI flags.
src/config/schema.ts Adds validated fields disableLocking, skipChecksumValidation, lockTimeout (with safe-integer + positive guard); removes the unused prismaClient field.
src/logger/index.ts Adds isLogLevel guard; setLogLevel and the level setter now throw on invalid values instead of silently casting; env-var log level is also validated at startup.

Sequence Diagram

sequenceDiagram
    participant CLI
    participant withPrismaClient
    participant Migrations
    participant MigrationLock
    participant DB

    CLI->>withPrismaClient: command (up/down/status...)
    withPrismaClient->>DB: createPrismaClient()
    withPrismaClient->>Migrations: new Migrations(client, config)

    alt locking enabled
        Migrations->>MigrationLock: withLock(fn, timeout)
        MigrationLock->>DB: CREATE TABLE IF NOT EXISTS _prisma_migrations_lock
        MigrationLock->>DB: DELETE stale rows (locked_at < threshold)
        MigrationLock->>DB: INSERT INTO _prisma_migrations_lock (id=1)
        Note over MigrationLock,DB: Retries every 1s until timeout
    end

    Migrations->>DB: SELECT id, migration_name FROM _prisma_migrations
    Migrations->>Migrations: hooks.beforeUp/beforeDown

    loop each migration
        Migrations->>DB: $transaction(tx => ...)
        DB->>DB: run migration SQL via tx.$executeRawUnsafe
        DB->>DB: INSERT/DELETE _prisma_migrations row
    end

    Migrations->>Migrations: hooks.afterUp/afterDown
    MigrationLock->>DB: DELETE FROM _prisma_migrations_lock
    withPrismaClient->>DB: client.$disconnect()
Loading

Reviews (8): Last reviewed commit: "chore: adds locking update" | Re-trigger Greptile

Comment thread src/migrations/locking.ts
Comment thread src/migrations/locking.ts
@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile

Comment thread tests/e2e/cli-test/node_modules Outdated
@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile review

Comment thread src/migrations/locking.ts
@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile

Comment thread src/migrations/locking.ts
@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile

Comment thread src/types.ts
@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile review

@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile

@yowainwright

Copy link
Copy Markdown
Owner Author

@greptile review

@yowainwright yowainwright merged commit f892510 into main May 3, 2026
7 checks passed
@yowainwright yowainwright deleted the improvements-tweaks branch May 3, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant