Describe the bug
When using the CLI to, for instance, create the database schema it gives an error.
Stack trace
/path/to/repository/$ yarn mikro-orm schema:create --run
yarn run v1.22.4
$ /path/to/repository/node_modules/.bin/mikro-orm schema:create --run
mikro-orm schema:create
Create database schema based on current metadata
Options:
-r, --run Runs queries [boolean]
-d, --dump Dumps all queries to console [boolean]
--fk-checks Do not skip foreign key checks [boolean]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]
ReferenceError: describe is not defined
at Object.<anonymous> (/path/to/repository/src/app.controller.spec.ts:5:1)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Module.m._compile (/path/to/repository/node_modules/ts-node/src/index.ts:858:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Object.require.extensions.<computed> [as .ts] (/path/to/repository/node_modules/ts-node/src/index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Module.require (internal/modules/cjs/loader.js:1089:19)
at require (internal/modules/cjs/helpers.js:73:18)
at MetadataDiscovery.getEntityClassOrSchema (/path/to/repository/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:614:25)
at MetadataDiscovery.discoverDirectories (/path/to/repository/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:90:33)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at MetadataDiscovery.findEntities (/path/to/repository/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:65:9)
at MetadataDiscovery.discover (/path/to/repository/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:32:9)
at Function.init (/path/to/repository/node_modules/@mikro-orm/core/MikroORM.js:40:24)
at Function.handleSchemaCommand (/path/to/repository/node_modules/@mikro-orm/cli/commands/SchemaCommandFactory.js:65:21)
error Command failed with exit code 1.
To Reproduce
Steps to reproduce the behavior:
yarn mikro-orm schema:create --runExpected behavior
Schema creation
Additional context
Using in combination with a nestjs project.
Versions
| Dependency | Version |
| - | - |
| mikro-orm | 4.0.0-alpha.12 |
| mikro-orm/nestjs | 4.0.0-alpha.1 |
| node | 14.4.0 |
| knex | 0.21.2 |
| mysql | 2 2.1.0 |
| typescript | 3.9.7 |
I think you need remove entitiesTs or set it correctly in src/mikro-orm.config.ts:
entitiesTs: ['./src/**/*.entity.ts'],
or
entitiesTs: [
AuditTrail,
Project,
GeneralInformation,
],
https://github.com/mikro-orm/mikro-orm/blob/dev/docs/docs/upgrading-v3-to-v4.md#changes-in-folder-based-discovery-entitiesdirs-removed
Ah yes, you are 100% right. My bad.
One suggestion to add to the cli, the ability to import a database dump. Currently only a file containing queries is accepted, while a dump file (from mysql for instance) is not accepted. I guess this is by design so the command is database type agnostic?
Not sure what you mean by dump file, but if its something vendor specific (like binary dumps in postgres), then nope, no plans to do that (at least not in the near future).
And as @xeladejo already suggested, the issue was with wrong entitiesTs value, as the ORM was trying to discover your test file.
One suggestion to add to the cli, the ability to import a database dump. Currently only a file containing queries is accepted, while a dump file (from mysql for instance) is not accepted. I guess this is by design so the command is database type agnostic?
@Langstra, you've tried adding multipleStatements: true to src/mikro-orm.config.ts.
Worked great. Thanks for mentioning that property. Should I perhaps create a PR with additional documentation on this?
Sure, be sure to mention its only for pg and mysql (afaik).
Most helpful comment
@Langstra, you've tried adding
multipleStatements: truetosrc/mikro-orm.config.ts.