-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
SchemaGenerator (CLI or called programmatically) fails on subsequent runs when a check constraint is placed on a column.
Stack trace
TypeError: Cannot read properties of undefined (reading 'replace')
at replaceKeyBindings (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/formatter/rawFormatter.js:46:23)
at Raw.toSQL (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/raw.js:79:13)
at Raw.Target.toQuery (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/builder-interface-augmenter.js:9:21)
at Raw.toString (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/raw.js:70:17)
at /Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/schema/tablecompiler.js:381:35
at Array.map (<anonymous>)
at TableCompiler_PG._addChecks (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/schema/tablecompiler.js:378:12)
at TableCompiler_PG.createQuery (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/dialects/postgres/schema/pg-tablecompiler.js:49:13)
at TableCompiler_PG.create (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/schema/tablecompiler.js:59:10)
at TableCompiler_PG.toSQL (/Users/surf/Developer/git/comfortai-consumer/targets/server/node_modules/knex/lib/schema/tablecompiler.js:42:22)
To Reproduce
Steps to reproduce the behavior:
- Define property w/ check constraint:
@Property({ type: 'number', columnType: 'bigint', default: null, nullable: true })
@Check({ expression: columns => '"unsignedIntField" IS NULL OR ("unsignedIntField" >= 0 AND "unsignedIntField" <= 4294967295)' })
'unsignedIntField'?: number;
- Run schema:fresh - first run succeeds
npx mikro-orm schema:fresh --run
- Run schema:fresh again - this time it fails; repeated runs also fail
npx mikro-orm schema:fresh --run
- Modify the check expression
@Property({ type: 'number', columnType: 'bigint', default: null, nullable: true })
@Check({ expression: columns => '"unsignedIntField" IS NULL OR ("unsignedIntField" >= 0 AND "unsignedIntField" <= 4294967295)' })
'unsignedIntField'?: number;
- Run schema:fresh - succeeds again once
npx mikro-orm schema:fresh --run
- Run schema:fresh again - back to failure mode; repeated runs also fail
npx mikro-orm schema:fresh --run
- Comment/remove the check expression
@Property({ type: 'number', columnType: 'bigint', default: null, nullable: true })
// @Check({ expression: columns => '"unsignedIntField" IS NULL OR ("unsignedIntField" >= 0 AND "unsignedIntField" <= 4294967295)' })
'unsignedIntField'?: number;
- Run schema:fresh - back to success; repeated runs also succeed
npx mikro-orm schema:fresh --run
Expected behavior
Schema should drop/build successfully each time with the check constraints in place
Additional context
This feels similar to #4312 in behavior, but the stack trace is quite different.
Versions
| Dependency | Version |
|---|---|
| node | 16.15.0 |
| typescript | 4.8.4 (also tried with 4.9.5) |
| mikro-orm | 5.7.12 |
| your-driver | postgresql |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working