Typeorm 0.3 migration generates changes even without making a single change to the entities

Viewed 17

I am facing a strange bug since I upgraded to TypeORM 0.3, I generate my first migration as the database is empty, and it is generated correctly. If I generate a second migration afterwards, without making a single change at the entities, the migration generated recognizes changes on every table, with scripts like this

await queryRunner.query(`ALTER TABLE \`clients\` CHANGE \`deletedAt\` \`deletedAt\` datetime(6) NULL`);
await queryRunner.query(`ALTER TABLE \`clients\` CHANGE \`type\` \`type\` varchar(255) NULL`);
await queryRunner.query(`ALTER TABLE \`clients\` CHANGE \`first_name\` \`first_name\` varchar(255) NULL`);
await queryRunner.query(`ALTER TABLE \`clients\` CHANGE \`last_name\` \`last_name\` varchar(255) NULL`);
await queryRunner.query(`ALTER TABLE \`clients\` CHANGE \`company_name\` \`company_name\` varchar(255) NULL`);
await queryRunner.query(`ALTER TABLE \`clients\` CHANGE \`administrator_name\` \`administrator_name\` varchar(255) NULL`);

These are just some of the lines of the second migrations, practically all my tables' columns are written in the second migration with the ALTER TABLE CHANGE script, and it is weird because I didn't make a single change. Even in the following migrations, these scripts continue to show.

Expected Behavior

I expect only changes made to the entities to be shown, not every column every time I generate a migration

package.json

"build": "tsc -p tsconfig.build.json",
"typeorm": "node -r ts-node/register ./node_modules/typeorm/cli.js -d src/ormconfig.ts",
"migration:revert": "npm run typeorm migration:revert",
"migration:run": "npm run build && npm run typeorm migration:run",
"migration:generate": "npm run build && npm run typeorm migration:generate",

ormconfig.ts

const ormconfiguration = {
type: getConnectionType(process.env.TYPEORM_CONNECTION),
host: process.env.TYPEORM_HOST,
port: Number(process.env.TYPEORM_PORT),
username: process.env.TYPEORM_USERNAME,
password: process.env.TYPEORM_PASSWORD,
database: process.env.TYPEORM_DATABASE,
entities: [process.env.TYPEORM_ENTITIES],
migrations: [process.env.TYPEORM_MIGRATIONS],
},

.env

 #APP_CONFIG
 HOST=http://localhost:5000
 NODE_ENV=development
 #DATABASE
 TYPEORM_CONNECTION=mysql
 TYPEORM_HOST=db-dev
 TYPEORM_USERNAME=root
 TYPEORM_PASSWORD=admin321
 TYPEORM_DATABASE=suitcase_db
 TYPEORM_PORT=3306
 TYPEORM_SYNCHRONIZE=false
 TYPEORM_LOGGING=false
 # TYPEORM_ENTITIES= ./src/entities/*.entity.ts
 # TYPEORM_MIGRATIONS= ./src/migrations/*.ts

 # for working with npm run start:dev
 TYPEORM_ENTITIES=./dist/**/entities/*.entity.js
 TYPEORM_MIGRATIONS=./dist/**/migrations/*.js

 TYPEORM_ENTITIES_DIR= ./src/entities/
 TYPEORM_MIGRATIONS_DIR= ./src/migrations/
 TYPEORM_MIGRATIONS_RUN=false
 TYPEORM_DROP_SCHEMA=false

My Environment

Dependency  Version
Operating System    Ubuntu 20.04
Node.js version 16.13
Typescript version  4.5.2
TypeORM version 0.3.9
0 Answers
Related