I have created a sample typeorm project using the typeorm cli which has ormconfig.json by default:
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "test",
"synchronize": false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"database/migrations/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "database/migrations",
"subscribersDir": "src/subscriber"
}
}
this is the directory structure:
-database
-migrations
-src
-entity
-ormconfig.json
This creates the migrations in the database/migrations folder properly as well as executes the migrations from it.
I replaced ormconfig.json with the following ormconfig.ts :
export default {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'test',
synchronize: false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"database/migrations/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "database/migrations",
"subscribersDir": "src/subscriber"
}
};
this however creates migrations in the root directory instead of inside database/migrations.
Can anyone help me in figuring out whats missing here and how i can use ormconfig.ts to generate migrations inside the intended directory?
Thanks!
At the time of writing, TypeORM only look for ormconfig.json
and ignores ormconfig.ts
. There is work in progress to support it though.
Beside having ormconfig.json you need these commands in your package.json.
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/.bin/typeorm",
"migration:generate": "npm run typeorm -- migration:generate --config src/config/ormconfig.json --connection --name ",
"migration:run": "npm run typeorm -- migration:run"
Hey i up this conversation since i can propose you a solution.
You can put the following line in your package.json
file:
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js --config server/environments/database.ts",
And your ts config must export directly the config by doing that:
export = { /* your config */ };
As you can see, you can also specify the path of your config. No need for your config to be at the root level of your project.
Hope that will help you
I am using html2canvas.js to create a <canvas> image from a div on a page. What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on ...
I am using html2canvas.js to create a <canvas> image from a div on a page. What I'd like to do is send the rendered base64 image to a cfc via ajax so I can actually save the image to a folder on ...
I have the following setup where a custom checkmark is added to style the radio buttons. but it also adds that checkmark to the text type inputs. var changed =function(){ Array.from(...
I have the following setup where a custom checkmark is added to style the radio buttons. but it also adds that checkmark to the text type inputs. var changed =function(){ Array.from(...
I need to take some non-trivial javascript and ensure that all code paths have code that is valid. For example: var num = 1; if (num == 2) { badFunctionName(); } and I need to do this from C#. ...
I need to take some non-trivial javascript and ensure that all code paths have code that is valid. For example: var num = 1; if (num == 2) { badFunctionName(); } and I need to do this from C#. ...
Suppose you have an array that is modified by one asynchronous process and then you have another asynchronous process that reads from the same array. Modifications and reads are done synchronously. ...
Suppose you have an array that is modified by one asynchronous process and then you have another asynchronous process that reads from the same array. Modifications and reads are done synchronously. ...