Skip to content

feat: handle PgLiteral in index expressions#1561

Merged
Shinigami92 merged 23 commits intomainfrom
fix-json-indexes
Jan 14, 2026
Merged

feat: handle PgLiteral in index expressions#1561
Shinigami92 merged 23 commits intomainfrom
fix-json-indexes

Conversation

@brenoepics
Copy link
Copy Markdown
Collaborator

@brenoepics brenoepics commented Jan 2, 2026

fixes #1560

@brenoepics brenoepics self-assigned this Jan 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 2, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 93.33% (🎯 90%)
⬆️ +0.13%
1457 / 1561
🔵 Statements 93.41% (🎯 90%)
⬆️ +0.14%
1475 / 1579
🔵 Functions 94.73% (🎯 90%)
⬆️ +0.32%
324 / 342
🔵 Branches 87.22% (🎯 85%)
⬆️ +0.12%
935 / 1072
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/operations/indexes/createIndex.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/operations/indexes/shared.ts 100%
🟰 ±0%
88.23%
⬆️ +3.23%
100%
🟰 ±0%
100%
🟰 ±0%
src/operations/tables/shared.ts 86.79%
🟰 ±0%
76.76%
🟰 ±0%
76.47%
🟰 ±0%
86.79%
🟰 ±0%
156, 240, 260, 286, 290-296, 300, 441-462
src/utils/createSchemalize.ts 96.42%
⬇️ -3.58%
93.54%
⬇️ -6.46%
100%
🟰 ±0%
96.29%
⬇️ -3.71%
84
src/utils/createTransformer.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/utils/quote.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
Affected Files
src/utils/PgLiteral.ts 100%
⬆️ +20.00%
100%
🟰 ±0%
100%
⬆️ +25.00%
100%
⬆️ +20.00%
Unchanged Files
src/db.ts 78.43% 75% 76.92% 78% 90-92, 125-137, 173, 177-178
src/index.ts 100% 100% 100% 100%
src/logger.ts 100% 100% 100% 100%
src/migration.ts 79.66% 74.07% 79.16% 79.48% 149-151, 174-187, 235-236, 301-336, 402, 429-431, 439, 457-459, 489
src/migrationBuilder.ts 95.49% 62.5% 90% 95.49% 833-836, 976-980
src/migrationOptions.ts 100% 100% 100% 100%
src/pgType.ts 100% 100% 100% 100%
src/runner.ts 76.85% 60.56% 82.6% 76.06% 209-217, 230, 283, 328, 338-341, 355, 367-369, 393, 434-445, 450-452, 473-474, 484, 486-494
src/sqlMigration.ts 83.33% 100% 80% 83.33% 57-59
src/operations/sql.ts 100% 50% 100% 100%
src/operations/casts/createCast.ts 100% 100% 100% 100%
src/operations/casts/dropCast.ts 100% 100% 100% 100%
src/operations/casts/index.ts 100% 100% 100% 100%
src/operations/domains/alterDomain.ts 100% 100% 100% 100%
src/operations/domains/createDomain.ts 100% 95.45% 100% 100%
src/operations/domains/dropDomain.ts 100% 100% 100% 100%
src/operations/domains/index.ts 100% 100% 100% 100%
src/operations/domains/renameDomain.ts 100% 100% 100% 100%
src/operations/domains/shared.ts 100% 100% 100% 100%
src/operations/extensions/createExtension.ts 100% 100% 100% 100%
src/operations/extensions/dropExtension.ts 100% 100% 100% 100%
src/operations/extensions/index.ts 100% 100% 100% 100%
src/operations/extensions/shared.ts 100% 100% 100% 100%
src/operations/functions/createFunction.ts 96.29% 92% 100% 96.29% 71-73
src/operations/functions/dropFunction.ts 100% 100% 100% 100%
src/operations/functions/index.ts 100% 100% 100% 100%
src/operations/functions/renameFunction.ts 100% 100% 100% 100%
src/operations/functions/shared.ts 100% 100% 100% 100%
src/operations/grants/grantOnSchemas.ts 100% 100% 100% 100%
src/operations/grants/grantOnTables.ts 100% 100% 100% 100%
src/operations/grants/grantRoles.ts 100% 100% 100% 100%
src/operations/grants/index.ts 100% 100% 100% 100%
src/operations/grants/revokeOnSchemas.ts 100% 100% 100% 100%
src/operations/grants/revokeOnTables.ts 100% 100% 100% 100%
src/operations/grants/revokeRoles.ts 100% 100% 100% 100%
src/operations/grants/shared.ts 100% 75% 100% 100%
src/operations/indexes/dropIndex.ts 100% 100% 100% 100%
src/operations/indexes/index.ts 100% 100% 100% 100%
src/operations/materializedViews/alterMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/createMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/dropMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/index.ts 100% 100% 100% 100%
src/operations/materializedViews/refreshMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/renameMaterializedView.ts 100% 100% 100% 100%
src/operations/materializedViews/renameMaterializedViewColumn.ts 100% 100% 100% 100%
src/operations/materializedViews/shared.ts 100% 83.33% 100% 100%
src/operations/operators/addToOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/createOperator.ts 100% 88.88% 100% 100%
src/operations/operators/createOperatorClass.ts 100% 75% 100% 100%
src/operations/operators/createOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/dropOperator.ts 100% 100% 100% 100%
src/operations/operators/dropOperatorClass.ts 100% 100% 100% 100%
src/operations/operators/dropOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/index.ts 100% 100% 100% 100%
src/operations/operators/removeFromOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/renameOperatorClass.ts 100% 100% 100% 100%
src/operations/operators/renameOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/shared.ts 81.81% 77.77% 100% 81.81% 24, 38
src/operations/policies/alterPolicy.ts 100% 100% 100% 100%
src/operations/policies/createPolicy.ts 100% 100% 100% 100%
src/operations/policies/dropPolicy.ts 100% 100% 100% 100%
src/operations/policies/index.ts 100% 100% 100% 100%
src/operations/policies/renamePolicy.ts 100% 100% 100% 100%
src/operations/policies/shared.ts 100% 100% 100% 100%
src/operations/roles/alterRole.ts 100% 100% 100% 100%
src/operations/roles/createRole.ts 100% 92.3% 100% 100%
src/operations/roles/dropRole.ts 100% 100% 100% 100%
src/operations/roles/index.ts 100% 100% 100% 100%
src/operations/roles/renameRole.ts 100% 100% 100% 100%
src/operations/roles/shared.ts 100% 86.66% 100% 100%
src/operations/schemas/createSchema.ts 100% 100% 100% 100%
src/operations/schemas/dropSchema.ts 100% 100% 100% 100%
src/operations/schemas/index.ts 100% 100% 100% 100%
src/operations/schemas/renameSchema.ts 100% 100% 100% 100%
src/operations/sequences/alterSequence.ts 90% 83.33% 100% 90% 23
src/operations/sequences/createSequence.ts 100% 100% 100% 100%
src/operations/sequences/dropSequence.ts 100% 100% 100% 100%
src/operations/sequences/index.ts 100% 100% 100% 100%
src/operations/sequences/renameSequence.ts 100% 100% 100% 100%
src/operations/sequences/shared.ts 81.48% 83.33% 100% 81.48% 41, 43, 49, 63, 69
src/operations/tables/addColumns.ts 100% 85.71% 100% 100%
src/operations/tables/addConstraint.ts 100% 100% 100% 100%
src/operations/tables/alterColumn.ts 91.17% 81.25% 100% 91.17% 69, 76-83
src/operations/tables/alterTable.ts 100% 100% 100% 100%
src/operations/tables/createTable.ts 88% 82.14% 100% 88% 51-54, 92
src/operations/tables/dropColumns.ts 100% 100% 100% 100%
src/operations/tables/dropConstraint.ts 100% 100% 100% 100%
src/operations/tables/dropTable.ts 100% 100% 100% 100%
src/operations/tables/index.ts 100% 100% 100% 100%
src/operations/tables/renameColumn.ts 100% 100% 100% 100%
src/operations/tables/renameConstraint.ts 100% 100% 100% 100%
src/operations/tables/renameTable.ts 100% 100% 100% 100%
src/operations/triggers/createTrigger.ts 88.23% 71.79% 100% 88.23% 53, 66, 70, 74-76
src/operations/triggers/dropTrigger.ts 100% 100% 100% 100%
src/operations/triggers/index.ts 100% 100% 100% 100%
src/operations/triggers/renameTrigger.ts 100% 100% 100% 100%
src/operations/triggers/shared.ts 100% 100% 100% 100%
src/operations/types/addTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/addTypeValue.ts 100% 100% 100% 100%
src/operations/types/createType.ts 100% 100% 100% 100%
src/operations/types/dropType.ts 100% 100% 100% 100%
src/operations/types/dropTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/index.ts 100% 100% 100% 100%
src/operations/types/renameType.ts 100% 100% 100% 100%
src/operations/types/renameTypeAttribute.ts 100% 100% 100% 100%
src/operations/types/renameTypeValue.ts 100% 100% 100% 100%
src/operations/types/setTypeAttribute.ts 100% 100% 100% 100%
src/operations/views/alterView.ts 100% 100% 100% 100%
src/operations/views/alterViewColumn.ts 100% 100% 100% 100%
src/operations/views/createView.ts 100% 100% 100% 100%
src/operations/views/dropView.ts 100% 100% 100% 100%
src/operations/views/index.ts 100% 100% 100% 100%
src/operations/views/renameView.ts 100% 100% 100% 100%
src/operations/views/shared.ts 100% 50% 100% 100%
src/utils/decamelize.ts 100% 100% 100% 100%
src/utils/escapeValue.ts 100% 100% 100% 100%
src/utils/formatLines.ts 100% 100% 100% 100%
src/utils/formatParams.ts 100% 87.5% 100% 100%
src/utils/formatPartitionColumns.ts 100% 100% 100% 100%
src/utils/getMigrationTableSchema.ts 100% 100% 100% 100%
src/utils/getSchemas.ts 100% 100% 100% 100%
src/utils/identity.ts 100% 100% 100% 100%
src/utils/index.ts 100% 100% 100% 100%
src/utils/intersection.ts 100% 100% 100% 100%
src/utils/makeComment.ts 100% 100% 100% 100%
src/utils/stringIdGenerator.ts 100% 100% 100% 100%
src/utils/toArray.ts 100% 100% 100% 100%
src/utils/types.ts 100% 100% 100% 100%
Generated in workflow #2815 for commit 48f5e26 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Collaborator

@Shinigami92 Shinigami92 left a comment

Choose a reason for hiding this comment

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

These changes look fantastic and are almost ready to be merged! I've just found a few minor improvements we should make before release.
Also, could you implement a test for the throw-inside-map-loop?

Comment thread src/operations/indexes/shared.ts Outdated
Comment thread src/operations/indexes/shared.ts
Comment thread src/operations/indexes/shared.ts Outdated
Comment thread src/utils/createSchemalize.ts Outdated
@Shinigami92 Shinigami92 added the c: feature Request for new feature label Jan 2, 2026
@Shinigami92 Shinigami92 changed the title fix: improve expression detection and handle PgLiteral in indexes feat: handle PgLiteral in index expressions Jan 2, 2026
Co-authored-by: Shinigami <chrissi92@hotmail.de>
Copy link
Copy Markdown

@filmaj filmaj left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! <3

Left a couple notes regarding the variety of different json operators available in Postgres.

Comment thread src/utils/createSchemalize.ts Outdated
Comment thread test/operations/indexes/createIndex.spec.ts
@Shinigami92
Copy link
Copy Markdown
Collaborator

@brenoepics just to manage expectations 😉 do you want to work further on the open change requests? or should someone take over?

@brenoepics
Copy link
Copy Markdown
Collaborator Author

@brenoepics just to manage expectations 😉 do you want to work further on the open change requests? or should someone take over?

Yup! I’ll have some free time tomorrow, so I’m planning to finish the remaining fixes and also add a few extra test cases I noticed.

@Shinigami92
Copy link
Copy Markdown
Collaborator

@brenoepics just to manage expectations 😉 do you want to work further on the open change requests? or should someone take over?

Yup! I’ll have some free time tomorrow, so I’m planning to finish the remaining fixes and also add a few extra test cases I noticed.

@brenoepics
Copy link
Copy Markdown
Collaborator Author

These changes look fantastic and are almost ready to be merged! I've just found a few minor improvements we should make before release. Also, could you implement a test for the throw-inside-map-loop?

it('should throw error if index name is not provided with PgLiteral', () => {
expect(() =>
createIndexFn(
'functions',
// @ts-expect-error: regression test for pgm.sql
PgLiteral.create("(contentSub->>'id')")
)
).toThrowError(
"Index name must be provided when using PgLiteral columns (column #1: (contentSub->>'id'))"
);
});

We already had this one, I just fixed the column name for better DX.

I also added a bunch of new test cases, such as missing operators and SQLi unit tests.

@brenoepics just to manage expectations 😉 do you want to work further on the open change requests? or should someone take over?

Yup! I’ll have some free time tomorrow, so I’m planning to finish the remaining fixes and also add a few extra test cases I noticed.

Sometimes days have about 200+ hours around here 😆

@Shinigami92 Shinigami92 self-requested a review January 14, 2026 08:28
Comment thread src/operations/generalTypes.ts
@Shinigami92 Shinigami92 added this pull request to the merge queue Jan 14, 2026
Merged via the queue into main with commit 9a2ca3b Jan 14, 2026
28 checks passed
@Shinigami92 Shinigami92 deleted the fix-json-indexes branch January 14, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use expressions in createIndex column name

3 participants