Skip to content

Conversation

@Newbie012
Copy link
Collaborator

@Newbie012 Newbie012 commented Nov 13, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of nullable custom types in INSERT statements.
    • Improved type resolution for nullable union mappings (X | null) so the non-null member is correctly propagated.
  • Tests

    • Added test coverage for nullable timestamp types and inserts using custom type mappings.
  • Chores

    • Recorded a patch release entry for this fix.

@changeset-bot
Copy link

changeset-bot bot commented Nov 13, 2025

🦋 Changeset detected

Latest commit: fdfb9cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@ts-safeql/eslint-plugin Patch
@ts-safeql-demos/basic-flat-config Patch
@ts-safeql-demos/basic-migrations-raw Patch
@ts-safeql-demos/basic-transform-type Patch
@ts-safeql-demos/basic Patch
@ts-safeql-demos/big-project Patch
@ts-safeql-demos/config-file-flat-config Patch
@ts-safeql-demos/from-config-file Patch
@ts-safeql-demos/multi-connections Patch
@ts-safeql-demos/playground Patch
@ts-safeql-demos/postgresjs-custom-types Patch
@ts-safeql-demos/postgresjs-demo Patch
@ts-safeql-demos/vercel-postgres Patch
@ts-safeql/generate Patch
@ts-safeql/shared Patch
@ts-safeql/sql-ast Patch
@ts-safeql/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link

vercel bot commented Nov 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
safeql Ignored Ignored Preview Nov 13, 2025 9:54pm

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Walkthrough

A changeset records a patch release for the ESLint plugin that fixes nullable custom types in insert statements. Tests add a table and cases for nullable timestamptz mapped to a custom Instant type, and the type-resolution utility now extracts and resolves non-null members of X | null unions.

Changes

Cohort / File(s) Summary
Release Metadata
\.changeset/stale-signs-bow\.md
Changeset entry for a patch release documenting a fix for nullable custom types in insert statements.
Test Coverage
packages/eslint-plugin/src/rules/check-sql\.test\.ts
Added migration/table test_nullable_timestamptz and two test cases verifying inserts with nullable custom type timestamptz mapped to Instant (direct ${instant} and nested ${x.instant}); minor formatting tweak in an existing SQL snippet.
Type Resolution Logic
packages/eslint-plugin/src/utils/ts-pg\.utils\.ts
getPgTypeFromTsType updated to detect unions of the form `X

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Call as Caller
  participant Util as getPgTypeFromTsType
  participant Check as checkType
  Note over Util: New branch for unions containing null
  Call->>Util: resolve Type (Identifier/Union)
  alt Type is Union and contains null and one non-null member
    Util->>Check: checkType(nonNullMember)
    Check-->>Util: resolved PG type
    Util-->>Call: return PG type
  else Other Union
    Util-->>Call: Unsupported union error / previous handling
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Localized logic change in one utility and corresponding tests.
  • Areas to check:
    • Ensure multi-member unions (more than one non-null) still reject as intended.
    • Confirm tests cover both direct and nested property insertion paths.
    • Verify no regressions in other union handling paths.

Poem

🐰 A nullable hop through unioned night,
I sniffed the inner type and set it right.
Instant dreams from timestamptz unfurled,
Now inserts skip the null-swirled world.
thump-thump, carrot confetti! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: custom nullable column' directly relates to the main changes in the PR, which fix handling of nullable custom types in insert statements by updating type resolution logic.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-custom-nullable-column

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 426799f and fdfb9cb.

📒 Files selected for processing (2)
  • packages/eslint-plugin/src/rules/check-sql.test.ts (2 hunks)
  • packages/eslint-plugin/src/utils/ts-pg.utils.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/eslint-plugin/src/utils/ts-pg.utils.ts
  • packages/eslint-plugin/src/rules/check-sql.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/eslint-plugin/src/utils/ts-pg.utils.ts (1)

323-336: LGTM! Union handling correctly supports nullable types.

The logic mirrors the Identifier case (lines 269-274) to handle X | null unions consistently across different type resolution paths.

Optional refactor: Consider extracting the X | null handling into a helper function to reduce duplication:

function tryExtractNonNullFromUnion(types: ts.Type[]): ts.Type | null {
  const nonNullTypes = types.filter((t) => t.flags !== ts.TypeFlags.Null);
  return nonNullTypes.length === 1 ? nonNullTypes[0] : null;
}

Then use it in both locations:

// In Identifier case (line 269)
if (TSUtils.isTsUnionType(symbolType)) {
  const nonNullType = tryExtractNonNullFromUnion(symbolType.types);
  if (nonNullType) {
    return checkType({ checker, type: nonNullType, options });
  }
  return getPgTypeFromTsTypeUnion({ types: symbolType.types });
}

// In union handling (line 323)
if (TSUtils.isTsUnionType(type)) {
  const matchingType = type.types.find((t) => t.flags in tsFlagToPgTypeMap);
  if (matchingType) {
    return E.right({ kind: "cast", cast: tsFlagToPgTypeMap[matchingType.flags] });
  }

  const nonNullType = tryExtractNonNullFromUnion(type.types);
  if (nonNullType) {
    return checkType({ checker, type: nonNullType, options });
  }

  return E.left("Unsupported union type");
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c90cd7 and 426799f.

📒 Files selected for processing (3)
  • .changeset/stale-signs-bow.md (1 hunks)
  • packages/eslint-plugin/src/rules/check-sql.test.ts (2 hunks)
  • packages/eslint-plugin/src/utils/ts-pg.utils.ts (2 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/stale-signs-bow.md

[style] ~4-~4: Consider using a different verb for a more formal wording.
Context: ... "@ts-safeql/eslint-plugin": patch --- fixed an issue with nullable custom types in ...

(FIX_RESOLVE)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: check (17)
🔇 Additional comments (3)
.changeset/stale-signs-bow.md (1)

1-5: LGTM!

The changeset clearly documents the patch release and the fix for nullable custom types in insert statements.

packages/eslint-plugin/src/rules/check-sql.test.ts (1)

148-150: LGTM!

The new test table properly sets up a nullable TIMESTAMPTZ column for testing the nullable custom type scenario.

packages/eslint-plugin/src/utils/ts-pg.utils.ts (1)

269-277: LGTM! Core fix for nullable custom types.

The logic correctly handles X | null unions by filtering out null and delegating to checkType with the single non-null type. This allows custom type overrides (like timestamptz: "Instant") to resolve properly for nullable parameters.

@Newbie012 Newbie012 merged commit ad0b725 into main Nov 13, 2025
5 checks passed
@Newbie012 Newbie012 deleted the fix-custom-nullable-column branch November 13, 2025 21:59
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.

2 participants