-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Description
Describe the bug
The SyntaxErrorException is thrown when I call the refreshDatabase() method. The bug occurs only in version 6.2.8. I assume it's related to the SQL conversion and the unique TypeScript type that we use for the type property of the User model (please see the reproduction).
The reproduction should be self-explanatory. However, I will post the full error message here:
SyntaxErrorException: create table "user" ("id" serial primary key, "type" ValueOf<Readonly<{ readonly ADMIN: "admin"; readonly CUSTOMER: "customer"; }>> not null); - syntax error at or near "<"
at PostgreSqlExceptionConverter.convertException (/Volumes/Development/unzico/mikro-orm-refresh-database/.yarn/__virtual__/@mikro-orm-postgresql-virtual-67b3ba023c/5/Users/unzico/.yarn/berry/cache/@mikro-orm-postgresql-npm-6.2.8-77c388a4d4-10c0.zip/node_modules/@mikro-orm/postgresql/PostgreSqlExceptionConverter.js:38:24)
at PostgreSqlDriver.convertException (/Users/unzico/.yarn/berry/cache/@mikro-orm-core-npm-6.2.8-d80bd9c295-10c0.zip/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:344:54)
at /Users/unzico/.yarn/berry/cache/@mikro-orm-core-npm-6.2.8-d80bd9c295-10c0.zip/node_modules/@mikro-orm/core/drivers/DatabaseDriver.js:348:24
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at SqlSchemaGenerator.execute (/Volumes/Development/unzico/mikro-orm-refresh-database/.yarn/__virtual__/@mikro-orm-knex-virtual-55a2757fbd/5/Users/unzico/.yarn/berry/cache/@mikro-orm-knex-npm-6.2.8-9f0930073e-10c0.zip/node_modules/@mikro-orm/knex/schema/SqlSchemaGenerator.js:467:17)
at SqlSchemaGenerator.createSchema (/Volumes/Development/unzico/mikro-orm-refresh-database/.yarn/__virtual__/@mikro-orm-knex-virtual-55a2757fbd/5/Users/unzico/.yarn/berry/cache/@mikro-orm-knex-npm-6.2.8-9f0930073e-10c0.zip/node_modules/@mikro-orm/knex/schema/SqlSchemaGenerator.js:17:9)
at SqlSchemaGenerator.refreshDatabase (/Users/unzico/.yarn/berry/cache/@mikro-orm-core-npm-6.2.8-d80bd9c295-10c0.zip/node_modules/@mikro-orm/core/utils/AbstractSchemaGenerator.js:40:9)
at main (/Volumes/Development/unzico/mikro-orm-refresh-database/src/index.ts:28:3)
at Parser.parseErrorMessage (/Users/unzico/.yarn/berry/cache/pg-protocol-npm-1.6.1-c0b26dda9d-10c0.zip/node_modules/pg-protocol/src/parser.ts:369:69)
at Parser.handlePacket (/Users/unzico/.yarn/berry/cache/pg-protocol-npm-1.6.1-c0b26dda9d-10c0.zip/node_modules/pg-protocol/src/parser.ts:188:21)
at Parser.parse (/Users/unzico/.yarn/berry/cache/pg-protocol-npm-1.6.1-c0b26dda9d-10c0.zip/node_modules/pg-protocol/src/parser.ts:103:30)
at Socket.<anonymous> (/Users/unzico/.yarn/berry/cache/pg-protocol-npm-1.6.1-c0b26dda9d-10c0.zip/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:545:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
at Socket.Readable.push (node:internal/streams/readable:375:5)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
code: '42601',
errno: undefined,
sqlState: undefined,
sqlMessage: undefined,
errmsg: undefined,
length: 90,
severity: 'ERROR',
detail: undefined,
hint: undefined,
position: '61',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1176',
routine: 'scanner_yyerror'
}
The relevant part is this:
"type" ValueOf<Readonly<{ readonly ADMIN: "admin"; readonly CUSTOMER: "customer"; }>>
The model file looks like this:
// src/models/User.ts
import { Entity, PrimaryKey, Property } from "@mikro-orm/core";
/**
* Return all unique value types of T.
*/
type ValueOf<T> = T[keyof T];
const UserType = Object.freeze({
ADMIN: "admin",
CUSTOMER: "customer",
} as const);
type Props = {
type: ValueOf<typeof UserType>;
};
@Entity()
export class User {
constructor(props: Props) {
this.type = props.type;
}
@PrimaryKey()
id!: number;
@Property()
type: ValueOf<typeof UserType>;
}Reproduction
https://github.com/unzico/mikro-orm-refresh-database
What driver are you using?
@mikro-orm/postgresql
MikroORM version
v6.2.8
Node.js version
v20.10.0
Operating system
macOs Sonoma 14.5
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Slack.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
No labels