Skip to content

Conversation

@brenoepics
Copy link
Collaborator

Added failing test cases for each issue reported at #1469, will be fixing them soon, let me know if I should send them in the same PR or separately.

@brenoepics brenoepics changed the title tests: Add failing tests for [object Object] identifier bug in migration operations test: Add failing tests for [object Object] identifier bug in migration operations Jul 20, 2025
@github-actions
Copy link

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 92.53% (🎯 90%)
🟰 ±0%
3273 / 3537
🟢 Statements 92.53% (🎯 90%)
🟰 ±0%
3273 / 3537
🟢 Functions 96.7% (🎯 90%)
🟰 ±0%
264 / 273
🟢 Branches 91.15% (🎯 85%)
🟰 ±0%
866 / 950
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Unchanged Files
src/db.ts 83.18% 88.88% 87.5% 83.18% 90-92, 122, 125-137, 177-179
src/index.ts 100% 100% 100% 100%
src/logger.ts 100% 100% 100% 100%
src/migration.ts 76.07% 86.76% 68.75% 76.07% 149-152, 173-189, 231-237, 296-337, 402-403, 429-431, 439-440, 457-460, 489-490
src/migrationBuilder.ts 96.19% 93.33% 100% 96.19% 833-837, 976-981
src/migrationOptions.ts 100% 100% 100% 100%
src/pgType.ts 100% 100% 100% 100%
src/runner.ts 80.33% 67.79% 100% 80.33% 189, 208-217, 229-230, 282-283, 325-328, 337-341, 354, 366-369, 392, 403, 433-446, 449-452, 472-474, 483, 485-494
src/sqlMigration.ts 85.36% 100% 80% 85.36% 54-60
src/operations/sql.ts 100% 100% 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% 100% 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 95.52% 94.44% 100% 95.52% 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 95.45% 85.71% 100% 95.45% 71
src/operations/indexes/createIndex.ts 100% 100% 100% 100%
src/operations/indexes/dropIndex.ts 100% 100% 100% 100%
src/operations/indexes/index.ts 100% 100% 100% 100%
src/operations/indexes/shared.ts 88% 86.95% 100% 88% 23, 33-36, 48
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% 87.5% 100% 100%
src/operations/operators/addToOperatorFamily.ts 100% 100% 100% 100%
src/operations/operators/createOperator.ts 100% 100% 100% 100%
src/operations/operators/createOperatorClass.ts 100% 83.33% 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 85% 75% 100% 85% 24-25, 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% 75% 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 98.07% 76.92% 100% 98.07% 78
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 94.73% 80% 100% 94.73% 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 78.57% 68.75% 100% 78.57% 41, 43-44, 49-50, 63-64, 69-70
src/operations/tables/addColumns.ts 100% 80% 100% 100%
src/operations/tables/addConstraint.ts 100% 100% 100% 100%
src/operations/tables/alterColumn.ts 89.33% 76.47% 100% 89.33% 69, 76-83
src/operations/tables/alterTable.ts 100% 100% 100% 100%
src/operations/tables/createTable.ts 89.39% 77.27% 100% 89.39% 51-55, 92-93
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/tables/shared.ts 83.15% 81.81% 80% 83.15% 157-158, 211-215, 241-242, 261-262, 287-288, 291-298, 301-302, 439-464
src/operations/triggers/createTrigger.ts 86.25% 68.18% 100% 86.25% 53-54, 66-67, 70-71, 74-77, 113
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% 66.66% 100% 100%
src/utils/PgLiteral.ts 90.47% 100% 80% 90.47% 44-45
src/utils/StringIdGenerator.ts 100% 100% 100% 100%
src/utils/createSchemalize.ts 100% 100% 100% 100%
src/utils/createTransformer.ts 100% 100% 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% 100% 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/quote.ts 100% 100% 100% 100%
src/utils/toArray.ts 100% 100% 100% 100%
src/utils/types.ts 100% 100% 100% 100%
Generated in workflow #2294 for commit 4b46711 by the Vitest Coverage Report Action

@Shinigami92
Copy link
Collaborator

Added failing test cases for each issue reported at #1469, will be fixing them soon, let me know if I should send them in the same PR or separately.

They are all falling into the same "module" operations, so I think it's fine to tackle them in one PR 👍

@brenoepics
Copy link
Collaborator Author

Mostly yeah, besides those:

tableName becomes [object Object] here 😳 (used in createTable and addColumn)

(referencesConstraintComment ? `${tableName}_fk_${columnName}` : '');

createFunction too but that's an error only, not so important

throw new Error(
`Language for function ${functionName} have to be specified`
);

@Shinigami92
Copy link
Collaborator

Mh, okay. There are already 8 touched files. We should keep the diff small. 10-20 file changes would already count as a medium to big PR.
Another indicator is to have one PR for one changelog entry. (Even if we don't have a CHANGELOG.md but only release page in this project. But in the release page it also generates an entry with the PR title.

@brenoepics
Copy link
Collaborator Author

I think I'm separating this PR due to different fixes, indexMethod is not typed correctly (gotta change docs too), it shouldn't be Name because it is not schema-qualified "schema"."btree" will not work on pg, for example.
reference

So we can either:

  • make all indexMethod: string
    ✅ No code changes besides types
    ❌ Breaking change for anyone using indexMethod = { name: "abc" } (we don't have any unit test like this, but who knows how people use it)
  • make all indexMethod: IndexMethod i.e., type IndexMethod = string | { name: string }, but now we have to fix all operators to handle indexMethod.name too
    ✅ No breaking changes
    ❌ touching all operator functions to correctly handle object (actually, I think this proves that no one is using this, {...} would never work based on how we do it currently)

IMO, the first option is far better since the worst thing that could happen is in case someone did it const indexMethod: Name and then passed it to the operator (using a simple string because an object will never work)

So, operators are easy, but the tables/shared.ts case does not apply in case you use schema, you are likely receiving something like:

CREATE TABLE "myschema"."distributors" (
  "user_id" integer CONSTRAINT "[object Object]_fk_user_id" REFERENCES "myschema"."users"
);
COMMENT ON CONSTRAINT "[object Object]_fk_user_id" ON "myschema"."distributors" IS $pga$user reference$pga$;

This actually works because [object Object]_fk_user_id is a valid name for it, so that no one might've noticed, our createColumn got the same issue, and createTable, createColumn are ok to have schema, our choices are:
see CONSTRAINT

  • Keep simple tableName_fk_columnName as CONSTRAINT but checking for {schema, name} and fixing it (but with the downside that you can reference another schema, it might be confusing)
  • schema.tableName_fk_columnName or schema_tableName_fk_columnName...

(.literal(..) or .schemalize(..) does not apply here since it might attach " breaking it.)

createFunction one is way simpler,

throw new Error(
   `Language for function ${mOptions.literal(functionName)} have to be specified`
);

'@typescript-eslint/no-base-to-string': 'off',

This rule could catch it, I think we can enable it back once we fix them, I only noticed because I'm running sonar locally so it is asking me to confirm on every push 😂 (actually this is happening with col too)

`${tableName}_fk_${cols.join('_')}`

I've uploaded the analysis from my fork to SonarCloud

@brenoepics brenoepics closed this Jul 21, 2025
@Shinigami92
Copy link
Collaborator

@brenoepics did you saw the PR #1458 from @adrenalin?
Maybe you both could join forces for that.

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