typeorm-extension
typeorm-extension copied to clipboard
Bug: Exception when creating postgres db with custom schema
Versions
- Node: 16.16.0
- pg: 8.7.3
- typeorm: 0.3.7
- typeorm-extension: 2.1.5
- OS: Windows 11
Steps to reproduce
- Setup a postgres database.
- Create ormconfig.ts like below
- Run the npm script db:setup attached below
ormconfig
For me, this is located at /src/config/ormconfig.ts
.
export default {
type: Config.dbDialect,
host: Config.postgres.host,
port: Config.postgres.port,
username: Config.postgres.user,
password: Config.postgres.password,
database: Config.postgres.database,
schema: Config.postgres.schema,
entities: ['build/db/entities/**/*.js'],
}
npm scripts
"db:setup": "npm run build && cross-env NODE_ENV=development npm run db:drop && cross-env NODE_ENV=development npm run db:create"
"db:create": "typeorm-extension db:create --config ./build/config/ormconfig.js --initialDatabase postgres --synchronize",
"db:drop": "typeorm-extension db:drop --config ./build/config/ormconfig.js",
"build": "npx tsc",
What is Expected?
When specifying a schema in the ormconfig, the db:create should create that schema.
What is actually happening?
Exception when the first CREATE TABLE statement is being executed since the provided schema doesn't exist.
Can you try if the following configuration is working for you?
I assume that your source code folder is named src
.
export default {
type: Config.dbDialect,
host: Config.postgres.host,
port: Config.postgres.port,
username: Config.postgres.user,
password: Config.postgres.password,
database: Config.postgres.database,
schema: Config.postgres.schema,
entities: ['src/db/entities/**/*.ts'],
}
Please reopen the issue, if it is still not working for you.