question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

0.3.0 generate migrations path

See original GitHub issue

Issue Description

Expected Behavior

When running migration:generate, I expect the migration generated goes into the migrations path set in the parameter of the DataSource constructor.

Basically, I expect it to generate a migration into the path: E:\Projects\Discord Bots\commissions\luigical\src\migrations\<the_migration_file_here>.ts

Actual Behavior

Generating and creating migrations works but it goes into project root folder.

$ yarn typeorm:generate CreateGuildTable
yarn run v1.22.17
$ yarn typeorm:cli migration:generate -d src/ormconfig.ts CreateGuildTable
$ ts-node ./node_modules/typeorm/cli.js migration:generate -d src/ormconfig.ts CreateGuildTable
Migration E:\Projects\Discord Bots\commissions\luigical\CreateGuildTable.ts has been generated successfully.
Done in 9.21s.

Steps to Reproduce

  1. Use the code below
  2. Create an entity schema in the path project\src\entities\table-name.entity.ts
  3. Run the migration:generate command - in my case the scripts I used are:
"typeorm:cli": "ts-node ./node_modules/typeorm/cli.js",
"typeorm:generate": "yarn typeorm:cli migration:generate -d src/ormconfig.ts",
  1. It does not generate the migration in the correct path
const config: DataSourceOptions = {
  type: 'mysql',
  host: process.env.MYSQL_HOST,
  port: Number(process.env.MYSQL_PORT) || 3306,
  username: process.env.MYSQL_USERNAME,
  password: process.env.MYSQL_PASSWORD,
  database: process.env.MYSQL_DATABASE_NAME,
  entities: [__dirname + '\\entities\\**\\*{.ts,.js}'],
  migrations: [__dirname + '\\migrations\\**\\*{.ts,.js}'],
  cli: {
    migrationsDir: 'src\\migrations',
    entitiesDir: 'src\\entities'
  },
  synchronize: false
};

export const dataSource = new DataSource(config);

My Environment

Dependency Version
Operating System Windows 10 Home
Node.js version 17.3.0
Typescript version 4.5.5
TypeORM version 0.3.0

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql yes
nativescript no
oracle no
postgres no
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don’t know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (2 by maintainers)

github_iconTop GitHub Comments

36reactions
ryanoborilcommented, Jul 8, 2022

You need to specify full path now.

@pleerock absolutely ridiculous change

32reactions
cyril-git-hcommented, May 24, 2022

You need to specify full path now

what the hell? it’s exhausting and not convenient at all. How to configure path once? you should’ve thought about it. And please update documentation, it’s confusing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how can i specify the migrations directory for typeorm CLI
You can do this instead: typescript esm: npx typeorm-ts-node-esm migration:create src/database/migration/MigrationFileName where ...
Read more >
Doing migrations has changed since type orm 0.3 old cli ...
From what I read on their website you just need to create a class for migrations and use it in a cli command....
Read more >
TypeORM v0.3.x Migrations, queries, with NestJS! - YouTube
We'll cover how to create a CRUD API, how to write SQL queries, and finally how to do migrations. 00:00 - Intro 00:21...
Read more >
Are you stuck working with TypeORM >= 0.3.0?
Basically, remove path from the command and pass it as argument like this npm run migration:generate-dev src/database/migrations/<filename>.
Read more >
Directory error when trying to do migrations using typeorm
No changes in database schema were found - cannot generate a migration. To create a new empty migration use "typeorm migration:create" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found